|Just another Perl shrine|
Re: perl substituteby sundialsvc4 (Monsignor)
|on Nov 04, 2013 at 16:48 UTC||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: http://excelhero.com/periodic-table/.
(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.)
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.