Packy Posted December 18, 2007 Share Posted December 18, 2007 Hello, I have an XML file, for example: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <flat-profile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SomeElement>ccccc</SomeElement> </flat-profile> and I can easily edit it with this simple code: <?php $dom = new DOMDocument; $dom->load('XML/sample.xml'); $SomeElement = $dom->getElementsByTagname('SomeElement')->item(0)->firstChild->nodeValue; echo '<br> Current value is: ' . $SomeElement . '<br>'; $dom->getElementsByTagname('SomeElement')->item(0)->firstChild->nodeValue = 'aaaaa'; $SomeElementValue = $dom->getElementsByTagname('SomeElement')->item(0)->firstChild->nodeValue; echo '<br> New value is: ' . $SomeElementValue . '<br>'; $dom->save('XML/sample.xml'); ?> This works fine, but when I, in XML file, instead of: <SomeElement>ccccc</SomeElement> have: <SomeElement/> or <SomeElement></SomeElement> It want work, it does not want to change SomeElement to a value 'aaaaa'. Is there some mistake with this code: $dom->getElementsByTagname('SomeElement')->item(0)->firstChild->nodeValue; or ????? Please help... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/82165-xml-dom-object-wierd-problem/ Share on other sites More sharing options...
448191 Posted December 20, 2007 Share Posted December 20, 2007 $dom->getElementsByTagname('SomeElement')->item(0)->nodeValue; or $dom->getElementsByTagname('SomeElement')->item(0)->nodeText; Quote Link to comment https://forums.phpfreaks.com/topic/82165-xml-dom-object-wierd-problem/#findComment-419351 Share on other sites More sharing options...
Packy Posted December 23, 2007 Author Share Posted December 23, 2007 I'm trying with: $dom->getElementsByTagname('SomeElement')->item(0)->nodeValue; Quote Link to comment https://forums.phpfreaks.com/topic/82165-xml-dom-object-wierd-problem/#findComment-421982 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.