Welcome to the Monastery. If you want to be able to find out which files have non-empty "fail-message" elements, so that you can see how many different values there are for fail messages, you probably want to use XPath expressions (which you can look up elsewhere - it's not strictly a Perl thing).

For example, a while back I figured out how to use the XPath facilities in XML::LibXML, and it was so easy and so cool, I posted some sample code for a generic tool to take an XPath expression and an XML file as command-line args, and output the portions of a given file (if any) that matched a given XPath: Re: XPath command line utility....

Consider a sample XML file like this (let's call this file "test.xml"):

<foo> <bar id="t1"> <fail-message></fail-message> </bar> <baz id="t2"> <fail-message>yar</fail-message> </baz> </foo>
If I want to extract non-empty "fail-message" elements from that sort of XML data, the XPath expression would be:
//*[fail-message!='']
To apply that expression using my "exp" tool, the (bash) command line would be:
exp -p "//*[fail-message!='']" test.xml
Since I might want to see all the markup (including attributes) for nodes that match the expression, I included a '-x' option on my "exp" script to do just that. In this case, seeing the markup would be helpful if I want to look at the empty fail-messages (by using "=" instead of "!=" in the XPath expression).

In reply to Re: parsing xml by graff
in thread parsing xml by RM99

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.