I need to parse XML Tags which are commented out like
<DataType Name="SecureCode" Size="4" Type="NVARCHAR">
<!-- <Validation>
<Regex JavaPattern="^[0-9]*$" JSPattern="^[0-9]*$"/>
</Validation> -->
<UIType Size="4" UITableSize="4"/>
</DataType>
But all I found was setIgnoringComments(boolean)
Document doc = docBuilder.parse(new File(PathChecker.getDataTypesFile()));
docFactory.setIgnoringComments(true); // ture or false, no difference
But it doesn't seem to change anything. Is there any other way to parse this comments? I have to use DOM.
Regards
Method "setIgnoringComments" removed comments from DOM tree during parsing. With "setIgnoringComments(false)" you can get comment text like:
NodeList nl = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
if (nl.item(i).getNodeType() == Element.COMMENT_NODE) {
Comment comment=(Comment) nl.item(i);
System.out.println(comment.getData());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With