Cannot read contents when XML has 2 wrappers

Helicopter Farm

New Member
This code works fine when you remove the \[code\]<data>\[/code\] wrapper, from the XML and the nodes, but when you add it, like below, i get 0 results.\[code\] -- Declare XML variable DECLARE @data XML; -- Element-centered XML SET @data = http://stackoverflow.com/questions/10375609/N' <data xmlns="test.xsd"> <subdata> <customer> <id>1</id> <name>Allied Industries</name> </customer> <customer> <id>2</id> <name>Trades International</name> </customer> </subdata> </data>'; -- Using the query() method SELECT T.customer.query('id').value('.', 'INT') AS customer_id, T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name FROM @data.nodes('data/subdata/customer') AS T(customer);\[/code\]But works fine when i do it like this:\[code\] -- Element-centered XML SET @data = http://stackoverflow.com/questions/10375609/N' <subdata> <customer> <id>1</id> <name>Allied Industries</name> </customer> <customer> <id>2</id> <name>Trades International</name> </customer> </subdata> '; -- Using the query() method SELECT T.customer.query('id').value('.', 'INT') AS customer_id, T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name FROM @data.nodes('subdata/customer') AS T(customer);\[/code\]Does anyone know how or why I'm not getting results in the first example, when the \[code\]<data>\[/code\] parent wrapper is there?
 
Back
Top