Link to home
Start Free TrialLog in
Avatar of longjt
longjt

asked on

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?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

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 ?
Avatar of longjt
longjt

ASKER

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>
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.
Avatar of longjt

ASKER

Yes that helped dramatically! Now however all 1200 devices are coming up with the same information.
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).
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of longjt

ASKER

With this i get an error of:
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'node.selectSingleNode(...)'
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of longjt

ASKER

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.
Sorry, was getting my contexts mixed up :o)  

The code that riyasjef posted should work ok.
Avatar of longjt

ASKER

I'll try it again.
Avatar of longjt

ASKER

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
Does your XML contain 1200 RMEPlatform nodes ?  If so can you post a slightly longer XML document, with, say, 3 or 4 RMEPlatform nodes ?
oh...Just change cModel = node.selectSingleNode("//Cisco_Chassis/Model").text

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

RJ

Avatar of longjt

ASKER

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>
Try above proposal..everything will be ok
Avatar of longjt

ASKER

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
Avatar of longjt

ASKER

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.
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
Here its ok with the test data..