Problem with XML::LibXML processing nested nodes

From: James Munson (james_at_catheadlabs.com)
Date: 06/28/04


Date: Mon, 28 Jun 2004 17:33:06 GMT

After spending a few hours and not getting much done, I thought I'd try
asking here.
 From reading XML::LibXML's docs it looks like it does exactly what I
want, but I can't seem to get it to locate the nodes the way I'd expect
it to.

An example of my XML document is at the end of this message, what I'm
trying to extract is all <bgp-peer> nodes, but all attempts to match it
has failed. If I remove the bgp-information node so that bgp-peers are
directly under rpc-reply I can match it fine, but since I'll be getting
this xml directly from somewhere else that isn't really a good option.
Any help would be appreciated, I'd especially love some sample code (in
the nature of the camelids.xml stuff) to just show a simple foreach
through the bgp-peers. Thanks in advance.

James Munson
------------------------

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/6.1R1/junos">
     <bgp-information
xmlns="http://xml.juniper.net/junos/6.1R1/junos-routing">
         <group-count>1</group-count>
         <peer-count>35</peer-count>
         <down-peer-count>5</down-peer-count>
         <bgp-rib junos:style="brief">
             <name>inet.0</name>
             <total-prefix-count>191</total-prefix-count>
             <received-prefix-count>191</received-prefix-count>
             <active-prefix-count>131</active-prefix-count>
             <suppressed-prefix-count>0</suppressed-prefix-count>
             <history-prefix-count>0</history-prefix-count>
             <damped-prefix-count>0</damped-prefix-count>
             <total-external-prefix-count>191</total-external-prefix-count>
 
<active-external-prefix-count>131</active-external-prefix-count>
 
<suppressed-external-prefix-count>0</suppressed-external-prefix-count>
             <total-internal-prefix-count>0</total-internal-prefix-count>
             <active-internal-prefix-count>0</active-internal-prefix-count>
 
<suppressed-internal-prefix-count>0</suppressed-internal-prefix-count>
             <pending-prefix-count>0</pending-prefix-count>
             <bgp-rib-state>BGP restart is complete</bgp-rib-state>
         </bgp-rib>
         <bgp-rib junos:style="brief">
             <name>inet.2</name>
             <total-prefix-count>0</total-prefix-count>
             <received-prefix-count>0</received-prefix-count>
             <active-prefix-count>0</active-prefix-count>
             <suppressed-prefix-count>0</suppressed-prefix-count>
             <history-prefix-count>0</history-prefix-count>
             <damped-prefix-count>0</damped-prefix-count>
             <total-external-prefix-count>0</total-external-prefix-count>
             <active-external-prefix-count>0</active-external-prefix-count>
 
<suppressed-external-prefix-count>0</suppressed-external-prefix-count>
             <total-internal-prefix-count>0</total-internal-prefix-count>
             <active-internal-prefix-count>0</active-internal-prefix-count>
 
<suppressed-internal-prefix-count>0</suppressed-internal-prefix-count>
             <pending-prefix-count>0</pending-prefix-count>
             <bgp-rib-state>BGP restart is complete</bgp-rib-state>
         </bgp-rib>
         <bgp-peer junos:style="terse" heading="Peer AS
    InPkt OutPkt OutQ Flaps Last
Up/Dwn State|#Active/Received/Damped...">
             <peer-address>193.109.219.22</peer-address>
             <peer-as>20976</peer-as>
             <input-messages>5125</input-messages>
             <output-messages>5232</output-messages>
             <route-queue-count>0</route-queue-count>
             <flap-count>0</flap-count>
             <elapsed-time junos:seconds="153759">1d 18:42:39</elapsed-time>
             <description>Hotlinks Internet Services</description>
             <peer-state junos:format="2/2/0
0/0/0">Established</peer-state>
             <bgp-rib>
                 <name>inet.0</name>
                 <active-prefix-count>2</active-prefix-count>
                 <received-prefix-count>2</received-prefix-count>
                 <suppressed-prefix-count>0</suppressed-prefix-count>
             </bgp-rib>
             <bgp-rib>
                 <name>inet.2</name>
                 <active-prefix-count>0</active-prefix-count>
                 <received-prefix-count>0</received-prefix-count>
                 <suppressed-prefix-count>0</suppressed-prefix-count>
             </bgp-rib>
         </bgp-peer>
         <bgp-peer junos:style="terse">
             <peer-address>193.109.219.26</peer-address>
             <peer-as>20915</peer-as>
             <input-messages>37165</input-messages>
             <output-messages>37559</output-messages>
             <route-queue-count>0</route-queue-count>
             <flap-count>0</flap-count>
             <elapsed-time junos:seconds="1114861">1w5d21h</elapsed-time>
             <description>100 Percent IT</description>
             <peer-state junos:format="1/1/0
0/0/0">Established</peer-state>
             <bgp-rib>
                 <name>inet.0</name>
                 <active-prefix-count>1</active-prefix-count>
                 <received-prefix-count>1</received-prefix-count>
                 <suppressed-prefix-count>0</suppressed-prefix-count>
             </bgp-rib>
         </bgp-peer>
         <bgp-peer junos:style="terse">
             <peer-address>193.109.219.27</peer-address>
             <peer-as>20915</peer-as>
             <input-messages>37164</input-messages>
             <output-messages>37554</output-messages>
             <route-queue-count>0</route-queue-count>
             <flap-count>0</flap-count>
             <elapsed-time junos:seconds="1114848">1w5d21h</elapsed-time>
             <description>100 Percent IT</description>
             <peer-state junos:format="0/1/0
0/0/0">Established</peer-state>
             <bgp-rib>
                 <name>inet.0</name>
                 <active-prefix-count>0</active-prefix-count>
                 <received-prefix-count>1</received-prefix-count>
                 <suppressed-prefix-count>0</suppressed-prefix-count>
             </bgp-rib>
         </bgp-peer>
         <bgp-peer junos:style="terse">
             <peer-address>193.109.219.28</peer-address>
             <peer-as>12621</peer-as>
             <input-messages>33770</input-messages>
             <output-messages>37560</output-messages>
             <route-queue-count>0</route-queue-count>
             <flap-count>0</flap-count>
             <elapsed-time junos:seconds="1114863">1w5d21h</elapsed-time>
             <description>1aNetworks</description>
             <peer-state junos:format="3/4/0
0/0/0">Established</peer-state>
             <bgp-rib>
                 <name>inet.0</name>
                 <active-prefix-count>3</active-prefix-count>
                 <received-prefix-count>4</received-prefix-count>
                 <suppressed-prefix-count>0</suppressed-prefix-count>
             </bgp-rib>
         </bgp-peer>
</bgp-information>
</rpc-reply>