Parse XML - parse Error
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018
12:02 AM
02-02-2018
12:02 AM
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:
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 1
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018
10:36 AM
02-02-2018
10:36 AM
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
