Pulpo Gris
Pulpo Gris

Reputation: 3

Path expressions on documents with namespaces

I need my query to return the values of the attribute EventType. This is my xml file:

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

This is my code:

for $x in /Report/OwnerList/Owner_Collection/Owner/Activities/Detail_Collection/Detail
  return string($x/@EventType)

but I get no hits. I have also tried return data($x/@EventType) return ($x/@EventType/string()) and return ($x/@EventType/data()) but no hits.

I would appreciate so much your help.

Greetings

Upvotes: 0

Views: 53

Answers (1)

Christian Gr&#252;n
Christian Gr&#252;n

Reputation: 6229

All nodes of your document are in the VehicleExcelActivityReport namespace. Your path can be resolved if you introduce your query with a default element namespace declaration:

declare default element namespace 'VehicleExcelActivityReport';
.. 

Upvotes: 0

Related Questions