xcandiottix Posted July 11, 2010 Share Posted July 11, 2010 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 More sharing options...
xcandiottix Posted July 11, 2010 Author Share Posted July 11, 2010 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 More sharing options...
BizLab Posted July 12, 2010 Share Posted July 12, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.