从javascript中提取数据
Extracting data from javascript
我对xml很陌生,我使用的是带有Javascript的testcomplete。我已经嵌套了xml,我正在粘贴下面的一小部分。
当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>
我已经写了一些代码来在测试完成时打开xml,但不确定这是否正确。
Doc = Sys.OleObject("Msxml2.DOMDocument.4.0");
Doc.async = false;
Doc.load("d:''MyFile.xml");
Node = Doc.documentElement;
最好的方法是使用XPath。您可以在MSDN的这篇文章中找到很多例子。
以下是适用于您的代码:
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);
}
相关文章:
- 在数据提取完成之前进行页面渲染
- 如何使用另一个字符串作为模板从字符串中提取数据
- 如何使用angular js从2个表(在sql server中)中提取数据
- 如何将json文件中的数据提取到对象数组中,并在两个控制器之间共享
- jQuery-数据提取问题(html遍历)
- 如何将jquery ajax数据提取为html
- AngularJS/Restangular索引JSON数据提取
- 如何在选择项目时使用 ajax 将数据提取到输入字段中
- 在表单提交时将客户端 HTML 表数据提取到服务器端 PHP 脚本
- 如何将mysql数据库中的数据提取到ckeditor中
- 如何创建一个使用ng-model的angular数据提取器指令
- Json数据提取工作不好
- React数据提取不工作
- 异步数据提取后更新jquery.sparkline
- Json数据提取
- Tablesorter→将过滤后的数据提取为csv文件
- 无法将变量数据提取为字符串格式以传递给数据库
- 将 HTML 表数据提取到 CSV 文件
- 瓦坎达报告和数据提取选项
- Web数据提取和表单填写