I am trying to insert data into my XML document into a specific node of content_set
I thought I had to use item()
but every time I submit my form the data gets put in at the end of my document but before the closing content_sets
PHP:
//This is where I thought I would choose what node the data is put into based on the value of the select in my html, with 0 being the doc_types and 1 being video_types
$file_type = $_POST['file_type'];
$doc = new DOMDocument();
$doc->load( 'myfile_files.xml' );
$doc->formatOutput = true;
$r = $doc->getElementsByTagname('content_sets')->item($file_type);
$b = $doc->createElement("article");
$titleName = $doc->createElement("doc_name");
$titleName->appendChild(
$doc->createTextNode( $Document_Array["name"] )
);
$b->appendChild( $titleName );
$r->appendChild( $b );
$doc->save("myfile_files.xml");
XML:
<?xml version="1.0" encoding="UTF-8"?>
<content_sets>
<doc_types>
<article>
<doc_name>Test Proposal</doc_name>
<file_name>tes_prop.docx</file_name>
<doc_description>Test Word document. Please remove when live.</doc_description>
<doc_tags>word document,test,rfp template,template,rfp</doc_tags>
<last_update>01/26/2013 23:07</last_update>
</article>
</doc_types>
<video_types>
<article>
<doc_name>Test Video</doc_name>
<file_name>test_video.avi</file_name>
<doc_description>Test video. Please remove when live.</doc_description>
<doc_tags>test video,video, avi,xvid,svid avi</doc_tags>
<last_update>01/26/2013 23:07</last_update>
</article>
</video_types>
</content_sets>
HTML:
<p>Content Type:<br/>
<select name="file_type">
<option value="0">Document</option>
<option value="1">Video</option>
<option value="2">Image</option>
</select></p>
I thried to include the most imporant parts of the script but can post all of it if needed.
Thanks!