繁体   English   中英

从JavaScript提取数据

[英]Extracting data from javascript

我对xml很陌生,我在Java中使用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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM