Solved

Reading an XML file in ASP (classic)

Posted on 2012-12-27
2
552 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

15 Experts available now in Live!

Get 1:1 Help Now