First all, thanks, those are great suggestions, I didn't know about the setNamespace trick for defining context, however I still have to redefine it for every level as I progress through the xml right? Perhaps I'm not being clear. Incomming example:
<root xmls='urn:foo'>
<first_sub name='foo'>
<second_sub id='1'>
<third_sub>Foo</third_sub>
</second_sub>
<second_sub id='2'>
</second_sub>
</first_sub>
</root>
Now just imagine that there are multiple first_sub, second_sub, and third_sub elements nested in the example above. In order to get at all the values I want, as far as I can tell I have to do something like this(assuming $xml is set to the above):
my $parser = XML::LibXML->new();
my $data = $parser->parse_string ( $xml );
$data->setNamespace ( 'urn:foo', 'x' );
for my $first_sub ( $data->findnodes ('/x:root/x:first_sub')) {
my $name = $first_sub->getAttribute('name');
$first_sub->setNamespace ('urn:foo','x');
for my $second_sub ( $first_sub->findnodes ('./x:second_sub')) {
my $id = $second_sub->getAttribute('id');
$second_sub->setNamespace ('urn:foo','x');
for my $third_sub ( $second_sub->findnodes('./x:third_sub')) {
# do something with the values
}
}
}
So I'm pretty sure its confirmed that I can't remove the name space to avoid all this setting/defining and extra work in the XPath expressions, which was my original question, this is fine, I'll just stick to something like the above. thanks again. | [reply] [d/l] [select] |
| [reply] |