Trying to print XML elements but only one prints when there should be multiple. I'm trying to print the node name and all of it's extendedAttributes. Here is a sample of the input & output file and the script I‘m using.
########## Output
172.30.1.7
NA_ID
26401
jfllt000fi01.atoesa.com
Device Category
Server
#!/usr/bin/perl -w use XML::LibXML; use strict; use warnings; my $filename = 'topo-small-sample.xml'; ## NNM XML Topology Source + File my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($filename); foreach my $node($doc->findnodes('/topo/node')){ my ($nodename) = $node->findnodes('./name'); my ($caname) = $node->findnodes('./extendedAttributes/attribut +e'); print $nodename->to_literal, "\n", "\t", $caname->to_literal, +"\t", "\n" } ########## Source file example <?xml version="1.0" encoding="UTF-8"?> <topo> <node> <shortname>10B_Gate_W</shortname> <name>172.30.1.7</name> <deviceDescription>Two Network Module Slots, Four WIC slots, T +wo Gigabit Ethernet ports 3800 family router</deviceDescription> <deviceCategory>Router</deviceCategory> <deviceFamily>Cisco 3800 Series Integrated Services Routers</d +eviceFamily> <deviceVendor>Cisco</deviceVendor> <capabilities> <capability>com.hp.nnm.capability.card.cisco.entfructrl</c +apability> <capability>com.hp.ov.nnm.capability.metric.cisco.env.fan< +/capability> <capability>com.hp.nnm.capability.metric.cpm2</capability> </capabilities> <extendedAttributes> <attribute> <name>NA_ID</name> <value>26401</value> </attribute> <attribute> <name>Device Category</name> <value>Router</value> </attribute> </extendedAttributes> </node> <node> <shortname>jfllt000fi01</shortname> <name>jfllt000fi01.atoesa.com</name> <deviceDescription>Microsoft Windows NT Server</deviceDescript +ion> <deviceCategory>Server</deviceCategory> <deviceFamily>Microsoft Windows NT Servers</deviceFamily> <deviceVendor>Microsoft</deviceVendor> <capabilities> <capability>com.hp.nnm.capability.metric.hr</capability> <capability>com.hp.nnm.capability.metric.ietf.DISK_HOST-RE +SOURCES-MIB</capability> </capabilities> <extendedAttributes> <attribute> <name>Device Category</name> <value>Server</value> </attribute> </extendedAttributes> </node> </topo>
In reply to XML Output by bitretriever
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |