私はxerces 2.8.0を使用しています。ドキュメントからコメント ノードを削除したい。
List = root->getChildNodes();
int count = List->getLength();
int i = 0;
while (i < count)
{
DOMNode* node = List->item(i);
if(node != 0 && node->getNodeType() == DOMNode::COMMENT_NODE)
{
cout<<"comment node found"<<endl;
root->removeChild(node);
}
i++;
}
入力が次の形式の場合、このコードは正常に機能します。
<?xml version="1.0"?>
<root><!-- comment --><node1>txt</node1></root>
ただし、入力ファイルが次のような「きれいな」形式の場合は機能しません。
<?xml version="1.0"?>
<root>
<!-- comment -->
<node1>txt</node1>
</root>
誰でも理由を教えてもらえますか?