Displaying XML in ASP

Displaying XML in ASP

am 27.02.2007 22:32:20 von lejason

I am having trouble with a really simple problem! haha. How do you
display that data from on xml file. Here is my xml file called
"test.xml"




Jason
blue
16


Josh
red
10


Justin
blue
7




Now, what I want to do is to have it display all the elements per
. For example, I want an output to say be something to the
extent of....

Jason
blue
16

Josh
red
10

Justin
blue
7

So here is the ASP I have set up...but it doesnt work. I am having
problems with the syntax I think?


' Sets up the DOM

Dim xdoc
Set xdoc=Server.CreateObject("Microsoft.XMLDOM")
xdoc.async=false
xdoc.load("c:\test.xml")

if xdoc.parseError.errorcode<>0 then
response.write("there was obviously an error")
else
response.write("Things worked

")
end if


Set Root = xdoc.documentElement
Set NodeList = Root.getElementsByTagName("person")
For Each Elem In NodeList
response.write(Elem.firstChild.firstchild.nodeValue)
Next

============================

that code wont error, but it only shows the firstchild. So I tired
Elem.firstChild.childNodes(1).nodeValue right after it and it broke
"Object requried".

WTf?

help?
%>

Re: Displaying XML in ASP

am 27.02.2007 23:32:52 von Anthony Jones

wrote in message
news:1172611939.994146.145250@k78g2000cwa.googlegroups.com.. .
> I am having trouble with a really simple problem! haha. How do you
> display that data from on xml file. Here is my xml file called
> "test.xml"
>
>
>
>
> Jason
> blue
> 16
>

>
> Josh
> red
> 10
>

>
> Justin
> blue
> 7
>

>

>
>
> Now, what I want to do is to have it display all the elements per
> . For example, I want an output to say be something to the
> extent of....
>
> Jason
> blue
> 16
>
> Josh
> red
> 10
>
> Justin
> blue
> 7
>
> So here is the ASP I have set up...but it doesnt work. I am having
> problems with the syntax I think?
>

Yes you are.

>
> ' Sets up the DOM
>
> Dim xdoc
> Set xdoc=Server.CreateObject("Microsoft.XMLDOM")

Use MSXML2.DOMDocument.3.0, the ProgID above it ambiguous it's likely to
return a DOM document version 3 but it may not. Also this version specific
ProgID tightens up the XML syntax parsing a little.

> xdoc.async=false
> xdoc.load("c:\test.xml")

Parentheses should not be used here use:-

xdoc.load "c:\test.xml"

>
> if xdoc.parseError.errorcode<>0 then
> response.write("there was obviously an error")
> else
> response.write("Things worked

")
> end if

Parentheses in response.writes not needed.

>
>
> Set Root = xdoc.documentElement
> Set NodeList = Root.getElementsByTagName("person")

The following IMO would be better although in this case the result is the
same:-

Set NodeList = xdoc.SelectNodes("/root/person")

> For Each Elem In NodeList
> response.write(Elem.firstChild.firstchild.nodeValue)

Each Elem will be a person node. The firstChild of a person element node is
a name element node. The firstChild of a name element node is a text node.
Hence the above code writes out the content of the name node of each person
node, other nodes in the person is ignored.

> Next

Ditching the NodeList variable we can get to this:-

For Each elemPerson in xdoc.SelectNodes("/root/person")
For Each elem in elemPerson.SelectNodes("*")
Response.Write elem.tagName & ": " elem.Text & "
"
Next
Next

Note the Text property of an element returns all the inner text of an
element. This saves you having to access the internal text node.

Re: Displaying XML in ASP

am 28.02.2007 01:31:12 von lejason

First off - THANKS :)

However...while it didnt error, the page produced nothing. So, using
the said xml file and now this code :

<%
' Sets up the DOM

Dim xdoc
Set xdoc=Server.CreateObject("Microsoft.XMLDOM")
xdoc.async=false
xdoc.load("c:\test.xml")

if xdoc.parseError.errorcode<>0 then
response.write "there was obviously an error"
else
response.write "Things worked

"
end if

For Each elemPerson in xdoc.SelectNodes("/root/person")
For Each elem in elemPerson.SelectNodes("*")
Response.Write elem.tagName & ": " & elem.Text & "
"
Next
Next
%>

========================================

All I get is a blank page that says "Things worked" Also, I should
mention that im not using ASP.NET...just plain old-school ASP. So, im
not sure if thats why its not working?

so...any ideas?

Re: Displaying XML in ASP

am 28.02.2007 08:58:34 von exjxw.hannivoort

wrote on 28 feb 2007 in microsoft.public.inetserver.asp.general:

> First off - THANKS :)

[please always quote on usenet]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: Displaying XML in ASP

am 28.02.2007 11:02:44 von Anthony Jones

wrote in message
news:1172622672.492966.160750@h3g2000cwc.googlegroups.com...
> First off - THANKS :)
>
> However...while it didnt error, the page produced nothing. So, using
> the said xml file and now this code :
>
> <%
> ' Sets up the DOM
>
> Dim xdoc
> Set xdoc=Server.CreateObject("Microsoft.XMLDOM")
> xdoc.async=false
> xdoc.load("c:\test.xml")
>
> if xdoc.parseError.errorcode<>0 then
> response.write "there was obviously an error"
> else
> response.write "Things worked

"
> end if
>
> For Each elemPerson in xdoc.SelectNodes("/root/person")

Oops didn't read your XML properly the root node is called 'test' in you
xml:-

For Each elemPerson in xdoc.SelectNodes("/test/person")


> For Each elem in elemPerson.SelectNodes("*")
> Response.Write elem.tagName & ": " & elem.Text & "
"
> Next
> Next
> %>
>
> ========================================
>
> All I get is a blank page that says "Things worked" Also, I should
> mention that im not using ASP.NET...just plain old-school ASP. So, im
> not sure if thats why its not working?
>
> so...any ideas?
>

Re: Displaying XML in ASP

am 28.02.2007 21:53:31 von ten.xoc

Ah, it's fun to quickly realize why I stay out of this group for months at a
time. Too much effort spent on correcting etiquette without adding any
substance to the conversation.




>> First off - THANKS :)
>
> [please always quote on usenet]

Re: Displaying XML in ASP

am 01.03.2007 03:55:01 von mmcginty

"Aaron Bertrand [SQL Server MVP]" wrote in message
news:uJLcDq3WHHA.5008@TK2MSFTNGP05.phx.gbl...
> Ah, it's fun to quickly realize why I stay out of this group for months at
> a time. Too much effort spent on correcting etiquette without adding any
> substance to the conversation.

Indeed, but 99.99% comes from a single source, and thus it is relatively
easily ignored (as well it should be)... once you get past the irritation
factor.


-Mark


>
>>> First off - THANKS :)
>>
>> [please always quote on usenet]
>
>