I am pretty new to xml, I am using testcomplete with Javascript. I have nested xml i am pasting a small part below.
I would like to extract rownumber and column code when rowtype category = "ExitRow" occupation is free Marketing seat type is E .
<Row rowNumber="011">
<RowCharacteristics>
<RowType category="ExitRow"/>
</RowCharacteristics>
<Seats>
<Seat occupation="Free" columnCode="A">
<MarketingSeatType category="E"/>
<PhysicalSeatTypes>
<PhysicalSeatType category="E"/>
</PhysicalSeatTypes>
</Seat>
<Seat occupation="Free" columnCode="B">
<MarketingSeatType category="E"/>
<PhysicalSeatTypes>
<PhysicalSeatType category="1A"/>
<PhysicalSeatType category="1B"/>
<PhysicalSeatType category="E"/>
</PhysicalSeatTypes>
</Seat>
<Seat occupation="Free" columnCode="C">
<MarketingSeatType category="E"/>
<PhysicalSeatTypes>
<PhysicalSeatType category="1A"/>
<PhysicalSeatType category="1B"/>
<PhysicalSeatType category="E"/>
</PhysicalSeatTypes>
</Seat>
<Seat occupation="Free" columnCode="D">
<MarketingSeatType category="E"/>
<PhysicalSeatTypes>
<PhysicalSeatType category="1A"/>
<PhysicalSeatType category="1B"/>
<PhysicalSeatType category="E"/>
</PhysicalSeatTypes>
</Seat>
<Seat occupation="Free" columnCode="E">
<MarketingSeatType category="E"/>
<PhysicalSeatTypes>
<PhysicalSeatType category="1A"/>
<PhysicalSeatType category="1B"/>
<PhysicalSeatType category="E"/>
</PhysicalSeatTypes>
</Seat>
<Seat occupation="Free" columnCode="F">
<MarketingSeatType category="E"/>
<PhysicalSeatTypes>
<PhysicalSeatType category="1A"/>
<PhysicalSeatType category="1B"/>
<PhysicalSeatType category="E"/>
</PhysicalSeatTypes>
</Seat>
</Seats>
</Row>
I have wrote some code to open xml in test complete but not sure is this correct.
Doc = Sys.OleObject("Msxml2.DOMDocument.4.0");
Doc.async = false;
Doc.load("d:\\MyFile.xml");
Node = Doc.documentElement;
The best way is to use XPath. You can find a lot of examples in this MSDN article .
Here is the code that should work for you:
function test()
{
var Doc = Sys.OleObject("Msxml2.DOMDocument.4.0");
Doc.async = false;
Doc.load("d:\\MyFile.xml");
var row = Doc.selectSingleNode('//Row[RowCharacteristics/RowType/@category="ExitRow"]');
var rowNumber = row.getAttribute("rowNumber");
Log.Message("Row number is " + rowNumber);
var cCodes = row.selectNodes('Seats/Seat[@occupation="Free" and MarketingSeatType/@category="E"]/@columnCode');
for (var i = 0; i < cCodes.length; i++)
Log.Message("Column code is " + cCodes.item(i).value);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.