[英]Extracting data from javascript
I am pretty new to xml, I am using testcomplete with Javascript. 我对xml很陌生,我在Java中使用testcomplete。 I have nested xml i am pasting a small part below.
我嵌套了xml,我在下面粘贴了一小部分。
I would like to extract rownumber and column code when rowtype category = "ExitRow" occupation is free Marketing seat type is E . 当rowtype category =“ ExitRow”职业是免费的时,我想提取行号和列代码市场营销席位类型为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. 我已经编写了一些代码以在测试完成时打开xml,但不确定是否正确。
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. 最好的方法是使用XPath。 You can find a lot of examples in this MSDN article .
您可以在此MSDN文章中找到很多示例。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.