XML Parsing Problem

  • Thread starter Thread starter pmclinn
  • Start date Start date
P

pmclinn

Below I have copied in an xml page I'm trying to parse out and the code
I'm currently using to do it. My code works great but I want to change
the .Item(0). part of this code to a typed refrence of the child node.
I have tried everything. How do I search through the xml for these
named child nodes?








Dim nodelist As XmlNodeList
Dim node As XmlNode
Dim temp As String
nodelist = doc.SelectNodes("/modeminfo/health")
For Each node In nodelist
'MsgBox(node.ChildNodes.Item(0).InnerText) ' 10 net
'MsgBox(node.ChildNodes.Item(1).InnerText) 'Modem State
'MsgBox(node.ChildNodes.Item(2).InnerText) 'sys desc
'MsgBox(node.ChildNodes.Item(3).InnerText) 'uptime
'MsgBox(node.ChildNodes.Item(4).InnerText) 'config file

temp = Split((node.ChildNodes.Item(5).InnerText),
":")(1).Trim
txtBrnsTx.Text = temp

temp = Split((node.ChildNodes.Item(6).InnerText),
":")(1).Trim
txtBrnsRx.Text = temp 'rx

temp = Split((node.ChildNodes.Item(7).InnerText),
":")(1).Trim
txtBrnsSnr.Text = temp 'snr

temp = Split((node.ChildNodes.Item(8).InnerText),
":")(1).Trim 'resets
txtBrnsResets.Text = temp

temp = Split((node.ChildNodes.Item(9).InnerText),
":")(1).Trim 'resets
txtBrnsLostSyncs.Text = temp

temp = Split((node.ChildNodes.Item(10).InnerText),
":")(1).Trim 'resets
txtT3.Text = temp


'MsgBox(node.ChildNodes.Item(10).InnerText) 't3s
'MsgBox(node.ChildNodes.Item(11).InnerText) 'healthproctime

Next


<?xml version="1.0" ?>
- <modeminfo>
- <health>
<tennet>10net IP: 10.xx.154.157</tennet>
<modemstate>Modem alive</modemstate>
<systemdescription>xxx</systemdescription>
<uptime>Uptime : (436490525) 50 days, 12 hours 28 mins 25.25
seconds</uptime>
<configfile>Config File : "e10_m_XX_ccowpe_c10.cm"</configfile>
<tx>Transmit Level (TX) : 34.5</tx>
- <rx>
Receive Level (RX) :
<font color="red">19.0</font>
</rx>
<snr>Rx Signal to Noise (SNR): 33.4</snr>
<resets>Resets : 1</resets>
<lostsyncs>Lost Syncs : 4</lostsyncs>
<t3s>T3 Timeouts : 5</t3s>
<healthproctime>26.4649</healthproctime>
</health>
<cpe>IP address MAC address xxxxx</cpe>
<bridgeproctime>20.9113</bridgeproctime>
<cmts>CMTS: something.net</cmts>
<mac>MAC: xx07.0e07.xxb9</mac>
- <extdata>
<macaddress>0007.0e07.2db9</macaddress>
<ipaddress>11.212.151.157</ipaddress>
<primsid>3801</primsid>
<qosprofileindex>116</qosprofileindex>
<interface>c60u5</interface>
<sysdescr />
<upstreampower>0.00dbmv(snr=24.63dbmv)</upstreampower>
<downstreampower>0.00dbmv(snr=-----dbmv)</downstreampower>
<timingoffset>2821</timingoffset>
<initialtimingoffset>2821</initialtimingoffset>
<receivedpower>7.50</receivedpower>
<macversion>doc1.0</macversion>
<qosprovisionedmode>doc1.0</qosprovisionedmode>
<enabledocsis2.0mode>y</enabledocsis2.0mode>
<phyoperatingmode>tdma</phyoperatingmode>
<capabilities>{frag=n,concat=y,phs=n,priv=bpi}</capabilities>
<sidsaidlimit>{maxussids=0,maxdssaids=0}</sidsaidlimit>

<optionalfilteringsupport>{802.1p=n,802.1q=n}</optionalfilteringsupport>


<transmitequalizersupport>{tapssymbol=0,numoftaps=0}</transmitequalizersupport>

<numberofcpeips>0(maxcpeips=5)</numberofcpeips>
<cfgmax-cpe>5</cfgmax-cpe>
<flaps>5(may116</flaps>
<errors>5crcs,0hcses</errors>
<stnmtnfailures>0aborts,0exhausted</stnmtnfailures>
<totalusflows>1(1active)</totalusflows>
<totaldsflows>1(1active)</totaldsflows>
<totalusdata>203330packets,24194640bytes</totalusdata>
<totalusthroughput>0bitssec,0packetssec</totalusthroughput>
<totaldsdata>77051packets,73160463bytes</totaldsdata>
<totaldsthroughput>0bitssec,0packetssec</totaldsthroughput>
<activeclassifiers>0(max=nolimit)</activeclassifiers>
<dsadsxmessages>permitall</dsadsxmessages>
<totaltimeonline>41d6h</totaltimeonline>
</extdata>
<extproctime>21.4699</extproctime>
<scriptproctime>68.8469</scriptproctime>
</modeminfo>
 
Instead of .ChildNodes.Item(#), try using .SelectSingleNode(targetNode)

For example, replace

MsgBox(node.ChildNodes.Item(0).InnerText)

with

MsgBox(node.SelectSingleNode("tennet").InnerText)


:
: Below I have copied in an xml page I'm trying to parse out and the
code
: I'm currently using to do it. My code works great but I want to
change
: the .Item(0). part of this code to a typed refrence of the child node.
: I have tried everything. How do I search through the xml for these
: named child nodes?
:
:
:
:
:
:
:
:
: Dim nodelist As XmlNodeList
: Dim node As XmlNode
: Dim temp As String
: nodelist = doc.SelectNodes("/modeminfo/health")
: For Each node In nodelist
: 'MsgBox(node.ChildNodes.Item(0).InnerText) ' 10 net
: 'MsgBox(node.ChildNodes.Item(1).InnerText) 'Modem State
: 'MsgBox(node.ChildNodes.Item(2).InnerText) 'sys desc
: 'MsgBox(node.ChildNodes.Item(3).InnerText) 'uptime
: 'MsgBox(node.ChildNodes.Item(4).InnerText) 'config file
:
: temp = Split((node.ChildNodes.Item(5).InnerText),
: ":")(1).Trim
: txtBrnsTx.Text = temp
:
: temp = Split((node.ChildNodes.Item(6).InnerText),
: ":")(1).Trim
: txtBrnsRx.Text = temp 'rx
:
: temp = Split((node.ChildNodes.Item(7).InnerText),
: ":")(1).Trim
: txtBrnsSnr.Text = temp 'snr
:
: temp = Split((node.ChildNodes.Item(8).InnerText),
: ":")(1).Trim 'resets
: txtBrnsResets.Text = temp
:
: temp = Split((node.ChildNodes.Item(9).InnerText),
: ":")(1).Trim 'resets
: txtBrnsLostSyncs.Text = temp
:
: temp = Split((node.ChildNodes.Item(10).InnerText),
: ":")(1).Trim 'resets
: txtT3.Text = temp
:
:
: 'MsgBox(node.ChildNodes.Item(10).InnerText) 't3s
: 'MsgBox(node.ChildNodes.Item(11).InnerText)
'healthproctime
:
: Next
:
:
: <?xml version="1.0" ?>
: - <modeminfo>
: - <health>
: <tennet>10net IP: 10.xx.154.157</tennet>
: <modemstate>Modem alive</modemstate>
: <systemdescription>xxx</systemdescription>
: <uptime>Uptime : (436490525) 50 days, 12 hours 28 mins 25.25
: seconds</uptime>
: <configfile>Config File : "e10_m_XX_ccowpe_c10.cm"</configfile>
: <tx>Transmit Level (TX) : 34.5</tx>
: - <rx>
: Receive Level (RX) :
: <font color="red">19.0</font>
: </rx>
: <snr>Rx Signal to Noise (SNR): 33.4</snr>
: <resets>Resets : 1</resets>
: <lostsyncs>Lost Syncs : 4</lostsyncs>
: <t3s>T3 Timeouts : 5</t3s>
: <healthproctime>26.4649</healthproctime>
: </health>
: <cpe>IP address MAC address xxxxx</cpe>
: <bridgeproctime>20.9113</bridgeproctime>
: <cmts>CMTS: something.net</cmts>
: <mac>MAC: xx07.0e07.xxb9</mac>
: - <extdata>
: <macaddress>0007.0e07.2db9</macaddress>
: <ipaddress>11.212.151.157</ipaddress>
: <primsid>3801</primsid>
: <qosprofileindex>116</qosprofileindex>
: <interface>c60u5</interface>
: <sysdescr />
: <upstreampower>0.00dbmv(snr=24.63dbmv)</upstreampower>
: <downstreampower>0.00dbmv(snr=-----dbmv)</downstreampower>
: <timingoffset>2821</timingoffset>
: <initialtimingoffset>2821</initialtimingoffset>
: <receivedpower>7.50</receivedpower>
: <macversion>doc1.0</macversion>
: <qosprovisionedmode>doc1.0</qosprovisionedmode>
: <enabledocsis2.0mode>y</enabledocsis2.0mode>
: <phyoperatingmode>tdma</phyoperatingmode>
: <capabilities>{frag=n,concat=y,phs=n,priv=bpi}</capabilities>
: <sidsaidlimit>{maxussids=0,maxdssaids=0}</sidsaidlimit>
:
:
<optionalfilteringsupport>{802.1p=n,802.1q=n}</optionalfilteringsupport>
:
:
:
<transmitequalizersupport>{tapssymbol=0,numoftaps=0}</transmitequalizers
upport>
:
: <numberofcpeips>0(maxcpeips=5)</numberofcpeips>
: <cfgmax-cpe>5</cfgmax-cpe>
: <flaps>5(may116</flaps>
: <errors>5crcs,0hcses</errors>
: <stnmtnfailures>0aborts,0exhausted</stnmtnfailures>
: <totalusflows>1(1active)</totalusflows>
: <totaldsflows>1(1active)</totaldsflows>
: <totalusdata>203330packets,24194640bytes</totalusdata>
: <totalusthroughput>0bitssec,0packetssec</totalusthroughput>
: <totaldsdata>77051packets,73160463bytes</totaldsdata>
: <totaldsthroughput>0bitssec,0packetssec</totaldsthroughput>
: <activeclassifiers>0(max=nolimit)</activeclassifiers>
: <dsadsxmessages>permitall</dsadsxmessages>
: <totaltimeonline>41d6h</totaltimeonline>
: </extdata>
: <extproctime>21.4699</extproctime>
: <scriptproctime>68.8469</scriptproctime>
: </modeminfo>
:
 
Back
Top