
July 31st, 2012, 09:00 AM
|
|
Contributing User
|
|
Join Date: Oct 2004
Posts: 127

Time spent in forums: 3 Days 10 h 40 m 4 sec
Reputation Power: 9
|
|
|
Querying xml that has a xmlns namespace (beginner)
Hello,
I'm trying to figure out how to access XML using sql queries.
I have 2 pieces of code which is identical, however 1 is using a xmlns namespace, the other one is not.
How would I change the select query in the first example to make it work(Given that there is such an XMLSchema)?
Thanks
Example 1 - this one does not work:
Code:
declare @myDoc xml
set @myDoc = '<Root xmlns="http://www.somewebsite.com/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.somewebsite.com/XMLSchema/someXmlSchema.xsd">>
<ProductDescription ProductID="1" ProductName="Road Bike">
<Features>
<Warranty>1 year parts and labor</Warranty>
<Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>
</Root>'
SELECT @myDoc.query('/Root/ProductDescription/Features')
example 2 - this one works as expected:
Code:
declare @myDoc xml
set @myDoc = '<Root>
<ProductDescription ProductID="1" ProductName="Road Bike">
<Features>
<Warranty>1 year parts and labor</Warranty>
<Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>
</Root>'
SELECT @myDoc.query('/Root/ProductDescription/Features')
|