I started with a couple other XML packages way back when and was never happy. I accidentally discovered LibXML and after fighting through the docs (they actually are pretty good, you just have to read them all front to back and then use them like a function index) I've never been happier. So stick it out, as it were. My Xpath sucks but here's something anyway.

First, there's a good basic tutorial here: Xpath basics. I use that site over and over because their tutorials are straightforward and well organized even when they aren't the deepest/best. Then, this is what I tried just to play around.

use XML::LibXML; my $parser = XML::LibXML->new(); my $tree = $parser->parse_fh(*DATA); my $root = $tree->getDocumentElement; for my $node ( $root->findnodes("//Device/*/status/text()") ) { print $node->nodeValue, $/; } # print $root->serialize(1); __DATA__ <?xml version="1.0" standalone="yes" ?> <SymCLI_ML> <Symmetrix> <Symm_Info> <symid>000290101935</symid> </Symm_Info> <Device> <Dev_Info> <pd_name>Not Visible</pd_name> <dev_name>0040</dev_name> # ...

To iterate through all the Device childNodes, this sort of thing should be pretty fast. I think there is a native Xpath for getting child nodes too.

for my $node ( $root->findnodes("//Device/*") ) { print $node->nodeName, $/; }

You could certainly cook up a hash of the nodeNames/Xpath to "your key names" you want and run your Xpath queries with it so that your solution would (human) scale as it would be little more than a configuration based filter.

(update: corrected an extra word and code comment)


In reply to Re: Any help available for a newbie to XML::LibXML? by Your Mother
in thread Any help available for a newbie to XML::LibXML? by wardy3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.