How do I ignore comments in XML Checkpoints?
I am using XML Checkpoints and would like to ignore comments when comparing files. I've removed the comments from the XML Checkpoint store item, but I dynamically load the base document and that seems to overwrite this action.
Here is my XML Checkpoint store. I have removed the comment field shown from this so that the compare would ignore it.
At runtime, I load an expected file into the Checkpoint and check a given file against it. See the code below:
XML.XMLCheckpointUsage.Document.load(expectedFilePath); var result = XML.XMLCheckpointUsage.Check(givenFilePath);
The check fails because of an "Only Expected" comment.
How do I make TestComplete ignore the comment in the dynamically-loaded document?
It's unfortunate that this scenario is not handled by TestComplete :(
I did some reasearch and ended up using the following code, which seems to be working. It returns the given XML doc with comment nodes removed.
var Node = { ELEMENT_NODE : 1, ATTRIBUTE_NODE : 2, TEXT_NODE : 3, CDATA_SECTION_NODE : 4, ENTITY_REFERENCE_NODE : 5, ENTITY_NODE : 6, PROCESSING_INSTRUCTION_NODE : 7, COMMENT_NODE : 8, DOCUMENT_NODE : 9, DOCUMENT_TYPE_NODE : 10, DOCUMENT_FRAGMENT_NODE : 11, NOTATION_NODE : 12 }; function getXMLDocWithoutComments(givenXMLFullPath) { var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); var objNodeList; xmlDoc.async = false; xmlDoc.load(givenXMLFullPath); if (xmlDoc.parseError.errorCode != 0) { var myErr = xmlDoc.parseError; } else { objNodeList = xmlDoc.childNodes; for (var i=0; i<objNodeList.length; i++) { if(objNodeList.item(i).nodeType == Node.COMMENT_NODE) { xmlDoc.removeChild( objNodeList.item(i) ); } } } return xmlDoc; }