开发者

How to get attributes value while parsing xml with XML::DOM parser in perl?

开发者 https://www.devze.com 2022-12-11 23:16 出处:网络
How can I get actual attribute value instead of XML::DOM::NamedNodeMap=HASH(0xa3246d4) while using getAttribute function from XML::DOM parser

How can I get actual attribute value instead of XML::DOM::NamedNodeMap=HASH(0xa3246d4) while using getAttribute function from XML::DOM parser

Code

 my $parent = $doc->getElementsByTagName ("ParentTag")->item(0);
         my @parent = $childnodes->getChildNodes();
         {
           foreach  my $parent(@parent) 
            {
             if ($parent->getNodeType == ELEMENT_NODE)
               {
              开发者_如何学Go   print $parent->getNodeName;
                 print $parent->getAttributes;
               }
            }
         }


The return value of getAttributes looks to be an XML::DOM::NamedNodeMap object, so you can use that object to get attribute values by name, e.g.

my $nodemap = $parent->getAttributes;
my $node = $nodemap->getNamedItem('foo');

$node, in turn will be an XML::DOM::Node object, which will have its own methods and will have its own documentation.

There are a lot of classes and reading through all their docs will help. If it seems like too much, you might be able to make use of XML::Simple, which is usually good enough until its no longer good enough :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消