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 :-)
精彩评论