Forum Discussion

Nformation's avatar
Nformation
Contributor
10 years ago

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 seem...
  • Nformation's avatar
    Nformation
    10 years ago

    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;
    }