Consulting

Results 1 to 8 of 8

Thread: XML Discussion

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    That will return the zip (the 5 being the zip code node)
    Matt;

    I'd love to take this into it's own thread. Since RPC is a pain with firewalls, HTTP requests are more prevalent and parsing responses a real art. I agree, node numbers are useless unless you already know the response. There is a freeware Chilkat XML parser that is superb assuming your aim is to parse responses as data objects. Another freeware from xStandard has HTML Tidy built into their OCX and a property ResponseAsXML which guarantees it will be loaded into the XMLDOM. However, when applied to REST (as opposed to SOAP) the response is misleading.

    What one needs is a generic pre-XML parser, but that's what they said about the Holy Grail

    I put my musings into a PDF document which I posted on another scripting BBS. It is 50kb and therefore above the limits here. Stan


    Quote Originally Posted by Matt
    I moved this to a new thread from http://www.vbaexpress.com/forum/showthread.php?t=10187 for anyone jumping in

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Oh, and one final word on this subject. I ran across an esoteric article about NameSpaces in XML and why xPath fails, most of which I shook my head over until the author suggested a work-around. I mentioned that [assuming oXML is the XMLDOM Object and you have loaded the HTTP ResponseText via LoadXML()]

    oXML.SelectSingleNode("//Zip").Text would come back empty.

    Well, if you were to remove the namespace `xmlns="urn:yahoo:maps"` prior to LoadXML() it would work fine. But who would know in advance that was mucking things up.

    oXML.SelectSingleNode(`//*[local-name()="Zip"]`).Text - works

    .03 Stan

  3. #3
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I did make this a new thread.. I havent tried this yet, but what about returning the XML to a string, looking for xmlns="..." and deleting that out? Would that work for all namespace problems or just for this yahoo example?

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by mvidas
    I did make this a new thread.. I havent tried this yet, but what about returning the XML to a string, looking for xmlns="..." and deleting that out? Would that work for all namespace problems or just for this yahoo example?
    No. In this particular instance you would eliminate the urn: but there is also an xsi - please, join me in my sense of confusion and wonderment Stan

    http://www.xml.com/pub/a/2004/02/25/qanda.html

  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Upon reading an article like that... I realize I know even less than I thought I did about xml

  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Well here goes: pseudo-quasi-crypto code to generate selection criteria for HTTP Responses.

    Assumption: Your are entered into the world of parsing xml responses from web services. You have 4 useful tools, 3 from Microsoft and one from www.xstandard.com (free download)
    oHTTP = CreateObject("Microsoft.XMLHTTP")
    oHTTP = CreateObject("MSXML2.XMLHTTP.4.0")
    oHTTP = Createobject("WinHttp.WinHttpRequest.5.1")
    oHTTP = CreateObject("XStandard.HTTP")

    1. with your choice of HTTP Object initialized, you perform either a GET or POST (The 3rd on the list is the leanest and perhaps best suited for multiple requests).

    2. If successful, you can pass the response from the server to a second object
    oXML = CreateObject("MSXML2.DOMDocument.4.0")
    oXML.Async = False
    oXML.setProperty("SelectionLanguage","XPath")

    3. Either you can or can't parse (NOTE: for the xStandard Object use ResponseString)
    If oXML.LoadXML(oHTTP.ResponseText)
    'can parse
    Else
    'can?t parse - call error handler
    End If
    4. So... what if you can parse? Let's just say at this point you wanted to just get a handle on the individual node names and write a line of code for each that you could test.
    cCode = ""
    For Each node In oXML.GetElementsByTagName("*")
       cCode = cCode & 'oXML.SelectSingleNode(`//*[local-name()="' & node.NodeName & '"]`)' & vbcrlf
    Next node
    By using the local-name() method of the DOM you overcome shooting blanks due to NameSpaces in the response code, because you decided it was easier to code that way than fix the Namespaces and besides the loop above can have cCode written to file.

    So using the URL that spawned this thread from another thread..
    cUrl = "http://api.local.yahoo.com/MapsServi...yvale&state=CA"

    you get something like

  7. #7
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    I meant
    cCode = "" For Each node In oXML.GetElementsByTagName("*") cCode = cCode & 'var' & node.NodeName & '=oXML.SelectSingleNode(`//*[local-name()="' & node.NodeName & '"]`).Text' & vbcrlf Next node
    But hopefully you get the jist, pre-code to write code snippets you can test and use in apps. Stan

  8. #8
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    ...and no discussion of XML is complete without mentioning SOAP...

    First, go here and look at the xml
    http://www.webcontinuum.net/webservices/ccydemo.wsdl

    Then go here to see how it works with Excel
    http://www.webcontinuum.net/ws_4.aspx

    Stan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •