Ask a Question

Parse XML - parse Error

Frequent Contributor

Parse XML - parse Error

Hi, i have problem with parsing XML file.


<?xml version="1.0"?>
    <control id="1">
        <value>My string</value>
    <control id="2">
    <control id="3">
        <value>My string</value>
    <control xmlns="CheckBoxes">
    <control xmlns="Button2">

my code in JavaScript&colon;


function TestWithXPath()
  var Doc, s, Nodes, ChildNodes, i, Node;
  // If you have MSXML 6:
  Doc = new ActiveXObject("Msxml2.DOMDocument.6.0");

  // Load data from a file
  // We use the file created earlier
  // Report an error, if, for instance, the markup or file structure is invalid
  if(Doc.parseError.errorCode != 0)
    s = "Reason:\t" + Doc.parseError.reason + "\n" +
        "Line:\t" + aqConvert.VarToStr(Doc.parseError.line) + "\n" +
        "Pos:\t" + aqConvert.VarToStr(Doc.parseError.linePos) + "\n" +
        "Source:\t" + Doc.parseError.srcText;
    // Post an error to the log and exit
    Log.Error("Cannot parse the document.", s);
  // Use an XPath expression to obtain a list of "control" nodes
  Nodes = Doc.selectNodes("/control");
  // Process the node
  for(i = 0; i < Nodes.length; i++)
    // Get the node from the collection of the found nodes
    Node = Nodes.item(i);
    // Get child nodes
    ChildNodes = Node.childNodes;
    // Output two child nodes to the log
    Log.Message(ChildNodes.item(1).text + ": " + ChildNodes.item(2).text);

Test script report parseError. Please help me, how can i parse XML file?

Cannot parse the document.


Esteemed Contributor

Your code posts reasons, line, etc, in the Additional Info of the test log.  What's in there?


I can't see anything obvious in your test code.  I would suggest instead of new ActiveXObject that you do Sys.OleObject as that's a more direct support in TestComplete.  But if you can get us the Additional Info, that would help.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Showing results for 
Search instead for 
Did you mean: