My Classic ASP code connects to a URL and displays XML, my code looks like below
Response.ContentType = "text/xml"
myRSSfile = "http://abc.com"
Set getPage = Server.CreateObject("Microsoft.XMLHTTP" )
getPage.Open "GET", myRSSfile, false
getPage.SetRequestHeader "Content-type", "text/xml"
getPage.Send
Response.Write(getPage.responseText)
'response.write getPage.Status
Set getPage = Nothing
XML as follows
<userContent xmlns="http://www.abc.com/userContent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.abc.com/abc.xsd">
<questions>
<question>
<item>
<sku>SCG20056-006</sku>
<title>Test me machine</title>
</item>
<text>
We are replacing a built in machine how it would be ?
</text>
<dateTime>2011-11-10T22:43:02Z</dateTime>
<answer>
<user>
<firstName>Raj</firstName>
<lastName>lastname</lastName>
</user>
<text>
We have been very happpy with the replacement
</text>
<dateTime>2011-11-21T21:00:24Z</dateTime>
</answer>
<answer>
<user>
<firstName>john</firstName>
<lastName>wright</lastName>
</user>
<text>
not so happy
</text>
<dateTime>2011-11-21T21:00:24Z</dateTime>
</answer>
</question>
</questions>
<comments/>
</userContent>
What i need to do is display
1) "questions/question/text" Tag
2) Display all the answers to that question that is this tag
"questions/question/answer/user/firstName" Tag
&
3) "questions/question/answer/text" Tag
Is it possible to do in Classic ASP?
The approach to take with this is to use XSL to perform a transform on the received XML to generate the HTML you would like to display. Here is a sample to get you started:
You would place this xsl in a file called for example "userContent.xsl" somewhere in you web site, for ease of example we'll put it in the root.
Now we need to tidy your code:
Notes:
responseXml
property which gives you a loaded XML Document to play with rather than theresponseText
. (Certainly don't use RegEx to do it).Option Explicit
in your scripts it will save you bags of time hunting bugs.It's certainly possible.
I'd try to do it with regular expressions.
To work out the expression there are lots of online tools.
edit: classic asp can handle xml documents (I incorrectly thought it had to remain as text, to be parsed) This example: Traverse XML document using asp should help you and is a much better solution than the reg ex option I offered (without totally thinking it through - soz)
I was able to do this using the following finally, thanks guys for all your help