XML DOM Methods question

Discussion in 'ASP General' started by joe, May 29, 2005.

  1. joe

    joe Guest

    Hello: I'd really appreciate some feedback, bacause I've been stuck for two
    days with this. I am trying to parse XML returns from a certain website,
    sent back in response to my URL queries. The root node of the returned XML
    has a namespace instruction that I cannot get rid of. Why do I want to do
    that, you may ask? Well, I' m really a newbie with XML/XLST/XPath and so on,
    but I know that If I paste the XML return into a new XML document, get rid
    of the namespace stuff, and use that page instead of the original XML
    return, my code works! Below is a sample of my code so far.

    '------- being code------------
    Dim objXMLDoc, strURL, bLoadResult, objNodeList, x

    strURL = http://somesite/xmlreturn?param1=etc&param2=etc

    Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")

    objXMLDoc.async = False
    objXMLDoc.validateOnParse = False
    objXMLDoc.resolveExternals = False

    Dim bLoadResult

    bLoadResult = objXMLDoc.load(strURL)

    If bLoadResult Then

    '-- 1 (for additional command explained below)
    '-- 2 (for additional command explained below)

    Set objNodeList = objXMLDoc.selectNodes("/RootNode/SubNode1")

    Response.Write (objNodeList.length&"</br>")

    For Each x in objNodeList

    With Response
    .Write x.selectSingleNode("SubNode2").nodeTypedValue
    .Write "</br>"
    End With

    Next

    Else

    ..... error message here ....

    End if
    '------- end code------------

    As it is above, I can list the items in the copy-pasted XML file mentioned
    above (with namespace command deleted). However, with the original XML,
    objNodeList.length is 0. I thought I'd have to polish my Xpath instruction,
    so I added the following line where the number 1 is commented above:
    '-- 1
    objXMLDoc.setProperty "SelectionLanguage", "XPath"

    I also tried to get rid of the namespace instruction like below, inserting
    that
    where the number 2 is commented above:

    '-- 2
    objXMLDoc.setProperty "SelectionNamespaces", "xmlns=''"

    I also tried:

    objXMLDoc.setProperty "SelectionNamespaces", empty

    Well, that's it for my code. Is there any way around this namespace thing,
    or does that mean that I must have some XSL
    file somewhere that transforms the returned XML? As I said, I don't know
    much about all this, and any help is appreciated. Thanks in advance
    joe, May 29, 2005
    #1
    1. Advertising

  2. joe

    joe Guest

    Errata:

    > '------- being code------------
    > Dim objXMLDoc, strURL, bLoadResult, objNodeList, x
    > [snipped]
    > Dim bLoadResult


    By mistake I defined bLoadResult in my example. In the code I use this is
    fixed.
    joe, May 29, 2005
    #2
    1. Advertising

  3. joe

    Joe Fawcett Guest

    Look in the MSXML documents for setProperty "SelectionNamespaces". You'll then
    be able to select nodes in a namespace.

    --

    Joe (MVP - XML)

    https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5
    "joe" <> wrote in message
    news:31mme.1950$...
    > Hello: I'd really appreciate some feedback, bacause I've been stuck for two
    > days with this. I am trying to parse XML returns from a certain website,
    > sent back in response to my URL queries. The root node of the returned XML
    > has a namespace instruction that I cannot get rid of. Why do I want to do
    > that, you may ask? Well, I' m really a newbie with XML/XLST/XPath and so on,
    > but I know that If I paste the XML return into a new XML document, get rid
    > of the namespace stuff, and use that page instead of the original XML
    > return, my code works! Below is a sample of my code so far.
    >
    > '------- being code------------
    > Dim objXMLDoc, strURL, bLoadResult, objNodeList, x
    >
    > strURL = http://somesite/xmlreturn?param1=etc&param2=etc
    >
    > Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument.4.0")
    >
    > objXMLDoc.async = False
    > objXMLDoc.validateOnParse = False
    > objXMLDoc.resolveExternals = False
    >
    > Dim bLoadResult
    >
    > bLoadResult = objXMLDoc.load(strURL)
    >
    > If bLoadResult Then
    >
    > '-- 1 (for additional command explained below)
    > '-- 2 (for additional command explained below)
    >
    > Set objNodeList = objXMLDoc.selectNodes("/RootNode/SubNode1")
    >
    > Response.Write (objNodeList.length&"</br>")
    >
    > For Each x in objNodeList
    >
    > With Response
    > .Write x.selectSingleNode("SubNode2").nodeTypedValue
    > .Write "</br>"
    > End With
    >
    > Next
    >
    > Else
    >
    > .... error message here ....
    >
    > End if
    > '------- end code------------
    >
    > As it is above, I can list the items in the copy-pasted XML file mentioned
    > above (with namespace command deleted). However, with the original XML,
    > objNodeList.length is 0. I thought I'd have to polish my Xpath instruction,
    > so I added the following line where the number 1 is commented above:
    > '-- 1
    > objXMLDoc.setProperty "SelectionLanguage", "XPath"
    >
    > I also tried to get rid of the namespace instruction like below, inserting
    > that
    > where the number 2 is commented above:
    >
    > '-- 2
    > objXMLDoc.setProperty "SelectionNamespaces", "xmlns=''"
    >
    > I also tried:
    >
    > objXMLDoc.setProperty "SelectionNamespaces", empty
    >
    > Well, that's it for my code. Is there any way around this namespace thing,
    > or does that mean that I must have some XSL
    > file somewhere that transforms the returned XML? As I said, I don't know
    > much about all this, and any help is appreciated. Thanks in advance
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Joe Fawcett, Jun 4, 2005
    #3
    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. Thorsten Meininger
    Replies:
    0
    Views:
    429
    Thorsten Meininger
    Jul 28, 2004
  2. Replies:
    0
    Views:
    534
  3. Replies:
    3
    Views:
    517
    Stefan Behnel
    Aug 3, 2007
  4. Alan
    Replies:
    6
    Views:
    1,566
  5. Kenneth McDonald
    Replies:
    5
    Views:
    296
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page