Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following : Where the query returns 1 which is correct but if I add namespace to
<Data xmlns="urn:semi-org:xsd.E142-1.V1005.SubstrateMap"> 
the query returns 0

DECLARE @ExportData  XML

SELECT @ExportData =
'<Data >
  <BulkData>
    <EachData Parts="Test1" />
    <EachData Parts="Test2" />
    <EachData Parts="Test3" />
  </BulkData>
</Data>';

SELECT @ExportData.exist('(//BulkData)') 


What I have tried:

I have tried changing select statement
SELECT @ExportData.exist('(*/BulkData)')
Posted
Updated 30-Jan-18 20:55pm

1 solution

Hi you need to change the default namespace when you make Xquery, here here is two solutions

SQL
DECLARE @ExportData  XML

SELECT @ExportData =
'<Data xmlns="urn:semi-org:xsd.E142-1.V1005.SubstrateMap">
  <BulkData>
    <EachData Parts="Test1" />
    <EachData Parts="Test2" />
    <EachData Parts="Test3" />
  </BulkData>
</Data>';

 
SELECT @ExportData.exist('
declare namespace ns="urn:semi-org:xsd.E142-1.V1005.SubstrateMap";
 ns:*/ns:BulkData')

 ;WITH XMLNAMESPACES (DEFAULT N'urn:semi-org:xsd.E142-1.V1005.SubstrateMap')  
SELECT @ExportData.exist('*/BulkData')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900