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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.