MSXML4 と C++ を使用して XML DOM を更新するコードを書いています。親要素に子要素を追加するメソッドが必要です。以下に記述したコードは、子のタイトルが親の下の別の子のタイトルと一致するまで機能します。子のタイトルを変更できないため、親に追加する方法を見つける必要があります。
誰でもガイダンスを提供できますか?
// this call creates '<parent><child/></parent>'
AppendChild("/root/parent", "child");
// this call attempts to create '<parent><child/><child/></parent>' but the DOM remains unchanged ('<parent><child/></parent>')
AppendChild("/root/parent", "child");
void AppendChild(const std::string kPathOfParent, const std::string kNameOfChild)
{
MSXML2::IXMLDOMNodePtr pElement = m_pXmlDoc->createNode(NODE_ELEMENT, kNameOfChild.c_str(), m_xmlns.c_str());
MSXML2::IXMLDOMNodePtr pParent = m_pXmlDoc->selectSingleNode(kPathOfParent.c_str());
MSXML2::IXMLDOMNodePtr pNewChild = pParent->appendChild(pElement);
}