Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reading an XML file in ASP (classic)

Posted on 2012-12-27
2
Medium Priority
?
585 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 34

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview

782 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