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
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
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
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
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 .DOMDocume nt")
oXML.async = False
oXML.load Server.MapPath("textfile.x ml")
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.
<%
Dim oXML, oNode, x
Set oXML = Server.CreateObject("MSXML
oXML.async = False
oXML.load Server.MapPath("textfile.x
x = 1
For Each oNode In oXML.selectNodes("/things/
Response.Write "thing" & x & ":<br>"
Response.Write oNode.getAttribute("id") & "<br>"
Response.Write oNode.getAttribute("name")
x = x + 1
Next
%>
I have only "compiled" this in my head. If you encounter any error, let us know.
ASKER
hi gete, shouldn't oNode get a value in the loop?
ASKER
<%
Dim oXML, oNode, x
Set oXML = Server.CreateObject("MSXML .DOMDocume nt")
oXML.async = False
oXML.load Server.MapPath("test.xml")
x = 1
For Each oNode In oXML.selectNodes("/bouwloc aties/bouw locatie")
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!
Dim oXML, oNode, x
Set oXML = Server.CreateObject("MSXML
oXML.async = False
oXML.load Server.MapPath("test.xml")
x = 1
For Each oNode In oXML.selectNodes("/bouwloc
Response.Write "bouwlocatie" & x & ":<br>"
Response.Write oNode.getAttribute("id") & "<br>"
Response.Write oNode.getAttribute("name")
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.xmlfiles.com/articles/seth/xmldatatransfer/default.asp