how to loop through xml node in SQL server
Posted on 2011-03-22
I have a table (A), which has one field (outerxml), data type is xml. I can use SELECT * FROM A WHERE OUTERXML.EXIST('\Country')=1 to query the records, very convenience.
Now I have a XML string (like <country>USA</country><postalcode>12345</postalcode>), I don't know which tag name could appear in the XML string. what's best way to get tag name (country or postalcode, not value) in a XML string?
If I can loop through xmlNode, that's would be great. BTW, I don't want to use string function to parse it.
I need to do it inside SQL server 2005 stored procedure. thanks.