0
XML文書から何も得られない理由は誰でも助けてくれますか?私はこれが最初の行と関係があると思います。これを "xsi:"や "ns3:"のようなもので消去すると、期待される出力 "Biking"が得られるからです。XML to openxml
コード:
DECLARE @XmlDocumentHandle int
DECLARE @XmlDocument nvarchar(max)
SET @XmlDocument =
'<TrainingCenterDatabase xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1">
<Activities>
<Activity Sport="Biking">
<Id>2014-09-28T08:48:39.000Z</Id>
<Lap StartTime="2014-09-28T08:48:39.000Z">
<TotalTimeSeconds>17766.56</TotalTimeSeconds>
<DistanceMeters>65047.04</DistanceMeters>
<MaximumSpeed>15.639999</MaximumSpeed>
<Calories>4113</Calories>
<AverageHeartRateBpm>
<Value>142</Value>
</AverageHeartRateBpm>
<MaximumHeartRateBpm>
<Value>182</Value>
</MaximumHeartRateBpm>
<Intensity>Active</Intensity>
<TriggerMethod>Manual</TriggerMethod>
<Track>
<Trackpoint>
<Time>2014-09-28T08:48:40.000Z</Time>
<Position>
<LatitudeDegrees>48.18774196319282</LatitudeDegrees>
<LongitudeDegrees>16.302834944799542</LongitudeDegrees>
</Position>
<AltitudeMeters>83.5999984741211</AltitudeMeters>
<DistanceMeters>3.180000066757202</DistanceMeters>
<HeartRateBpm>
<Value>94</Value>
</HeartRateBpm>
<Extensions>
<ns3:TPX>
<ns3:Speed>0.0</ns3:Speed>
</ns3:TPX>
</Extensions>
</Trackpoint>
<Trackpoint>
<Time>2014-09-28T08:48:45.000Z</Time>
<Position>
<LatitudeDegrees>48.18779996596277</LatitudeDegrees>
<LongitudeDegrees>16.30263394676149</LongitudeDegrees>
</Position>
<AltitudeMeters>83.4000015258789</AltitudeMeters>
<DistanceMeters>19.360000610351562</DistanceMeters>
<HeartRateBpm>
<Value>100</Value>
</HeartRateBpm>
<Extensions>
<ns3:TPX>
<ns3:Speed>0.0</ns3:Speed>
</ns3:TPX>
</Extensions>
</Trackpoint>
</Track>
</Lap>
<Creator xsi:type="Device_t">
<Name>Garmin Edge 705</Name>
<UnitId>3417593319</UnitId>
<ProductID>625</ProductID>
<Version>
<VersionMajor>3</VersionMajor>
<VersionMinor>3</VersionMinor>
<BuildMajor>0</BuildMajor>
<BuildMinor>0</BuildMinor>
</Version>
</Creator>
</Activity>
</Activities>
<Author xsi:type="Application_t">
<Name>Garmin Connect API</Name>
<Build>
<Version>
<VersionMajor>16</VersionMajor>
<VersionMinor>15</VersionMinor>
<BuildMajor>4</BuildMajor>
<BuildMinor>4</BuildMinor>
</Version>
</Build>
<LangID>en</LangID>
<PartNumber>003-F3589-01</PartNumber>
</Author>
</TrainingCenterDatabase>'
EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @XmlDocument
SELECT *
FROM OPENXML (@XmlDocumentHandle, 'TrainingCenterDatabase/Activities/Activity')
WITH (
Sport nvarchar(max) '@Sport'
)
EXEC sp_xml_removedocument @XmlDocumentHandle