• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Cant Get element text from XML file

Just started with XML yesterday and having a slight problem. I can load the XML file and succesfully search for patters. I can get the nodes into a "nodelist" but I cant assign any veriables to the text data from the elements! Here is the code:
<%
Set XML=Server.CreateObject("Microsoft.XMLDOM")
XML.async=false
XML.load("c:\temp\CiscoWorks\rme.export")

set nodelist = XML.selectNodes("//RMEPlatform")
rc = 0
for each node in nodelist
rc = rc + 1
response.write rc & "<br>"
cModel = node.selectSingleNode("//Cisco_Chassis/model").text
response.write cModel & "<br>"
next
%>
This is in asp. what is wrong with this?
0
longjt
Asked:
longjt
  • 9
  • 7
  • 4
2 Solutions
 
Carl TawnSystems and Integration DeveloperCommented:
Nothing is wrong with it at first glance.  Can you post a snippet of the XML so we can get a better idea of its structure ?
0
 
longjtAuthor Commented:
Sure:
     <?xml version="1.0" encoding='ISO-8859-1'?>
<InvDetails>
<SchemaInfo>
     <RMEServer>cw-s1</RMEServer>
     <CreatedAt>Fri Nov 05 15:27:15 CST 2004</CreatedAt>
     <SchemaVersion>1.0</SchemaVersion>
</SchemaInfo>
<RMEPlatform>
     <Cisco_Chassis>
          <InstanceID>1</InstanceID>
          <Model>VCH02-AP08</Model>
          <HardwareVersion>A0</HardwareVersion>
          <ChassisSystemType>airap1210               </ChassisSystemType>
          <NumberOfSlots>0</NumberOfSlots>
               <Cisco_Card>
                    <SoftwareIdentity></SoftwareIdentity>
                         <Cisco_FlashDevice>
                              <InstanceID>1</InstanceID>
                              <InstanceName>board flash</InstanceName>
                              <Size>8388608 Bytes</Size>
                              <NumberOfPartitions>1</NumberOfPartitions>
                              <ChipCount>1</ChipCount>
                              <Description>System Flash</Description>
                              <Removable>false</Removable>
                                   <Cisco_FlashPartition>
                                        <InstanceID>1</InstanceID>
                                        <InstanceName>flash</InstanceName>
                                        <Upgrade>direct</Upgrade>
                                        <NeedsErasure>false</NeedsErasure>
                                        <PartitionStatus>readWrite</PartitionStatus>
                                        <FileSystemSize>7741440 Bytes</FileSystemSize>
                                        <AvailableSpace>4042240 Bytes</AvailableSpace>
                                        <FileCount>151</FileCount>
                                   </Cisco_FlashPartition>
                         </Cisco_FlashDevice>
                         <Cisco_PhysicalMemory>
                              <MemoryType>RAM</MemoryType>
                              <Capacity>14669824 Bytes</Capacity>
                         </Cisco_PhysicalMemory>
                         <Cisco_PhysicalMemory>
                              <MemoryType>NVRAM</MemoryType>
                              <Capacity>32768 Bytes</Capacity>
                                   <AdditionalInformation>
                                        <AD name="NVRAMUsed" value="9512 Bytes"></AD>
                                   </AdditionalInformation>
                         </Cisco_PhysicalMemory>
                         <Cisco_PhysicalMemory>
                              <AdditionalInformation>
                                   <AD name="ROMVersion" value="Bootstrap program is C1200 boot loader"></AD>
                              </AdditionalInformation>
                         </Cisco_PhysicalMemory>
               </Cisco_Card>
     </Cisco_Chassis>
</RMEPlatform>
</InvDetails>
0
 
Carl TawnSystems and Integration DeveloperCommented:
Thanks for that.

It looks like it mat be a case-sensitivity issue. XPath queries are case-sensitive.

Your current XPath says "//Cisco_Chassis/model", whereas "model" in the XML has an uppercase M.

Try:

    cModel = node.selectSingleNode("//Cisco_Chassis/Model").text

Hope that helps.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
longjtAuthor Commented:
Yes that helped dramatically! Now however all 1200 devices are coming up with the same information.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Take out the // at the start of the query. This tells XPath to start searching from the root of the document so its always finding the first node that matches.

So you end up with:

    cModel = node.selectSingleNode("Cisco_Chassis/model").text

This will tell XPath to search from the current context node (the current RMEPlatform node in this case).
0
 
Carl TawnSystems and Integration DeveloperCommented:
oops, typo.  That should say:

    cModel = node.selectSingleNode("Cisco_Chassis/Model").text
0
 
longjtAuthor Commented:
With this i get an error of:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'node.selectSingleNode(...)'
0
 
riyasjefCommented:
Hi

This code is working fine for me

<%

Set XML=Server.CreateObject("Microsoft.XMLDOM")
XML.async=false
bln=XML.load("c:\inetpub\wwwroot\asp\test.xml")

If bln Then

set nodelist = XML.selectNodes("//RMEPlatform")

rc = 0

for each node in nodelist
      rc = rc + 1
      response.write rc & "<br>"
      cModel = node.selectSingleNode("//Cisco_Chassis/Model").text
      response.write cModel & "<br>"
next

End If

%>


RJ
0
 
longjtAuthor Commented:
Yes that works for getting the first node in the list. After that when you get to the second and third+ nodes the data does not increment, So I see the same data for all 1200 nodes.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Sorry, was getting my contexts mixed up :o)  

The code that riyasjef posted should work ok.
0
 
longjtAuthor Commented:
I'll try it again.
0
 
longjtAuthor Commented:
Nope that code does the same. here is an example of what i get:
1208
VCH02-AP08
1209
VCH02-AP08
1210
VCH02-AP08
1211
VCH02-AP08
1212
VCH02-AP08
1213
VCH02-AP08
1214
VCH02-AP08
1215
VCH02-AP08
1216
VCH02-AP08
0
 
Carl TawnSystems and Integration DeveloperCommented:
Does your XML contain 1200 RMEPlatform nodes ?  If so can you post a slightly longer XML document, with, say, 3 or 4 RMEPlatform nodes ?
0
 
riyasjefCommented:
oh...Just change cModel = node.selectSingleNode("//Cisco_Chassis/Model").text

to
cModel = node.selectSingleNode("Cisco_Chassis/Model").text

RJ

0
 
longjtAuthor Commented:
Yes, Ill post 3 full nodes:
<?xml version="1.0" encoding="ISO-8859-1"?>
<InvDetails>
<SchemaInfo>
      <RMEServer>cw-s1</RMEServer>
      <CreatedAt>Fri Nov 05 15:27:15 CST 2004</CreatedAt>
      <SchemaVersion>1.0</SchemaVersion>
</SchemaInfo>
<RMEPlatform>
      <Cisco_Chassis>
            <InstanceID>1</InstanceID>
            <Model>VCH02-AP09</Model>
            <HardwareVersion>A0</HardwareVersion>
            <ChassisSystemType>airap1210               </ChassisSystemType>
            <NumberOfSlots>0</NumberOfSlots>
                  <Cisco_Card>
                        <SoftwareIdentity/>
                              <Cisco_FlashDevice>
                                    <InstanceID>1</InstanceID>
                                    <InstanceName>board flash</InstanceName>
                                    <Size>8388608 Bytes</Size>
                                    <NumberOfPartitions>1</NumberOfPartitions>
                                    <ChipCount>1</ChipCount>
                                    <Description>System Flash</Description>
                                    <Removable>false</Removable>
                                          <Cisco_FlashPartition>
                                                <InstanceID>1</InstanceID>
                                                <InstanceName>flash</InstanceName>
                                                <Upgrade>direct</Upgrade>
                                                <NeedsErasure>false</NeedsErasure>
                                                <PartitionStatus>readWrite</PartitionStatus>
                                                <FileSystemSize>7741440 Bytes</FileSystemSize>
                                                <AvailableSpace>4042240 Bytes</AvailableSpace>
                                                <FileCount>151</FileCount>
                                          </Cisco_FlashPartition>
                              </Cisco_FlashDevice>
                              <Cisco_PhysicalMemory>
                                    <MemoryType>RAM</MemoryType>
                                    <Capacity>14669824 Bytes</Capacity>
                              </Cisco_PhysicalMemory>
                              <Cisco_PhysicalMemory>
                                    <MemoryType>NVRAM</MemoryType>
                                    <Capacity>32768 Bytes</Capacity>
                                          <AdditionalInformation>
                                                <AD name="NVRAMUsed" value="9512 Bytes"/>
                                          </AdditionalInformation>
                              </Cisco_PhysicalMemory>
                              <Cisco_PhysicalMemory>
                                    <AdditionalInformation>
                                          <AD name="ROMVersion" value="Bootstrap program is C1200 boot loader"/>
                                    </AdditionalInformation>
                              </Cisco_PhysicalMemory>
                  </Cisco_Card>
      </Cisco_Chassis>
<Cisco_NetworkElement>
<InstanceID>1</InstanceID>
<Description>Cisco Internetwork Operating System Software

IOS (tm) C1200 Software (C1200-K9W7-M), Version 12.2(13)JA3, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1)

Technical Support: http://www.cisco.com/techsupport

Copyright (c) 1986-2004 by cisco Systems, Inc.

Comp</Description>
<InstanceName>VCH02-AP09</InstanceName>
<PhysicalPosition>Outside room VCH 2509</PhysicalPosition>
<SysObjectId>1.3.6.1.4.1.9.1.525                                             </SysObjectId>
<OfficialHostName></OfficialHostName>
<Cisco_LogicalModule>
</Cisco_LogicalModule>
<Cisco_MemoryPool>
<InstanceName>Processor</InstanceName>
<PoolType>1</PoolType>
<AlternatePoolType>0</AlternatePoolType>
<IsValid>true</IsValid>
<Allocated>2458788 Bytes</Allocated>
<Free>4303716 Bytes</Free>
<LargestFree>4154776 Bytes</LargestFree>
</Cisco_MemoryPool>
<Cisco_MemoryPool>
<InstanceName>I/O</InstanceName>
<PoolType>2</PoolType>
<AlternatePoolType>0</AlternatePoolType>
<IsValid>true</IsValid>
<Allocated>413008 Bytes</Allocated>
<Free>1684144 Bytes</Free>
<LargestFree>1635384 Bytes</LargestFree>
</Cisco_MemoryPool>
<AdditionalInformation>
<AD name="ConfigReg" value="0x0000000f"/>
</AdditionalInformation>
</Cisco_NetworkElement>
<Cisco_ComputerSystemPackage>
<Antecedent>1</Antecedent>
<Dependent>1</Dependent>
</Cisco_ComputerSystemPackage>
</RMEPlatform>
<RMEPlatform>
      <Cisco_Chassis>
            <InstanceID>1</InstanceID>
            <Model>VCH02-AP08</Model>
            <HardwareVersion>A0</HardwareVersion>
            <ChassisSystemType>airap1210               </ChassisSystemType>
            <NumberOfSlots>0</NumberOfSlots>
                  <Cisco_Card>
                        <SoftwareIdentity/>
                              <Cisco_FlashDevice>
                                    <InstanceID>1</InstanceID>
                                    <InstanceName>board flash</InstanceName>
                                    <Size>8388608 Bytes</Size>
                                    <NumberOfPartitions>1</NumberOfPartitions>
                                    <ChipCount>1</ChipCount>
                                    <Description>System Flash</Description>
                                    <Removable>false</Removable>
                                          <Cisco_FlashPartition>
                                                <InstanceID>1</InstanceID>
                                                <InstanceName>flash</InstanceName>
                                                <Upgrade>direct</Upgrade>
                                                <NeedsErasure>false</NeedsErasure>
                                                <PartitionStatus>readWrite</PartitionStatus>
                                                <FileSystemSize>7741440 Bytes</FileSystemSize>
                                                <AvailableSpace>4042240 Bytes</AvailableSpace>
                                                <FileCount>151</FileCount>
                                          </Cisco_FlashPartition>
                              </Cisco_FlashDevice>
                              <Cisco_PhysicalMemory>
                                    <MemoryType>RAM</MemoryType>
                                    <Capacity>14669824 Bytes</Capacity>
                              </Cisco_PhysicalMemory>
                              <Cisco_PhysicalMemory>
                                    <MemoryType>NVRAM</MemoryType>
                                    <Capacity>32768 Bytes</Capacity>
                                          <AdditionalInformation>
                                                <AD name="NVRAMUsed" value="9512 Bytes"/>
                                          </AdditionalInformation>
                              </Cisco_PhysicalMemory>
                              <Cisco_PhysicalMemory>
                                    <AdditionalInformation>
                                          <AD name="ROMVersion" value="Bootstrap program is C1200 boot loader"/>
                                    </AdditionalInformation>
                              </Cisco_PhysicalMemory>
                  </Cisco_Card>
      </Cisco_Chassis>
<Cisco_NetworkElement>
<InstanceID>1</InstanceID>
<Description>Cisco Internetwork Operating System Software

IOS (tm) C1200 Software (C1200-K9W7-M), Version 12.2(13)JA3, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1)

Technical Support: http://www.cisco.com/techsupport

Copyright (c) 1986-2004 by cisco Systems, Inc.

Comp</Description>
<InstanceName>VCH02-AP08</InstanceName>
<PhysicalPosition>Outside room VCH 2509</PhysicalPosition>
<SysObjectId>1.3.6.1.4.1.9.1.525                                             </SysObjectId>
<OfficialHostName></OfficialHostName>
<Cisco_LogicalModule>
</Cisco_LogicalModule>
<Cisco_MemoryPool>
<InstanceName>Processor</InstanceName>
<PoolType>1</PoolType>
<AlternatePoolType>0</AlternatePoolType>
<IsValid>true</IsValid>
<Allocated>2458788 Bytes</Allocated>
<Free>4303716 Bytes</Free>
<LargestFree>4154776 Bytes</LargestFree>
</Cisco_MemoryPool>
<Cisco_MemoryPool>
<InstanceName>I/O</InstanceName>
<PoolType>2</PoolType>
<AlternatePoolType>0</AlternatePoolType>
<IsValid>true</IsValid>
<Allocated>413008 Bytes</Allocated>
<Free>1684144 Bytes</Free>
<LargestFree>1635384 Bytes</LargestFree>
</Cisco_MemoryPool>
<AdditionalInformation>
<AD name="ConfigReg" value="0x0000000f"/>
</AdditionalInformation>
</Cisco_NetworkElement>
<Cisco_ComputerSystemPackage>
<Antecedent>1</Antecedent>
<Dependent>1</Dependent>
</Cisco_ComputerSystemPackage>
</RMEPlatform><RMEPlatform>
      <Cisco_Chassis>
            <InstanceID>1</InstanceID>
            <Model>VCH02-AP07</Model>
            <HardwareVersion>A0</HardwareVersion>
            <ChassisSystemType>airap1210               </ChassisSystemType>
            <NumberOfSlots>0</NumberOfSlots>
                  <Cisco_Card>
                        <SoftwareIdentity/>
                              <Cisco_FlashDevice>
                                    <InstanceID>1</InstanceID>
                                    <InstanceName>board flash</InstanceName>
                                    <Size>8388608 Bytes</Size>
                                    <NumberOfPartitions>1</NumberOfPartitions>
                                    <ChipCount>1</ChipCount>
                                    <Description>System Flash</Description>
                                    <Removable>false</Removable>
                                          <Cisco_FlashPartition>
                                                <InstanceID>1</InstanceID>
                                                <InstanceName>flash</InstanceName>
                                                <Upgrade>direct</Upgrade>
                                                <NeedsErasure>false</NeedsErasure>
                                                <PartitionStatus>readWrite</PartitionStatus>
                                                <FileSystemSize>7741440 Bytes</FileSystemSize>
                                                <AvailableSpace>4042240 Bytes</AvailableSpace>
                                                <FileCount>151</FileCount>
                                          </Cisco_FlashPartition>
                              </Cisco_FlashDevice>
                              <Cisco_PhysicalMemory>
                                    <MemoryType>RAM</MemoryType>
                                    <Capacity>14669824 Bytes</Capacity>
                              </Cisco_PhysicalMemory>
                              <Cisco_PhysicalMemory>
                                    <MemoryType>NVRAM</MemoryType>
                                    <Capacity>32768 Bytes</Capacity>
                                          <AdditionalInformation>
                                                <AD name="NVRAMUsed" value="9512 Bytes"/>
                                          </AdditionalInformation>
                              </Cisco_PhysicalMemory>
                              <Cisco_PhysicalMemory>
                                    <AdditionalInformation>
                                          <AD name="ROMVersion" value="Bootstrap program is C1200 boot loader"/>
                                    </AdditionalInformation>
                              </Cisco_PhysicalMemory>
                  </Cisco_Card>
      </Cisco_Chassis>
<Cisco_NetworkElement>
<InstanceID>1</InstanceID>
<Description>Cisco Internetwork Operating System Software

IOS (tm) C1200 Software (C1200-K9W7-M), Version 12.2(13)JA3, EARLY DEPLOYMENT RELEASE SOFTWARE (fc1)

Technical Support: http://www.cisco.com/techsupport

Copyright (c) 1986-2004 by cisco Systems, Inc.

Comp</Description>
<InstanceName>VCH02-AP07</InstanceName>
<PhysicalPosition>Outside room VCH 2509</PhysicalPosition>
<SysObjectId>1.3.6.1.4.1.9.1.525                                             </SysObjectId>
<OfficialHostName></OfficialHostName>
<Cisco_LogicalModule>
</Cisco_LogicalModule>
<Cisco_MemoryPool>
<InstanceName>Processor</InstanceName>
<PoolType>1</PoolType>
<AlternatePoolType>0</AlternatePoolType>
<IsValid>true</IsValid>
<Allocated>2458788 Bytes</Allocated>
<Free>4303716 Bytes</Free>
<LargestFree>4154776 Bytes</LargestFree>
</Cisco_MemoryPool>
<Cisco_MemoryPool>
<InstanceName>I/O</InstanceName>
<PoolType>2</PoolType>
<AlternatePoolType>0</AlternatePoolType>
<IsValid>true</IsValid>
<Allocated>413008 Bytes</Allocated>
<Free>1684144 Bytes</Free>
<LargestFree>1635384 Bytes</LargestFree>
</Cisco_MemoryPool>
<AdditionalInformation>
<AD name="ConfigReg" value="0x0000000f"/>
</AdditionalInformation>
</Cisco_NetworkElement>
<Cisco_ComputerSystemPackage>
<Antecedent>1</Antecedent>
<Dependent>1</Dependent>
</Cisco_ComputerSystemPackage>
</RMEPlatform>
</InvDetails>
0
 
riyasjefCommented:
Try above proposal..everything will be ok
0
 
longjtAuthor Commented:
No with the line above i get an error:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'node.selectSingleNode(...)'
/datafeed/test.asp, line 11

line 11 is:       cModel = node.selectSingleNode("Cisco_Chassis/Model").text
0
 
longjtAuthor Commented:
OK I found whay was causing the page to only see the first node. It was the file extension. Even though the file was a valid XML file it had an export extension.
0
 
Carl TawnSystems and Integration DeveloperCommented:
I wrote this quick test in VB and it works ok:

    Set oxml = New DOMDocument40
    oxml.Load "c:\temp.xml"

    Set onodes = oxml.selectNodes("//RMEPlatform")

    For Each node In onodes
        Debug.Print node.selectSingleNode("Cisco_Chassis/Model").Text
    Next
0
 
riyasjefCommented:
Here its ok with the test data..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now