...

View Full Version : XML Child Tag rename



jedistev
03-23-2009, 12:01 PM
Hi

i have done many different way to rename Child TAG to allow

here is example



<root>
<parent>
<child>bar</child>
<price>20</price>
<author> dunno</author>
</parent>
</root>



i know it sound wrong code but i have different many way



$dita = new DOMDocument;
$dita->Load("book.xml");
$ditaList=$dita->getElementsByTagName("book")->item($id);
$tagToReplace=$ditaList->getElementsByTagName("author")->item($id);
$ditaList->replaceChild($tagToReplace);


seems code is not working and i have try another way but fail

my aim is change on outputclass XML like



<?xml version="1.0"?>
<root>
<parent>
<child outputclass="internal" >bar</child>
<price outputclass="internal >20</price>
<author outputclass= "external"> dunno</author>
</parent>
</root>


that i want to set the outputclass attribute to outputclass="external" or "internal"

or prefer use

PHP (or XML) code call the "control file (can be an ASCII text file or an XML file)" , and then the PHP code does the processing logic on the desired DITA files based on the info in the control file.

Fou-Lu
03-23-2009, 12:56 PM
You're usage of replacechild is incorrect. ReplaceChild requires two parameters, the new and the old nodes.
However, I don't see where you're actually needing to do this. The difference between the two blocks of xml code only indicate changes in attributes. You can fetch a domNodeList from the getElementsByTagName method (it won't work on book though, since you don't have a book element), iterate through the list or fetch a single item (I assume that $id is for this purpose, but I don't see it defined anywhere), and use the createAttribute method on DomDocument, and append this to the desired DOMNode(s).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum