Parse XML document

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron Harter

    #1

    Parse XML document


    I have an XML DOM that contains a response from a server
    it looks somethng like this:

    <?xml version="1.0"?>
    <a:multistatu s xmlns:b="urn:uu id:c2f41010-65b3-11d1-a29f-00aa00c14882/"
    xmlns:e="urn:sc hemas:httpmail: " xmlns:d="urn:sc hemas:mailheade r:"
    xmlns:c="xml:" xmlns:f="urn:sc hemas-microsoft-com:office:offi ce"
    xmlns:a="DAV:">
    <a:response>
    <a:href>SomeDat a/a:href>
    <a:propstat>
    <a:status>HTT P/1.1 200 OK</a:status>
    <a:prop>
    <a:href>SomeDat a</a:href>
    <a:uid>AQEAAAAA CKqfAAAAAAAAAAA AAAAA</a:uid>
    </a:prop>
    </a:propstat>
    <a:propstat>
    <a:status>HTT P/1.1 404 Resource Not Found</a:status>
    <a:prop>
    <d:cc/>
    </a:prop>
    </a:propstat>
    </a:response>
    <a:response>
    <a:href>SomeMor eData</a:href>
    <a:propstat>
    <a:status>HTT P/1.1 200 OK</a:status>
    <a:prop>
    <a:href>SomeMOr eData</a:href>
    <a:uid>AQEAAAAA CKqgAAAAAAAAAAA AAAAA</a:uid>
    </a:prop>
    </a:propstat>
    <a:propstat>
    <a:status>HTT P/1.1 404 Resource Not Found</a:status>
    <a:prop>
    <d:cc/>
    </a:prop>
    </a:propstat>
    </a:response>

    There can be an arbitrry number of response elements in the document.
    I am able to get the number of responses elements in the document so I can
    llop through each on the responses
    nodes. The problem I have is I can't figure out how to access the named
    elements inside the nodelist that i create

    Am I going about this the wrong way? How do I access the elements by name in
    each seperate response element tree?

    I am using MSXML to do this




    --
    Ron Harter
    JP Mobile. Inc.
    ron.harter@jpmo bile.com

    --
    Ron Harter
    JP Mobile. Inc.
    ron.harter@jpmo bile.com

  • Keith M. Corbett

    #2
    Re: Parse XML document

    $oA5.6839@newss vr31.news.prodi gy.com...[color=blue]
    > There can be an arbitrry number of response elements in the document.
    > I am able to get the number of responses elements in the document so I can
    > llop through each on the responses
    > nodes. The problem I have is I can't figure out how to access the named
    > elements inside the nodelist that i create[/color]


    This is a FAQ, and you can find many examples by googling on the DOM API
    method names. Unfortunately that doesn't help if you don't know which
    methods to apply. :)

    Here's the basic pattern: Iterate over the node list, and for each node,
    check its nodeType(). If it is of type ELEMENT_NODE, identify its nodeName()
    (element or "tag" name). For each "interestin g" element node, get its
    children using getChildNodes() (for its first level children) or
    getElementsByTa gName() (named elements at any depth).

    HHH

    /kmc


    Comment

    Working...