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?
longjtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.