0

我有这个 XML

<?xml version="1.0" encoding="utf-8"?>
    <DataSet xmlns="http://www.dotnous.co.nz/ws">
      <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
          <xs:complexType>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:element name="FuelLabelData">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="ErrorCode" type="xs:int" minOccurs="0" />
                    <xs:element name="Explanation" type="xs:string" minOccurs="0" />
                    <xs:element name="LabelVersion" type="xs:string" minOccurs="0" />
                    <xs:element name="LabelID" type="xs:string" minOccurs="0" />
                    <xs:element name="ModelCode" type="xs:string" minOccurs="0" />
                    <xs:element name="Variant" type="xs:int" minOccurs="0" />
                    <xs:element name="Make" type="xs:string" minOccurs="0" />
                    <xs:element name="Model" type="xs:string" minOccurs="0" />
                    <xs:element name="SubModel" type="xs:string" minOccurs="0" />
                    <xs:element name="VehicleType" type="xs:string" minOccurs="0" />
                    <xs:element name="Seats" type="xs:short" minOccurs="0" />
                    <xs:element name="FuelType" type="xs:string" minOccurs="0" />
                    <xs:element name="EngineSize" type="xs:int" minOccurs="0" />
                    <xs:element name="EnginePower" type="xs:int" minOccurs="0" />
                    <xs:element name="Transmission" type="xs:string" minOccurs="0" />
                    <xs:element name="Weight" type="xs:int" minOccurs="0" />
                    <xs:element name="FuelStars" type="xs:int" minOccurs="0" />
                    <xs:element name="FuelConsumption" type="xs:double" minOccurs="0" />
                    <xs:element name="YearlyCost" type="xs:double" minOccurs="0" />
                    <xs:element name="RUCrate" type="xs:double" minOccurs="0" />
                    <xs:element name="RUC" type="xs:double" minOccurs="0" />
                    <xs:element name="CO2Stars" type="xs:unsignedByte" minOccurs="0" />
                    <xs:element name="CO2" type="xs:double" minOccurs="0" />
                    <xs:element name="YearlyCO2" type="xs:double" minOccurs="0" />
                    <xs:element name="PollutantsStars" type="xs:unsignedByte" minOccurs="0" />
                    <xs:element name="TestRegime" type="xs:string" minOccurs="0" />
                    <xs:element name="DriverSafetyStars" type="xs:unsignedByte" minOccurs="0" />
                    <xs:element name="DriverSafetyTest" type="xs:string" minOccurs="0" />
                    <xs:element name="OthersSafetyStars" type="xs:unsignedByte" minOccurs="0" />
                    <xs:element name="OthersSafetyTest" type="xs:string" minOccurs="0" />
                    <xs:element name="LikeVehicle" type="xs:string" minOccurs="0" />
                    <xs:element name="Item" type="xs:long" minOccurs="0" />
                    <xs:element name="LastRegUpdate" type="xs:dateTime" minOccurs="0" />
                    <xs:element name="VIN" type="xs:string" minOccurs="0" />
                    <xs:element name="VehicleYear" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:schema>
      <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
        <NewDataSet xmlns="">
          <FuelLabelData diffgr:id="FuelLabelData1" msdata:rowOrder="0">
            <ErrorCode>0</ErrorCode>
            <Explanation>2011(a) cost per year based on price per litre of petrol $2.00 and an average distance of 14000 km</Explanation>
            <LabelVersion>2011(a)</LabelVersion>
            <LabelID>V:W0L0AHL4855174049D:130213</LabelID>
            <ModelCode>AH8TL48254;</ModelCode>
            <Variant>0</Variant>
            <Make>HOLDEN</Make>
            <Model>ASTRA</Model>
            <SubModel>CD AUTO</SubModel>
            <VehicleType>Car(Small)</VehicleType>
            <Seats>5</Seats>
            <FuelType>petrol</FuelType>
            <EngineSize>1796</EngineSize>
            <EnginePower>90</EnginePower>
            <Transmission>4-gear automatic</Transmission>
            <Weight>1805</Weight>
            <FuelStars>8</FuelStars>
            <FuelConsumption>8.2</FuelConsumption>
            <YearlyCost>2300</YearlyCost>
            <RUCrate>0</RUCrate>
            <RUC>0</RUC>
            <CO2Stars>8</CO2Stars>
            <CO2>188</CO2>
            <YearlyCO2>2.64</YearlyCO2>
            <PollutantsStars>8</PollutantsStars>
            <TestRegime>EUR4</TestRegime>
            <DriverSafetyStars>8</DriverSafetyStars>
            <DriverSafetyTest>Based on ANCAP rating for 04-08 models with front+side airbags</DriverSafetyTest>
            <OthersSafetyStars>2</OthersSafetyStars>
            <OthersSafetyTest>Based on ANCAP rating for 04-08 models with front+side airbags</OthersSafetyTest>
            <LikeVehicle>8|84||7|83||6|1434||5|70||4|58||15|2630||13|2576||16|2638||2|1215||1|12||20|3929||</LikeVehicle>
            <Item>6413</Item>
            <LastRegUpdate>2007-10-08T00:00:00+13:00</LastRegUpdate>
          </FuelLabelData>
        </NewDataSet>
      </diffgr:diffgram>
    </DataSet>

我的问题是,如何FuelLabelData使用 xpath 获取标签内的数据(FuelStars例如获取信息)?

4

1 回答 1

0

您可以将 X 路径表达式用作 //*[local-name() = "local_name"]

例如-:/ /*[local-name() = "FuelStars"]

微笑场景之前在这里发布过,也看看他们

尽管在处理多个名称空间时这是一个非常方便的选项,但您不应该使用//除非您真的确定自己在做什么。

于 2013-02-13T09:02:20.343 回答