Solved

Converting some XML to variables in ASP

Posted on 2004-10-06
7
285 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
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 400 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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