Using MSXML and C++to get all children?

B

BCC

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
 
M

Martin Honnen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top