[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Converting some XML to variables in ASP

Posted on 2004-10-06
7
Medium Priority
?
290 Views
Last Modified: 2012-05-05
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




0
Comment
Question by:florisb
[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
7 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 12238384
0
 
LVL 19

Expert Comment

by:peh803
ID: 12238446
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
0
 
LVL 2

Author Comment

by:florisb
ID: 12238486
ah, what the.. ..got enough points and really need some fast help. bit more points.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:gete
ID: 12245288
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.
0
 
LVL 2

Author Comment

by:florisb
ID: 12248268
hi gete, shouldn't oNode get a value in the loop?
0
 
LVL 2

Author Comment

by:florisb
ID: 12248304
<%
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!
0
 
LVL 6

Accepted Solution

by:
gete earned 1200 total points
ID: 12254604
My mistake.. too much coding using attributes instead of child nodes in storing values.
This should work:

<%
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.selectSingleNode("id").text & "<br>"
    Response.Write oNode.selectSingleNode("name").text & "<br>"
    x = x + 1
Next
%>
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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