Reputation: 67
I have an XML as below stored in a table.
`<Customer>
<Name>
<FName>Mark</FName>
<MName>A</MName>
<LName>Antomy</LName>
</Name>
<Address>
<Street>Clare</Street>
<City>Clarkson</City>
</Address>
</Customer> `
I want to select everything except the root node.
`<Name>
<FName>Mark</FName>
<MName>A</MName>
<LName>Antomy</LName>
</Name>
<Address>
<Street>Clare</Street>
<City>Clarkson</City>
</Address>`
There are two parallel levels below root. I am unable to get them both in a single query. Can it can be achieved through XQuery. Thanks in advance.
Edit : removed an extra enter code here
lurking in the xml.
Upvotes: 0
Views: 61
Reputation: 69789
You can use .query()
with a wildcard:
DECLARE @T TABLE (X XML);
INSERT @T (X) VALUES ('<Customer>
<Name>
<FName>Mark</FName>`enter code here`
<MName>A</MName>
<LName>Antomy</LName>
</Name>
<Address>
<Street>Clare</Street>
<City>Clarkson</City>
</Address>
</Customer>');
SELECT X.query('/Customer/*')
FROM @T;
Upvotes: 1