XML::LibXML, namespaces and findvalue

后端 未结 2 1557
滥情空心
滥情空心 2020-12-10 18:15

I\'m using XML::LibXML to parse an XML document with a namespace. I therefore use XML::LibXML::XPathContext to findnodes using the XPath //u:model

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 18:33

    You can't use $node->findvalue() because of the whole default namespace thing. However, you can reuse your XML::LibXML::XPathContext object to find the values you want:

    for my $node ( $context->findnodes('//u:model') ) {
       my $mh   = $context->findvalue('u:mh', $node);
       my $attr = $context->findvalue('u:attribute', $node);
       print "mh = $mh, attr = $attr\n";
    }
    

提交回复
热议问题