I have the following XML column in a table. My hope is to parse LocationResponseBodyType into its individual elements.
<LocationResponseBodyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <LocationResponseText xmlns="urn:nena:xml:ns:LoggingDataTypes:2.0"><locationResponse xmlns="urn:ietf:params:xml:ns:geopriv:held"> <locationUriSet expires="2018-04-28T17:28:38Z"> <locationURI>https://svr-adv.xx.svcTEL.us:2001/?LbyR=fc43a892-b70f-4495-8281-a4219cc369a3</locationURI> </locationUriSet> <presence entity="pres:temp@svr.xx.svcTEL.us" xmlns="urn:ietf:params:xml:ns:pidf"> <tuple id="lds-995f"> <contact>tel:+18575551212</contact> <timestamp>2018-04-28T10:22:45Z</timestamp> </tuple> </presence> </locationResponse></LocationResponseText> <DirectionValuesCode xmlns="urn:nena:xml:ns:CodeList:2.0">incoming</DirectionValuesCode> <LocationQueryId xmlns="urn:nena:xml:ns:LoggingDataTypes:2.0">https://svr-adv.xx.svcTEL.us:2001</LocationQueryId> </LocationResponseBodyType>
In the attached code, you can see that I am able to parse the "normal" XML items. I cannot figure out how to also parse the elements that are included between the < and > escape characters.
with xmlnamespaces ('urn:nena:xml:ns:LoggingDataTypes:2.0' AS ns1 ,'urn:ietf:params:xml:ns:geopriv:held' AS ns2 ,'urn:nena:xml:ns:CodeList:2.0' AS ns3 ) select top 10 logID --LocationResponseBodyType ,eventBody.value('(/LocationResponseBodyType//ns1:LocationResponseText)[1]','nvarchar(max)') AS 'LoSTResponseBodyType' ,eventBody.value('(/LocationResponseBodyType//ns3:DirectionValuesCode)[1]','nvarchar(max)') AS 'DirectionValuesCode' ,eventBody.value('(/LocationResponseBodyType//ns1:LocationQueryId)[1]','nvarchar(max)') AS 'LocationQueryId' from dbo.LogEvent
Thank you for taking the time to read this. -John