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):<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>
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.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 } } }
In reply to Re^2: LibXML - Removing Namespace?
by Anonymous Monk
in thread LibXML - Removing Namespace?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |