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



"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





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 / webmaster@blu.org