开发者

How do acquire a xml string for a child using msxml4?

开发者 https://www.devze.com 2022-12-23 00:45 出处:网络
Using MSXML4, I am creating and saving an xml file: MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc; //add some elements with data

Using MSXML4, I am creating and saving an xml file:

MSXML2::IXMLDOMDocument2Ptr m_pXmlDoc;
//add some elements with data
SaveToDisk(static_cast<std::string>(m_pXmlDoc->xml));

I now need to acquire a substring from m_pXmlDoc->xml and save it. For example, if the full开发者_运维问答 xml is:

<data>
    <child1>
        <A>data</A>
            <One>data</One>
        <B>data</B>
    </child1>
</data>

I want to store this substring instead:

<A>data</A>
    <One>data</One>
<B>data</B>

How do I get this substring using MXML4?


Use XPath queries. See the MSDN documentaion for querying nodes. Basically you need to call the selectNodes API with the appropriate XPath expression that matches the part of the DOM you are interested in.

// Query a node-set.
MSXML4::IXMLDOMNodeListPtr pnl = pXMLDom->selectNodes(L"//child/*");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号