[thelist] beginner XML ASP question
Aaron Johnson
ajlist at mindseye.com
Tue Oct 1 09:06:01 CDT 2002
--
[ Picked text/plain from multipart/alternative ]
Hi Jacques,
I reformatted your xml and wrote some code that gets the job done, check
it out:
<%
Dim objXML, objElement
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load (Server.MapPath("loadxml.xml"))
'make sure we have the right path to the xml packet
response.write("The path to the xml file is: " &
Server.MapPath("loadxml.xml") & "<br />")
set objElements = objXML.SelectSingleNode("web_articles")
Response.write("You can crawl the tree manually...<br />")
Response.Write("The value of the first child of element 0 is: " &
objElements.childNodes(0).childNodes(0).text & "<br />")
Response.Write("The value of the second child of element 0 is: " &
objElements.childNodes(0).childNodes(1).text & "<br />")
Response.Write("And so on and so forth...<br />")
Response.write("<br/><br /> Or you can crawl the tree
programatically...<br />")
for x=0 to objElements.childNodes(0).childNodes.length - 1
Response.Write("The value of the child '" & x & "' of element 0
is: " &
objElements.childNodes(0).childNodes(x).text & "<br />")
next
%>
<?xml version="1.0"?>
<web_articles>
<webObject>
<IDNo>1</IDNo>
<Title>How to code in XML</Title>
<Subject>XML</Subject>
<keywords>XML Code</keywords>
<body>First you do this, and the you do that.</body>
</webObject>
<webObject>
<IDNo>2</IDNo>
<Title>Press Release 3</Title>
<Subject>Press Release</Subject>
<keywords>Press Release ActiveCorp</keywords>
<body>We announced today the acquisition of
ActiveCorp.Hooray!</body>
</webObject>
</web_articles>
That work for ya?
AJ
On Tue, 2002-10-01 at 09:34, Jacques Capesius wrote:
> <snip>
> For one thing, your open/close tags don't match?
> </snip>
>
> see, I told you it was something stupid I was doing. Well, taking lon's much
> appreciated advice, I reformatted the xml document as follows.
>
> <?xml version="1.0"?>
> <articles>
> <webObject>
> <IDNo>1</IDNo>
> <Title>How to code in XML</Title>
> <Subject>XML</Subject>
> <keywords>XML Code</keywords>
> <content>Don't bother. It's too difficult.</content>
> </webObject>
> </articles>
>
> ...and I changed the code around to access it a little, so that it looks
> like this.
>
> Dim xml,root,i
> set xml = Server.CreateObject("Microsoft.XMLDOM")
> xml.async = False
> xml.load (Server.MapPath("test.xml"))
> set root = xml.documentElement
> For i = 0 To (root.childNodes.length)
> document.write(root.childNodes.item(i).text & "<br>")
> Next
>
> ... still, the root.childNodes.length throws an "object required" error.
> I'll continue to look into this, but any nudge in the right direction would
> be most appreciated. Thanks again, fellaz.
>
> -jacques :)
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>
--
More information about the thelist
mailing list