Solved

Reading an XML file in ASP (classic)

Posted on 2012-12-27
2
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB script help 23 50
Powershell Regex Replace Question 5 42
SQL Stored Procedure Speed Improvements 6 55
JSON Error in ASP Page 3 38
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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