Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从javascript中提取数据_Javascript_Xml_Testcomplete - Fatal编程技术网

从javascript中提取数据

从javascript中提取数据,javascript,xml,testcomplete,Javascript,Xml,Testcomplete,我对xml非常陌生,我正在使用testcomplete和Javascript。我在下面粘贴了一小部分嵌套xml 当rowtype category=“ExitRow”occupation为免费营销座位类型为E时,我想提取rownumber和列代码 <Row rowNumber="011"> <RowCharacteristics> <RowType category="ExitR

我对xml非常陌生,我正在使用testcomplete和Javascript。我在下面粘贴了一小部分嵌套xml

当rowtype category=“ExitRow”occupation为免费营销座位类型为E时,我想提取rownumber和列代码

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

最好的方法是使用XPath。你可以在中找到很多例子

以下是适用于您的代码:

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);
}
功能测试()
{
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”);
日志消息(“行号为”+行号);
var cCodes=row.selectNodes('Seats/Seat[@occulation=“Free”和MarketingSeatType/@category=“E”]/@columnCode');
对于(变量i=0;i
这真是太好了,谢谢我能够用上面的代码提取行和列。实际上,当第一个退出行被填充时,我有多个退出行。上面的程序返回了行号,没有列名称:(我可能已经检查了所有的出口行,我该怎么做,还有一件事,我将重复这个过程,为多个乘客寻找免费座位。一旦我使用了座位,有没有办法改变占用=阻塞,以便下次不再选择它。工作变量numberofExitRow=Doc.selectNodes('//Row(j=0;jfunction 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); }