Note that there are some explanatory texts on larger screens.

plurals
  1. POMSXML Select Nodes Not Working
    primarykey
    data
    text
    <p>I am working on an automated testing app, and am currently in the process of writing a function that compares values between two XML files that should be identical, but may not be. Here is a sample of the XML I'm trying to process:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;report xmlns="http://www.**.com/**"&gt; &lt;subreport name="RBDReport"&gt; &lt;record rowNumber="1"&gt; &lt;field name="Time"&gt; &lt;value&gt;0&lt;/value&gt; &lt;/field&gt; &lt;field name="Reliability"&gt; &lt;value&gt;1.000000&lt;/value&gt; &lt;/field&gt; &lt;field name="Unreliability"&gt; &lt;value&gt;0.000000&lt;/value&gt; &lt;/field&gt; &lt;field name="Availability"&gt; &lt;value&gt; &lt;/value&gt; &lt;/field&gt; &lt;field name="Unavailability"&gt; &lt;value&gt; &lt;/value&gt; &lt;/field&gt; &lt;field name="Failure Rate"&gt; &lt;value&gt;N/A&lt;/value&gt; &lt;/field&gt; &lt;field name="Number of Failures"&gt; &lt;value&gt; &lt;/value&gt; &lt;/field&gt; &lt;field name="Total Downtime"&gt; &lt;value&gt; &lt;/value&gt; &lt;/field&gt; &lt;/record&gt; </code></pre> <p>(Note there may be multiple <code>&lt;subreport&gt;</code> elements and within those, multiple <code>&lt;record&gt;</code> elements.)</p> <p>What I'd like is to extract the <code>&lt;value&gt;</code> tags of two documents and then compare their values. That part I know how to do. The problem is the extraction itself.</p> <p>Since I'm stuck in C++, I'm using MSXML, and have written a wrapper to allow my app to abstract away the actual XML manipulation, in case I ever decide to change my data format.</p> <p>That wrapper, CSimpleXMLParser, loads an XML document and sets its "top record" to the document element of the XML document. (CRecord being an abstract class with CXMLRecord one of its subclasses, and which gives access to child records singularly or by group, and also allowing access to the "value" of the Record (values for child elements or attributes, in the case of CXMLRecord.) A CXMLRecord contains an MSXML::MSXMLDOMNodePtr and a pointer to an instance of a CSimpleXMLParser.) The wrapper also contains utility functions for returning children, which the CXMLRecord uses to return its child records.</p> <p>In my code, I do the following (trying to return all <code>&lt;subreport&gt;</code> nodes just to see if it works):</p> <pre><code>CSimpleXMLParser parserReportData; parserReportData.OpenXMLDocument(strPathToXML); bool bGetChildrenSuccess = parserReportData.GetFirstRecord()-&gt;GetChildRecords(listpChildren, _T("subreport")); </code></pre> <p>This is always returning false. The meat of the implementation of CXMLRecord::GetChildRecords() is basically</p> <pre><code>MSXML2::IXMLDOMNodeListPtr pListChildren = m_pParser-&gt;SelectNodes(strPath, m_pXMLNode); if (pListChildren-&gt;Getlength() == 0) { return false; } for (long l = 0; l &lt; pListChildren-&gt;Getlength(); ++l) { listRecords.push_back(new CXMLRecord(pListChildren-&gt;Getitem(l), m_pParser)); } return true; </code></pre> <p>And CSimpleXMLParser::SelectNodes() is:</p> <pre><code>MSXML2::IXMLDOMNodeListPtr CSimpleXMLParser::SelectNodes(LPCTSTR strXPathFilter, MSXML2::IXMLDOMNodePtr pXMLNode) { return pXMLNode-&gt;selectNodes(_bstr_t(strXPathFilter)); } </code></pre> <p>When run, the top record is definitely being set to the <code>&lt;report&gt;</code> element properly. I can do all sorts of things with it, like getting its child nodes (through the MSXML interface, not through my wrapper) or its name, etc. I know that my wrapper <em>can</em> work, because I use it elsewhere in the app for parsing an XML configuration file, and that works flawlessly.</p> <p>I thought maybe I was doing something faulty with the XPath query expression, but every permutation I could think of gives no joy. The <code>MSXML::IXMLDOMNodeListPtr</code> returned by <code>IXMLDOMNodePtr::SelectNodes()</code> is always of length 0 when I try to deal with this XML file.</p> <p>This is driving me crazy.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload