You are here: XML/DOM deleting childnodes/hierarchy « PHP Programming Language « IT news, forums, messages
XML/DOM deleting childnodes/hierarchy

Posted by tsuki on 10/18/06 06:30

Hello,

I have a problem concerning DOM and XML.

The structure of my xml is the following:
<?xml version="1.0" encoding="utf-8"?>
<website>
<language1>
<seite>
<bereich1>
<text></text>
<link>
<link></link>
</link>
<link>
<link></link>
</link>
<link>
</link>
</bereich1>
<bereich2>
</bereich2>
</seite>
</language1>
</website>

if I change and save the contents of the link-tags, there is no
problem.
(to change the value of a link, I simply select them by getElementsByID
and loop them in a for-loop).

But if I have to delete one of them, it seems that the hierarchy
somehow causes trouble, a "not found error" occurs.
If there is only a list of links, which doesn't contain other links,
the deleting works.

My question: why does the principle of the for-looping work with
changing the values of the link, but doesnt work when i want to delete
them?

The code for deleting:

$DeleteIt=(int)$DeleteIt;
if($Sprache=="Deutsch") $parent =
$dom->getElementsByTagName('language1')->item(0);
else if ($Sprache=="Englisch") $parent =
$dom->getElementsByTagName('language2')->item(0);
$parent2=$parent->getElementsByTagName('seite')->item($Seite);
$parent3=$parent2->getElementsByTagName('bereich1')->item(0);
$toDelete=$parent3->getElementsByTagName('link')->item($DeleteIt);
$okay = $parent3->removeChild($toDelete);

if I replace the last two lines by:

$toDelete=$parent3->getElementsByTagName('link')->item($DeleteIt)->nodeValue;
echo $toDelete;

the value of the link that has to be deleted is given - this works.


Can anyone help me solving the problem or explaining why the one works
and the other doesn't?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация