具有命名空间的文档的路径表达式
Path expressions on documents with namespaces
我需要查询 return 属性 EventType 的值。这是我的 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
-<Report xmlns="VehicleExcelActivityReport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="VehicleExcelActivityReport" xsi:schemaLocation="VehicleExcelActivityReport https://onlineavl2rpt-cl.navmanwireless.com/ReportServer?%2FFLD_99b60f01-620d-4651-a2c4-31d773d80fca%2FVehicleExcelActivityReport&rs%3ACommand=Render&rs%3AFormat=XML&rs%3ASessionID=sklpjpaslys3ujybhjorfabz&rs%3ASnapshot=2020-01-16T01%3A27%3A35&rc%3ASchema=True">
-<OwnerList>
-<Owner_Collection>
-<Owner>
-<Activities>
-<Detail_Collection>
<Detail Longitude="-71,45113" Latitude="-30,42046" Location="Ruta 5 Norte Km (400 - 410), Iv Region, Chile" Channel="" Driver="LUIS LILLO" NumSatellites="11" HDOP="0,8" OnSiteTimeUnits="min" OnSiteTime="0" TripUnit="km" TripDistance="0" SpeedUnit="km/h" Speed="0" EventTime="07:51 a.m." EventDate="14/01/2020" EventType="Ignition On" Registration="GKZJ-97" Vehicle="GKZJ-97"/>
<Detail Longitude="-71,58305" Latitude="-31,23375" Location="Ruta 5 Norte Km (300 - 310), Iv Region, Chile" Channel="" Driver="LUIS LILLO" NumSatellites="7" HDOP="1,2" OnSiteTimeUnits="min" OnSiteTime="0" TripUnit="km" TripDistance="103.300003051758" SpeedUnit="km/h" Speed="0" EventTime="09:19 a.m." EventDate="14/01/2020" EventType="Ignition Off" Registration="GKZJ-97" Vehicle="GKZJ-97"/>
</Detail_Collection>
</Activities>
</Owner>
</Owner_Collection>
</OwnerList>
</Report>
这是我的代码:
for $x in /Report/OwnerList/Owner_Collection/Owner/Activities/Detail_Collection/Detail
return string($x/@EventType)
但我没有点击。我也试过 return data($x/@EventType)
return ($x/@EventType/string())
和 return ($x/@EventType/data())
但没有成功。
非常感谢你的帮助。
问候
您文档的所有节点都在 VehicleExcelActivityReport
命名空间中。如果您使用默认元素命名空间声明引入查询,则可以解析您的路径:
declare default element namespace 'VehicleExcelActivityReport';
..
我需要查询 return 属性 EventType 的值。这是我的 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
-<Report xmlns="VehicleExcelActivityReport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="VehicleExcelActivityReport" xsi:schemaLocation="VehicleExcelActivityReport https://onlineavl2rpt-cl.navmanwireless.com/ReportServer?%2FFLD_99b60f01-620d-4651-a2c4-31d773d80fca%2FVehicleExcelActivityReport&rs%3ACommand=Render&rs%3AFormat=XML&rs%3ASessionID=sklpjpaslys3ujybhjorfabz&rs%3ASnapshot=2020-01-16T01%3A27%3A35&rc%3ASchema=True">
-<OwnerList>
-<Owner_Collection>
-<Owner>
-<Activities>
-<Detail_Collection>
<Detail Longitude="-71,45113" Latitude="-30,42046" Location="Ruta 5 Norte Km (400 - 410), Iv Region, Chile" Channel="" Driver="LUIS LILLO" NumSatellites="11" HDOP="0,8" OnSiteTimeUnits="min" OnSiteTime="0" TripUnit="km" TripDistance="0" SpeedUnit="km/h" Speed="0" EventTime="07:51 a.m." EventDate="14/01/2020" EventType="Ignition On" Registration="GKZJ-97" Vehicle="GKZJ-97"/>
<Detail Longitude="-71,58305" Latitude="-31,23375" Location="Ruta 5 Norte Km (300 - 310), Iv Region, Chile" Channel="" Driver="LUIS LILLO" NumSatellites="7" HDOP="1,2" OnSiteTimeUnits="min" OnSiteTime="0" TripUnit="km" TripDistance="103.300003051758" SpeedUnit="km/h" Speed="0" EventTime="09:19 a.m." EventDate="14/01/2020" EventType="Ignition Off" Registration="GKZJ-97" Vehicle="GKZJ-97"/>
</Detail_Collection>
</Activities>
</Owner>
</Owner_Collection>
</OwnerList>
</Report>
这是我的代码:
for $x in /Report/OwnerList/Owner_Collection/Owner/Activities/Detail_Collection/Detail
return string($x/@EventType)
但我没有点击。我也试过 return data($x/@EventType)
return ($x/@EventType/string())
和 return ($x/@EventType/data())
但没有成功。
非常感谢你的帮助。
问候
您文档的所有节点都在 VehicleExcelActivityReport
命名空间中。如果您使用默认元素命名空间声明引入查询,则可以解析您的路径:
declare default element namespace 'VehicleExcelActivityReport';
..