Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Having started with (very good!) XML::LibXML, now you need to finish with it.   You are, in fact, much closer to your goal than you dream.

Having parsed the file successfully, now you can use XPath expressions to “query” the file for the nodes that you want to, in this case, rename.   Then, by iterating through each returned list of nodes, you can change the content of the node including its name.   That is, if you want to do this using Perl . . .

You might also be interested to know that a technology known as XSLT can do this sort of thing without programming ... neither in Perl nor anything else.   (Well, except for the fact that “XSL” is very-much a programming tool unto itself, as any sort of tool meant to solve that particular problem must be.)   If you want a crystalline example of just how powerful this technology is, and how available it is, surf here:

(No, I am not going to spell-out for you all of the Magickal Mysteries that you will uncover here when you diligently use the “View Source” option of your browser . . .   Keep Digging.)

What you see here is an XHTML document that is directing your web browser to, on-the-fly(!) transform an external XML document (containing “information about all of the elements”) into the HTML representation that you now see being displayed.   (A small amount of JavaScript drives the interaction with the finished page, but not the construction of the page from its XML sources.   (I repeat... JavaScript did not do this!)

It appears to me that what you ultimately want to do to this file is to re-name a few of the nodes, wherever they might be found.   XSLT can do that, without Perl or anything else.

This being said, XML::LibXML gives Perl access to the same underlying functionality that you see your web-browser (or most XSLT processors) using.   (So, your web browser is not making Perl “look bad.”   “The full power of LibXML” is at your/Perl’s fingertips, too.)   In all cases, regardless of tool, you/they approach the problem in fundamentally the same way:   parse the XML document to a set of nodes, transform the nodes, then emit the node-structure as XML.   At no point do you/they attempt to treat the XML document as text.

In reply to Re: perl substitute by sundialsvc4
in thread perl substitute by ambrill

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2015-11-28 03:36 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (737 votes), past polls