Newbie help in selecting nodes

Discussion in 'XML' started by Jenna, Feb 23, 2006.

  1. Jenna

    Jenna Guest

    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>
     
    Jenna, Feb 23, 2006
    #1
    1. Advertising

  2. Jenna wrote:
    > 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.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Feb 24, 2006
    #2
    1. Advertising

  3. 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.

    > xmlDoc.load("http://www.fly.faa.gov/flyfaa/xmlAirportStatus.jsp")


    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>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 24, 2006
    #3
  4. Jenna

    Jenna Guest

    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!
     
    Jenna, Feb 24, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olivier Wulveryck
    Replies:
    1
    Views:
    682
    Andrew Thompson
    Sep 14, 2004
  2. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    414
    Patrick TJ McPhee
    Jun 17, 2004
  3. Tjerk Wolterink
    Replies:
    9
    Views:
    1,253
    Joris Gillis
    Feb 7, 2005
  4. Ryan  Adler
    Replies:
    2
    Views:
    395
  5. Replies:
    1
    Views:
    582
    Soren Kuula
    Aug 24, 2006
Loading...

Share This Page