簡體   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