xmlns attribute causes xpath queries to fail



When the root element has the attribute xmlns set to a (non-functioning) URI "http://ift.tt/VxNYPL", then xpath queries fail. Without that attribute, xpath queries work as expected.


The following two blocks is a minimal working example of the problem



foo <- xmlParse(file='<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase>
<Activities>
<Activity Sport="Other">
<Id>2013-08-31T09:01:43Z</Id>
<Lap StartTime="2013-08-31T09:01:43Z">
<TotalTimeSeconds>1928.82</TotalTimeSeconds>
<DistanceMeters>11250.1543</DistanceMeters>
<MaximumSpeed>15.6822205</MaximumSpeed>
<Calories>631</Calories>
<AverageHeartRateBpm><Value>126</Value></AverageHeartRateBpm>
<MaximumHeartRateBpm><Value>151</Value></MaximumHeartRateBpm>
<Intensity>Active</Intensity>
<TriggerMethod>Manual</TriggerMethod>
<Track><Trackpoint>
<Time>2013-08-31T09:01:43Z</Time>
<Position><LatitudeDegrees>57.91393099</LatitudeDegrees><LongitudeDegrees>11.77463514</LongitudeDegrees></Position>
<AltitudeMeters>55.4130859</AltitudeMeters>
<DistanceMeters>0.00000000</DistanceMeters>
<HeartRateBpm><Value>77</Value></HeartRateBpm>
</Trackpoint></Track></Lap></Activity></Activities></TrainingCenterDatabase>
')
xpathSApply(foo,'//*/Time',xmlValue)
[1] "2013-08-31T09:01:43Z"


And the non-working version



foo <- xmlParse(file='<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xmlns:xs="http://ift.tt/tphNwY" xmlns:xsi="http://ift.tt/ra1lAU" xmlns="http://ift.tt/VxNYPL">
<Activities>
<Activity Sport="Other">
<Id>2013-08-31T09:01:43Z</Id>
<Lap StartTime="2013-08-31T09:01:43Z">
<TotalTimeSeconds>1928.82</TotalTimeSeconds>
<DistanceMeters>11250.1543</DistanceMeters>
<MaximumSpeed>15.6822205</MaximumSpeed>
<Calories>631</Calories>
<AverageHeartRateBpm><Value>126</Value></AverageHeartRateBpm>
<MaximumHeartRateBpm><Value>151</Value></MaximumHeartRateBpm>
<Intensity>Active</Intensity>
<TriggerMethod>Manual</TriggerMethod>
<Track><Trackpoint>
<Time>2013-08-31T09:01:43Z</Time>
<Position><LatitudeDegrees>57.91393099</LatitudeDegrees><LongitudeDegrees>11.77463514</LongitudeDegrees></Position>
<AltitudeMeters>55.4130859</AltitudeMeters>
<DistanceMeters>0.00000000</DistanceMeters>
<HeartRateBpm><Value>77</Value></HeartRateBpm>
</Trackpoint></Track></Lap></Activity></Activities></TrainingCenterDatabase>
')
xpathSApply(foo,'//*/Time',xmlValue)
list()


My understanding is that the xml data was generated with this xslt-file, and it validates against this xsd-scheme, and that these two sources could be used instead of the non functioning link to http://ift.tt/VxNYPL . I used this-bash-script toghether with data from a garmin forerunner 305 to create the xml data.


The easy way out would be to tell xmlParse() from the R package XML to ignore xmln attribute. How do I do that?


Another route would be to change the content of the xlmns attribute to something that works What would be needed in that case, and can the xsd-scheme and or the xslt-file help here?


No comments:

Post a Comment