MSXML Select No-Operate Nodes

I am working on an automated test application, and am currently in the process of writing a function that compares values ​​between two XML files, which should be identical, but may not be. Here is an example of the XML I'm trying to process:

<?xml version="1.0" encoding="utf-8"?>
<report xmlns="http://www.**.com/**">
  <subreport name="RBDReport">
    <record rowNumber="1">
      <field name="Time">
        <value>0</value>
      </field>
      <field name="Reliability">
        <value>1.000000</value>
      </field>
      <field name="Unreliability">
        <value>0.000000</value>
      </field>
      <field name="Availability">
        <value> </value>
      </field>
      <field name="Unavailability">
        <value> </value>
      </field>
      <field name="Failure Rate">
        <value>N/A</value>
      </field>
      <field name="Number of Failures">
        <value> </value>
      </field>
      <field name="Total Downtime">
        <value> </value>
      </field>
    </record>

(Note that there may be several elements <subreport>and within them several elements <record>.)

I would like to extract tags <value>from two documents and then compare their values. This is the part that I know how to do. The problem is the extraction itself.

Since I'm stuck in C ++, I use MSXML and wrote a wrapper to let my application ignore the actual manipulation of XML if I ever decided to change my data format.

, CSimpleXMLParser, XML- " " XML-. (CRecord CXMLRecord , "" ( , CXMLRecord.) CXMLRecord MSXML:: MSXMLDOMNodePtr CSimpleXMLParser.) , CXMLRecord .

( <subreport>, , ):

CSimpleXMLParser parserReportData;
parserReportData.OpenXMLDocument(strPathToXML);
bool bGetChildrenSuccess = parserReportData.GetFirstRecord()->GetChildRecords(listpChildren, _T("subreport"));

false. CXMLRecord:: GetChildRecords()

MSXML2::IXMLDOMNodeListPtr pListChildren = m_pParser->SelectNodes(strPath, m_pXMLNode);

if (pListChildren->Getlength() == 0)
{
    return false;
}

for (long l = 0; l < pListChildren->Getlength(); ++l)
{
    listRecords.push_back(new CXMLRecord(pListChildren->Getitem(l), m_pParser));
}

return true;

CSimpleXMLParser:: SelectNodes():

MSXML2::IXMLDOMNodeListPtr CSimpleXMLParser::SelectNodes(LPCTSTR strXPathFilter, MSXML2::IXMLDOMNodePtr pXMLNode)
{
    return pXMLNode->selectNodes(_bstr_t(strXPathFilter));
}

<report>. , , ( MSXML, ) .. , , XML .

, , , - XPath, , , . MSXML::IXMLDOMNodeListPtr, IXMLDOMNodePtr::SelectNodes(), 0, XML .

.

+3
2

.NET XmlDocument, , :

XML- - , Xpath . , XMLDoument, , XPATH ( , XML- xpath, )

SO, XPath, /report/subreport/record/field/value, :

  pXMLDoc->setProperty(_bstr_t("SelectionNamespaces"),
                       _bstr_t("xmlns:r="http://www.**.com/**"));

selectNodes() /r:report/r:subreport/r:record/r:field/r:value

+6

. , .

0

Source: https://habr.com/ru/post/1699471/


All Articles