Using MSXML and C++to get all children?

Discussion in 'XML' started by BCC, Feb 27, 2005.

  1. BCC

    BCC Guest

    Hi,

    I am new to msxml, and am having a hard time figuring out how to get all
    children of a particular node. For example, if I have something like this:
    <?xml version="1.0" encoding="utf-8"?>
    <rules>
    <cell id="1">
    <type>CD4 Cell</type>
    <x>10</x>
    <y>10</y>
    <z>2</z>
    <is_static>false</is_static>
    </cell>
    <cell id="2">
    <type>CD4 Cell</type>
    <x>10</x>
    <y>10</y>
    <z>4</z>
    <is_static>false</is_static>
    </cell>
    <cell id="3">
    <type>CD4 Cell</type>
    <x>10</x>
    <y>10</y>
    <z>6</z>
    <is_static>false</is_static>
    </cell>
    </rules>

    I need to return a list of some sort that I can iterate through so I can
    create a new 'cell' object for each cell in the list and initialize it in
    the parameters given in the xml file (x, y, z, is_static, whatever). I can
    read in the file okay, and have it stored as a CComPtr<IXMLDOMDocument2>
    object (code I got from the web), but now Im at a loss as to how to parse it
    and get what I need out.

    Any suggestions, links or other helpful advice?

    Thanks,
    Bryan
    BCC, Feb 27, 2005
    #1
    1. Advertising

  2. BCC wrote:


    > I am new to msxml, and am having a hard time figuring out how to get all
    > children of a particular node. For example, if I have something like this:
    > <?xml version="1.0" encoding="utf-8"?>
    > <rules>
    > <cell id="1">
    > <type>CD4 Cell</type>
    > <x>10</x>
    > <y>10</y>
    > <z>2</z>
    > <is_static>false</is_static>
    > </cell>
    > <cell id="2">
    > <type>CD4 Cell</type>
    > <x>10</x>
    > <y>10</y>
    > <z>4</z>
    > <is_static>false</is_static>
    > </cell>
    > <cell id="3">
    > <type>CD4 Cell</type>
    > <x>10</x>
    > <y>10</y>
    > <z>6</z>
    > <is_static>false</is_static>
    > </cell>
    > </rules>
    >
    > I need to return a list of some sort that I can iterate through so I can
    > create a new 'cell' object for each cell in the list and initialize it in
    > the parameters given in the xml file (x, y, z, is_static, whatever). I can
    > read in the file okay, and have it stored as a CComPtr<IXMLDOMDocument2>
    > object (code I got from the web), but now Im at a loss as to how to parse it
    > and get what I need out.


    If you load the file and already have an IXMLDOMDocument2 then the
    document is parsed and you can now use the DOM API and the MSXML
    specific XPath API to extract data or change it.
    So your document object has a method named selectNodes for instance
    which takes a string with an XPath expression e.g. (JScript syntax)
    var nodeList = xmlDocument.selectNodes("/rules/cell")
    The documentation for MSXML is here:
    <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_xmlprod.asp>
    Look at the members of IXMLDOMDocument2 and the examples there.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 27, 2005
    #2
    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. William F. Robertson, Jr.
    Replies:
    1
    Views:
    969
    Kathy Burke
    Jun 25, 2003
  2. Alexander N. Spitzer
    Replies:
    1
    Views:
    531
    Lawrence Kirby
    Nov 12, 2004
  3. asim
    Replies:
    0
    Views:
    192
  4. Replies:
    4
    Views:
    183
  5. Replies:
    1
    Views:
    94
    Bart Van der Donck
    Dec 26, 2006
Loading...

Share This Page