-1

Scenario:

I'm on an AIX machine - actually, over a dozen. I have an application that outputs information to XML files, unfortunately without linebreaks. I have a need to run scripts that can make queries on those files. It's mostly simple : If they were normal log files, grep and cut would do me just fine. However, I'm stuck with what I've got.

I've done very little work with XML, and these are production AIX machines, so I can't install random software to see if something works. Perl is on these machines, and grepping through @INC for XML shows me (abridged):

XML/LibXML
XML/Parser
XML/Simple
XML/SAX

Is using one of these the right way to go about doing what I need to do?

3
  • 1
    Proper xml parsing is good, but you can generate linebreaks like this: sed 's/>/>\n/g'
    – LatinSuD
    Sep 24, 2010 at 21:17
  • Please add the 'perl' tag, unless of course you're not saying you HAVE to use perl, which is sounds like you will.
    – VxJasonxV
    Sep 24, 2010 at 21:39
  • Not a case of having to use perl - but that's a tool on the system, and it's cumbersome to get approval to request the infrastructure team to install additional tools.
    – mfinni
    Sep 25, 2010 at 1:21

3 Answers 3

2

I recommend XML::Simple. Very easy to pick up and is already installed.

1
  • Thanks - with the many options in front of me, and reading and not understanding the details between SAX, DOM, XPath, etc - I just wanted the "... for Dummies" , "just-start-here" answer.
    – mfinni
    Sep 25, 2010 at 0:43
1

Expanding a big on Maris(t?)'s answer, XML::Simple is definitely my best friend. It's dead simple, and works well for static XML files.

XML::Simple is NOT good for an XML stream, nor huge (we're talking many multiples of megabytes here) XML files, but for configuration files and resource files, XML::Simple works wonderfully.

I'll spare you the details, because my link (to mclean.net.nz) should be a great primer on usage, and maris(t?)'s link to CPAN will be great to really get you into the details of it. How to tweak it to your behavior, and what all you can do with it.

Two quick tips for something I always see screw over new users;
When instantiating the handler, add an option of KeyAttr => 0. I don't understand who in their right minds wants that to start out with. Down the road, when you understand it? Sure, you'll use it. Until then? Worthless.

Anyways, second tip:
ForceArray is your best friend when a node can have 0, 1, or many records. Saves you from nasty workarounds like checking the size of an XML node and acting on it two different ways, or skipping it altogether. Put that key on a ForceArray, use a for/foreach loop, call it done.

2
  • Extra-plus thanks for the added hints and link.
    – mfinni
    Sep 25, 2010 at 0:43
  • Gracías. I can't explain how much I love XML::Simple. The 'simple' versions of programming languages help so much. PHP has SimpleXML, Perl has XML::Simple, Ruby has XML-Simple (A port pf XML::Simple), and I'm sure Python has something, but I don't use Python :P. Have fun!
    – VxJasonxV
    Sep 25, 2010 at 20:30
1

Possibly check some of the answers from here: https://stackoverflow.com/questions/91791/grep-and-sed-equivalent-for-xml-command-line-processing

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .