simple XML::XPath question
by Lev Lvovsky other posts by this author
Jul 13 2006 5:29PM messages near this date
view in the new Beta List Site
Re: XPath/XML tool question
|
RE: simple XML::XPath question
& XSLT Hello,
I'm new to proper XML parsing (read: not a one-off regex) - I've gone
through the XPath tutorial on w3schools.com, but have a question in
regards to usage of XML::XPath in particular
say that this is my xml file which I'd like to parse:
<CompanyData>
<Owner> Joe Smith</Owner>
<Data>
<DataList>
<Id> first</Id>
<DataListElement1> first_element_1 </DataListElement1>
<DataListElement2> ... </DataListElement2>
<DataListElement3> ... </DataListElement3>
</DataList>
<DataList>
<Id> second</Id>
<DataListElement1> second_element_1 </DataListElement1>
<DataListElement2> ... </DataListElement2>
<DataListElement3> ... </DataListElement3>
</DataList>
<DataList>
<Id> third</Id>
<DataListElement1> ... </DataListElement1>
<DataListElement2> ... </DataListElement2>
<DataListElement3> ... </DataListElement3>
</DataList>
</Data>
</CompanyData>
What I'd like to do, is get all this stuff into a hash like this one:
$DataList{first} = ("first_element1", "...", "...");
Or perhaps a hash of hashes...
I would think that I could do this with a series of for loops, but
what confuses me a bit, is the type of object returned when I specify
the paths I'm interested in:
my @DataLists = $xp-> findnodes("/CompanyData/Data/Datalist);
Here, @nodeset is a XML::XPath::Node::Element, whereas I'd ideally
like for it to be an XML::XPath object to where I could run through
several more for loops via path declaration.
All that said, I could certainly be missing something in the usage of
XML::Path::Node::Element, but it seems that the way I'd want to use
it would be to run through a similar set of for loops:
foreach $DataList (@DataLists)
{
foreach $child ($DataList-> getChildNodes)
{
...
}
}
getChildNodes however returns just an array, not an array of
XML::XPath::Node::Element objects, further limiting what I can do
(seemingly).
I would be more than happy to hear that I'm using XML::XPath in a
horribly wrong way, or be pointed to some examples of its uses in
these sorts of nested data structures - the documentation mentions
that there're examples in "/t", but I don't know what, or where that
might be...
any help greatly appreciated!!
-lev
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Lev Lvovsky
Mark - BLS CTR Thomas
Yanick Champoux
Lev Lvovsky
|