Solved

Converting some XML to variables in ASP

Posted on 2004-10-06
7
283 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
Comment Utility
0
 
LVL 19

Expert Comment

by:peh803
Comment Utility
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
Comment Utility
ah, what the.. ..got enough points and really need some fast help. bit more points.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Expert Comment

by:gete
Comment Utility
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
Comment Utility
hi gete, shouldn't oNode get a value in the loop?
0
 
LVL 2

Author Comment

by:florisb
Comment Utility
<%
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now