在XML中使用序数和条件获取元素值

时间:2019-06-26 13:19:45

标签: javascript xml xpath

我正在尝试使用JavaScript测试XML中的2个条件来遍历XML。由于XML是在JavaScript的原始版本和自定义版本中遍历的,因此我需要使用序数引用XML。这是我的XML示例。我想从XML中获取当前ID号,其中IsSelected = false。

    for(var x = 0; x < nCount; x++){
     if( SCRIPT_REFERENCE_TO_XML("/OptionalEquipment/EquipmentOption" + " 
       [" + x + "]/[IsSelected = 'false']")){
        removeRecs[x] = 
          SCRIPT_REFERENCE_TO_XML.getValue("/OptionalEquipment/EquipmentOption" + "[" + x + "]/@vehicleOptionId");
     }


            <OptionalEquipment>
            <EquipmentOption vehicleOptionId="7093735">
              <DisplayName>4-Cyl, GDI, 2.4 Liter</DisplayName>
              <VehicleOptionId>7093735</VehicleOptionId>
              <IsSelected>false</IsSelected>
              <OptionTypeDisplayName>Engine</OptionTypeDisplayName>
            </EquipmentOption>
            <EquipmentOption vehicleOptionId="7093790">
              <DisplayName>Auto, 6-Spd Shiftronic</DisplayName>
              <VehicleOptionId>7093790</VehicleOptionId>
              <IsSelected>true</IsSelected>
              <OptionTypeDisplayName>Transmission</OptionTypeDisplayName>
             </EquipmentOption>
            <EquipmentOption vehicleOptionId="7093801">
              <DisplayName>FWD</DisplayName>
              <VehicleOptionId>7093801</VehicleOptionId>
              <IsSelected>true</IsSelected>
              <OptionTypeDisplayName>Drivetrain</OptionTypeDisplayName>
             </EquipmentOption>
            <EquipmentOption vehicleOptionId="7093804">
              <DisplayName>AWD</DisplayName>
              <VehicleOptionId>7093804</VehicleOptionId>
              <IsSelected>false</IsSelected>
              <OptionTypeDisplayName>Drivetrain</OptionTypeDisplayName>
            </EquipmentOption>
            </OptionalEquipment>    

我不确定如何在条件中使用序数。

1 个答案:

答案 0 :(得分:0)

在现代浏览器中,它可能看起来像这样:

TextField