[Discuss] perl and xml

Rich Braun richb at pioneer.ci.net
Tue Oct 10 13:31:24 EDT 2017


"R. Luoma" <nobluspam5476 at penguinmail.com> wrote:
> 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
>
>
> Consider the following
> ...  [ xml stuff] ...
> I want to change tagA contents so that
> they contain the quoted text in tagB as follows

Here's how I'd do the same thing in python:

  #!/usr/bin/env python
  import xml.etree.ElementTree as tree

  obj = tree.parse('things.xml')
  root = obj.getroot()
  root[0][0].text = 'good_tag_001'
  obj.write('newthings.xml')

Bill Ricker noted:
> In Perl's spirit of TIMTOWTDI, There is More than One Way to Do It.

Indeed, so does python. But it's really easy to learn this particular way of
parsing XML, and python is part of the base Linux distro in most environments.
Learn more at: https://docs.python.org/2/library/xml.etree.elementtree.html

-rich





More information about the Discuss mailing list