Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: XML Child Tag rename
03-23-2009, 12:01 PM #1
- Join Date
- Mar 2009
- Thanked 0 Times in 0 Posts
XML Child Tag rename
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);
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>
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.
03-23-2009, 12:56 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,662 Times in 2,631 Posts
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).
Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');