Reputation: 148
I have a xml that I need to shred. But I am getting this error XQuery [nodes()]: The name "s" does not denote a namespace.
I have xml in following format
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">urn:somename-com:Access.2012.Services.Patient.GetCensus</a:Action>
</s:Header>
<s:Body>
<GetCensusByUnitResponse xmlns="urn:somename-com:Access.2012.Services.Patient">
<GetCensusByUnitResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<BeddedPatients>
<BeddedPatient>
...
...
...
</GetCensusByUnitResult>
</GetCensusByUnitResponse>
</s:Body>
</s:Envelope>
;with xmlnamespaces('urn:Epic-com:Access.2012.Services.Patient' as ep,
'http://www.w3.org/2003/05/soap-envelope' as s,
'http://www.w3.org/2005/08/addressing' as a,
'http://www.w3.org/2001/XMLSchema-instance' as i)
But when try to shred it using xquery it gives me the error.
To shred i have written following query:
select x.n.value('(ep:AccommodationCode)[1]', 'varchar(128)') as accomdationCode
from @xml.nodes('/s:Envelope/s:Body/ep:GetCensusByUnitReeponse/ep:GetCensusByUnitResult/ep:BeddedPatients/ep:BeddedPatient') x(n)
Can somebody suggest me what might be problem? Thanks in advance.
Upvotes: 3
Views: 5465
Reputation: 19
It seems Ankur added correct answer inside his/her question body. T-sql requires namespace declaration before select statement:
WITH XMLNAMESPACES ( <XML namespace declaration item> [ { , <XML namespace declaration item> }...] )
It is working on MS SQL 2016 still.
Upvotes: 2
Reputation: 7054
You need to declare the namespace prefixes so that they are available in the query execution context (not just in the document). I'm not familiar with SQL server's XQuery execution engine, but it must have some facility for declaring namespaces. You'll need to find that -- or -- you might consider using a native XML database so you don't need to "shred".
Upvotes: 0