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
Solved

Reading an XML file in ASP (classic)

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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