Jump to content

XML update with DOM


xcandiottix

Recommended Posts

XML File

<Name N="john">

 

PHP File

$xmltabname = $dom->getElementsByTagName("Name");
$xmltabname->item($i)->textContent = $_POST['tabname'.$i.''];

 

I'm trying to update my XML file, as above I want to change N="john" to $_POST['tabname'.$i.'']. I'm not sure how to construct the second line of the php code. In place of textContent i've tried nodeValue but I'm not hitting the attribute.

 

Can anyone point me the right way?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/207398-xml-update-with-dom/
Share on other sites

Got it. For anyone interested:

$xmltabname = $dom->getElementsByTagName("Name");
$xmltabname->item($i)->textContent = $_POST['tabname'.$i.''];

 

should be:

$xmltabname = $dom->getElementsByTagName("Name");							
$xmltabname->item($i)->setAttribute("N",$_POST['tabname'.$i.'']);

 

 

Link to comment
https://forums.phpfreaks.com/topic/207398-xml-update-with-dom/#findComment-1084515
Share on other sites

Just a heads up: Things get much more tricky if you have more than one XML element on the page with the attribute "N". If you have a file with a bunch of repeated (nested) XML in it, you will have to first search for a unique value, then perform your search for a particular value or attribute inside of the parent node for that element (the one containing the unique value).

Link to comment
https://forums.phpfreaks.com/topic/207398-xml-update-with-dom/#findComment-1084795
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.