Forum Discussion

David91's avatar
Frequent Contributor
7 years ago

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.


1 Reply

  • tristaanogre's avatar
    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.