How to remove a child node from an XML file in C++ using Xerces-C?
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.
精彩评论