Link to home
Start Free TrialLog in
Avatar of florisb
florisb

asked on

Converting some XML to variables in ASP

Hi, I would like to open a text file containing some XML, looping stuff  and putting it in variables. I did dis before in Coldfusion and normally don't work woth ASP. I was hoping for a 'working example' for the following scenario.
Thanks in advance! Floris.

ps. making question difficult. 250 points is ok when asking working example in case like this? tanx.


textfile.xml; xml format; 0..x time a thing struct.
<things>
 <thing>
  <id>1</id>
  <name>bla</name>
 </thing>
 <thing>
  <id>3</id>
  <name>bli</name>
 </thing>
<things>

asp file in pseudo code (I'm looking for the real stuff please!-)..)

<%
Dim mVar,myXMLVar, x

x = 1
myXMLVar = openXmlFile("textfile.xml")

While not myXMLVar.End do
 myVar = myXMLVar.thing
 response.write "thing" & x & ":<br>"
 response.write myVar.id & "<br>"
 response.write myVar.name & "<br>"
 x = x + 1
end while
%>

which should given the xml, then give the output:
thing1
1
bla
thing2
3
bli




Avatar of jitganguly
jitganguly

Avatar of peh803
Here's a good tutorial that will not only give you a working example, but explain why it's doing what it's doing.

http://stardeveloper.com:8080/articles/display.html?article=2000072801&page=1

Apologies to any that may have recently posted if this is a repost...

peh803
Avatar of florisb

ASKER

ah, what the.. ..got enough points and really need some fast help. bit more points.
Following your pseudo code:

<%
Dim oXML, oNode, x

Set oXML = Server.CreateObject("MSXML.DOMDocument")
oXML.async = False
oXML.load Server.MapPath("textfile.xml")

x = 1
For Each oNode In oXML.selectNodes("/things/thing")
    Response.Write "thing" & x & ":<br>"
    Response.Write oNode.getAttribute("id") & "<br>"
    Response.Write oNode.getAttribute("name") & "<br>"
    x = x + 1
Next
%>

I have only "compiled" this in my head. If you encounter any error, let us know.
Avatar of florisb

ASKER

hi gete, shouldn't oNode get a value in the loop?
Avatar of florisb

ASKER

<%
Dim oXML, oNode, x

Set oXML = Server.CreateObject("MSXML.DOMDocument")
oXML.async = False
oXML.load Server.MapPath("test.xml")

x = 1
For Each oNode In oXML.selectNodes("/bouwlocaties/bouwlocatie")
    Response.Write "bouwlocatie" & x & ":<br>"
    Response.Write oNode.getAttribute("id") & "<br>"
    Response.Write oNode.getAttribute("name") & "<br>"
    x = x + 1
Next
%>

with

<?xml version="1.0" encoding="iso-8859-1" ?>
<bouwlocaties>
 <bouwlocatie>
  <id>1001</id>
  <name>in de bushbush</name>
 </bouwlocatie>
 <bouwlocatie>
  <id>1002</id>
  <name>op het dak</name>
 </bouwlocatie>
</bouwlocaties>

gives me just

bouwlocatie1:


bouwlocatie2:

and no values...;-(

thanks!
ASKER CERTIFIED SOLUTION
Avatar of gete
gete

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial