Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    XML Child Tag rename

    Hi

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

    here is example

    Code:
    <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

    Code:
    $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

    Code:
    <?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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •