Solved

Reading an XML file in ASP (classic)

Posted on 2012-12-27
2
555 Views
Last Modified: 2012-12-28
Hi,

I am using classic ASP, but am relatively new to it. I would like to read in an XML file for an image placeholder that displays a different image depending on the page number. Also have a default image if none is available in the XML. The XML will be similar to this...

<items>
      <item>
            <page_number>1</page_number>
            <image>/assets/image1.jpg</image>
      </item>
      <item>
            <page_number>2</page_number>
            <image>/assets/image2.jpg</image>
      </item>
</items>

But this can change to a better format should it need to.

Any help to start off would be great thanks.
0
Comment
Question by:Al4ddin2
2 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 38724649
here's a real good tutorial to get you going:

http://www.albofish.co.uk/reading-an-xml-feed-using-classic-asp/
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 38725911
Try the code below - be sure to read the comments:
Dim filename
'assuming your file is located at http://yoursite.com/files/items.xml
filename=Server.MapPath "/files/items.xml"

'this variable is meant for you to dynamically provide a value for it - most likely through 
'a POST  or GET request
Dim pageNumber 

'if using POST (and passing a field named "page", then replace the code below with 
'pageNumber=CInt( Request.Form("page") )
'if using GET, then use:
'pageNumber=CInt( Request.QueryString("page") )
pageNumber = 2

Set doc=Server.CreateObject("MSXML2.DOMDocument")
doc.async = false
doc.validateOnParse=false
doc.setProperty "SelectionLanguage", "XPath" 

doc.load filename

Set nodeItem=doc.selectSingleNode("/items/item[page_number=" & pageNumber & "]")

If nodeItem is Nothing Then
    Response.Write( "There is no item with page_number " & pageNumber )
Else
    Response.Write( nodeItem.selectSingleNode("image").text )
End If
Set result=Nothing
Set doc=Nothing

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now