|We don't bite newbies here... much|
XML parsing and Listsby madbee (Acolyte)
|on Jul 04, 2013 at 23:31 UTC||Need Help??|
madbee has asked for the
wisdom of the Perl Monks concerning the following question:
Hello! I'm trying to parse an XML file, sample of which is below.
I am using: XML::LibXML for parsing this. I can easily get the entire section of lists. However, my problem is I just need to know how many LIST elements are there. One way I was thinking is:
1. Parse the xml for the sec4. store contents in array
2. Loop through array until I get the first LIST element. Track counter;
3. Increment counter for each LIST element found until the last LIST element is reached.
While this approach may work, I feel this is very kludgy. So I am looking to see if there is an elegant way I can count the number of list elements in a section
The challenge ofcourse is that not every XML file I am parsing has the exact same structure. There could be variations where the <P1> This is the criteria</P1> may not exist before the start of the list.
Hoping someone here has some thoughts on how best I can capture the count of list elements
Sadly, I cannot use XPath here since I have an entire piece of code built around LibXML parsing. Also I'm having an Xpath installation nightmare which I just cannot get past.
Thanks so much in advance.