开发者

How to remove a child node from an XML file in C++ using Xerces-C?

开发者 https://www.devze.com 2023-03-26 15:45 出处:网络
root = doc->getDocumentElement(); child=root->getLastChild(); DOMNode* removedElement = root->removeChild(child);
    root = doc->getDocumentElement();
    child=root->getLastChild();

    DOMNode* removedElement = root->removeChild(child);
    removedElement->release();

The child is getting newline character as a node if the XML file开发者_如何学运维 is like this:

     <root>
         <child1> </child1>
         <child2> text </child2>
      </root>

The same code is working fine and removing child if the XML file is of the format

     <root> <child1></child1><child2>text</child2> </root>

How can I get rid of it (the newline)?


Found the answer myself.

The understanding of DOM is different. The children of <root> in this case are the text nodes of root, child1, text node of child1, child2, text node of child2. So the number of children of root is 5. But generally, as per XML notations, we thought they are 2. So here when I try to remove the last child it is an error. We can remove that text node from child2.

0

精彩评论

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