Jump to content

XML DOM object wierd problem


Packy

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/82165-xml-dom-object-wierd-problem/
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.