Newbie help in selecting nodes

J

Jenna

I've been trying to get my head around this XML stuff and think I
understand it pretty well.

But the XML file I'm trying to use looks very different from the
examples I've seen. I don't think I'm selecting the nodes correctly.

Any suggestions or should I be looing in JS group?

XML file location: http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp

##########################################
# My Script
##########################################
<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp")

set
nodes=xmlDoc.selectNodes("/AIRPORT_STATUS_INFORMATION/Ground_Delay/ARPT/text()")

for each x in nodes
document.write("<xmp>")
document.write(x.xml)
document.write("</xmp>")
next

</script>
 
J

Joe Kesselman

Jenna said:
But the XML file I'm trying to use looks very different from the
examples I've seen.

Looks like absolutely standard XML to me, outside of the fact that its
<Dtd_file> element is not actually a DTD reference that a normal XML
parser would recognize as meaningful. I presume it's just there as
documentation, or to assist some specific tool.

I don't use VBScript, or the Microsoft tools, so I have absolutely no
opinion on the correctness of your script. It looks like you're trying
to use an XPath to extract the content of any <ARPT> elements, and for
each of those generate the XML text syntax (not a parsed XML data
structure) to wrap that in the strings <xmp> and </xmp>. Note that since
you aren't generating anything resembling a top-level element to enclose
these, if there's more than one this won't even be correct text syntax
for an XML document.
 
M

Martin Honnen

Jenna wrote:

Any suggestions or should I be looing in JS group?

If you use VBScript I don't think looking in a JS (JavaScript) group is
a good idea. For MSXML scripting questions the newsgroup
microsoft.public.xml is a good place.
XML file location: http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp

<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")

You need to be aware that XPath is only supported in MSXML 3 and later
while Microsoft.XMLDOM is a program id that also works in IE 5 or 5.5
without MSXML 3 installed.
It is a bit difficult to make suggestions on what to do but if you
really want to use XPath then trying to create
CreateObject("Msxml2.DOMDocument.3.0")
is necessary and works in IE 6. You also need to make sure you set the
SelectionLanguage property to XPath, see the example below.

With normal security settings client-side script can't load XML from
different origins so trying to access that URL with script in a HTML
document loaded from another HTTP server (e.g. http://example.com/)
might give you a permission denied or security error.
set
nodes=xmlDoc.selectNodes("/AIRPORT_STATUS_INFORMATION/Ground_Delay/ARPT/text()")

For the above XML

AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Delay_List/Ground_Delay/ARPT/text()
seems a better XPath.


Here is a complete example that works in IE 6 if loaded in a IE zone
like trusted sites where you can access other servers:

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<title>example</title>
<script type="text/vbscript">
Sub Show (Url)
Dim XmlDoc, ArptList, Arpt, Ul, Li
Set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
XmlDoc.async = False
If XmlDoc.load(Url) Then
XmlDoc.setProperty "SelectionLanguage", "XPath"
Set ArptList = XmlDoc.selectNodes(_

"AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Delay_List/Ground_Delay/ARPT/text()")
Set Ul = document.createElement("ul")
For Each Arpt in ArptList
Set Li = document.createElement("li")
Li.appendChild document.createTextNode(Arpt.nodeValue)
Ul.appendChild Li
Next
document.body.appendChild Ul
End If
End Sub
</script>
</head>
<body onload='Show("http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp")'>
<h1>ARPT</h1>
</body>
</html>
 
J

Jenna

Thanks for the replies, it's helps a lot!! After reading the replies
I'm starting to think I shouldn't try using vbscript to read this XML
file. Being that I am a newbie and am not to familiar with vbscript at
all. I'm going to try looking up some php example since that is
something U do use. But I will still try vbscript :)

Thanks everyone!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,852
Latest member
CarlaDowle

Latest Threads

Top