Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2008, 06:29 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default Read xml data

I have following xml file, which I am trying to read with ASP code:

 
Quote:
quote:<?xml version="1.0" ?>
Quote:
<data>
<continent name="North America" listings="0" />
</continent>
<continent name="South America" listings="0" />
</continent>
<continent name="Europe" listings="0" />
</continent>
<continent name="Africa" listings="0" />
</continent>
<continent name="Asia" listings="0" />
</continent>
<continent name="Australia" listings="0" />
</continent>
</data>

Following is the ASP code, I am trying to use:

 
Quote:
quote:Dim oXML, xmlC, txtContinentName
Quote:

    Set oXML = Server.CreateObject("Microsoft.XMLDOM")
    oXML.async = False
    oXML.load (adPhysicalFlash & "countryindex.xml")

    set xmlC = oXML.selectNodes("//data/continent1")

    txtContinentName = xmlC.getAttribute("listings").text

response.Write(txtContinentName)
www.ithighway.co.uk
 
Old November 16th, 2008, 02:44 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Ummm...why would you think that "continent1" and "continent" would be the same thing???

Computers don't care whether you misspell by 1 letter or by 97 letters; if there's any difference AT ALL, the two strings are not the same.

And then, once you fix that, you need to understand the xmlC is going to be a *collection* of nodes. So how can you ask to get *ONE* attribute from an entire collection of nodes?

On top of that, why would you think that the attribute named "listings" would hold a continent name when clearly each of those tags says
     listings="0"
???

So *PROBABLY* you need code *SOMETHING* like this:
Code:
...
Set oXML = Server.CreateObject("Microsoft.XMLDOM")
oXML.async = False
oXML.load (adPhysicalFlash & "countryindex.xml")

set xmlC = oXML.selectNodes("//data/continent")
For nnum = 0 To xmlC.length-1
    set cont = xmlC(nnum)
    cname  = cont.getAttribute("name").text
    Response.Write "Continent: " & cname & "<BR>" & vbNewLine
Next
...
%>
 
Old December 1st, 2008, 02:38 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

Thanks for you response. I used your code and get the error on following line:

cname = cont.getAttribute("name").text

The error is:

Microsoft VBScript runtime (0x800A01A8)
Object required: '[string: "South America"]'



Please advice.

www.ithighway.co.uk
 
Old December 1st, 2008, 04:09 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I think an attribute is *ALREADY* a string, so the ".text" there is extraneous. Try without it:
   cname = cont.getAttribute("name")

I'd try it but don't have time right this minute.
 
Old December 2nd, 2008, 04:46 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 198
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via MSN to itHighway
Default

Excellent. It worked. Thanks!

www.ithighway.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
xml file read data from servlet kotaiah J2EE 0 October 15th, 2006 06:37 AM
Read data from XML then load it into combo box edizone XML 4 October 4th, 2006 05:11 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
xml Files read in asp with formated data shaileshk Classic ASP XML 1 June 7th, 2006 04:53 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.