Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month at the Massachusetts Institute of Technology, in Building E51.

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] perl and xml

On Mon, Oct 9, 2017 at 1:49 PM, R. Luoma <nobluspam5476 at> 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 .
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,


> 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).


Bill Ricker
bill.n1vux at  a/k/a bricker at
Facilitator, Boston Perl Mongers

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /