Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Manipulate xml with libxml

by Anonymous Monk
on Jun 08, 2005 at 05:20 UTC ( [id://464606]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Manipulate xml with libxml
in thread Manipulate xml with libxml

Thank you very much Don!! It works well. I am happy.

I just added the argument 1 with the cloneNode function to get the child nodes.
$descr->addSibling($elt->cloneNode(1))
You are right, <fixe> is not the root element of the file. I should have mentioned that.

by the way, when I remove some nodes and then when I use toString or serialize, the xml is not really pretty. Is there a function to remove unneeded \n and to format the output with the good indentation? (a kind of "pretty print" with xmlspy for those who know this software)

Replies are listed 'Best First'.
Re^3: Manipulate xml with libxml
by BaldPenguin (Friar) on Jun 08, 2005 at 12:24 UTC
    I confess LibXML doesn't create pretty XML, in fact I normally include variables to strip out the unneccesary whitespace because I send it through XSLT. You can write some kind recursive loop to fix it all or if you are not to worried about speed, send your string to XML::Twig. It has some great pretty_print functionality. I only make the comment about speed because in this you will be effectively parsing your XML twice.

    Don
    WHITEPAGES.COM | INC

    Edit by castaway: Closed small tag in signature

      As much as it pains me to say this ;--( ... if libxml2 is installed, it might be just as simple to use xmllint --format. And XML::Twig comes with a standalone tool: xml_pp.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://464606]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.