Forum Discussion

David91's avatar
David91
Frequent Contributor
7 years ago

Parse XML - parse Error

Hi, i have problem with parsing XML file.

 

<?xml version="1.0"?>
<controls>
    <control id="1">
        <type>TextEdit</type>
        <name>Text1</name>
        <value>My string</value>
    </control>
    <control id="2">
        <type>Button</type>
        <name>Btn1</name>
        <value>OK</value>
    </control>
    <control id="3">
        <type>TextEdit</type>
        <name>Text2</name>
        <value>My string</value>
    </control>
    <control xmlns="CheckBoxes">
        <type>CheckBox</type>
        <name>CheckBox1</name>
        <value>True</value>
    </control>
    <control xmlns="Button2">
        <type>Button</type>
        <name>Btn2</name>
        <value>Cancel</value>
    </control>
</controls>

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
  Doc.load("c:\\Projects\\Windows7\\DEV\\Data.xml");
 
  // 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);
    return;
  }
 
  // 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
    tristaanogre
    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.