[Discuss] perl and xml

Bill Ricker bill.n1vux at gmail.com
Mon Oct 9 15:20:41 EDT 2017


On Mon, Oct 9, 2017 at 1:49 PM, R. Luoma <nobluspam5476 at penguinmail.com> wrote
on BLU Discuss:

> This may be off-topic, but I am trying to manipulate
> what I think is an "xml" file with perl (on a linux system).
> I am not familiar with the ins and outs of xml

It would not be off-topic on Boson-pm at mail.perl.org .
We're your local Perl UG.
(Second Tuesdays, around the corner from where BLU meets. Tomorrow
night, come visit!)

Weren't you formerly on our Listserve too?

(So I'm CC:ing discussion there, but folks there should REPLY ALL, so
that he can see the replies.)


> Supposedly, perl has xml modules for this purpose,

Yes.

> but I am have difficulty figuring them out.

In Perl's spirit of TIMTOWTDI, There is More than One Way to Do It.

The default answer is to parse an entire document and navigate the DOM
from the root.  That could be XML::LibXML or XML::Simple or
XML::LibXSLT or ...
That way lies madness, when your edits are strictly local.

> The above example is simple, but, ultimately,
> I would be working on an xml file with many items
> and each item would have many different tags.

So you want to edit XML locally, replacing a tag's text contents with
a specific portion of the text contents of a specifically-named
sibling tag.

For local edits such as you need, I'd use XML::Twig [2][3].
   I did a worked example [1] not so very different from yours for the
Perl Advent calendar in a prior decade (when Boston.PM's Jerrad Pierce
was editor and Boston.PM were majority contributors).


[1] http://perladvent.pm.org/2009/06
[2] https://metacpan.org/module/XML::Twig
[3] http://xmltwig.org/xmltwig/


-- 
Bill Ricker
bill.n1vux at gmail.com  a/k/a bricker at theperlshop.com
Facilitator, Boston Perl Mongers http://Boston.PM.org
Consultant, ThePerlShop.com
https://www.linkedin.com/in/n1vux



More information about the Discuss mailing list