Displaying XML node attribute with XQuery and TSQL

MrDavidThorn used Ask the Experts™
I have an xml file that is not particularly well formed, I can bulk load the XML file into a sql server xml Field then Im using xquery to query the xml into relational data, the problem that I have is a key value is set as an attribute of a node rather than the text, with my current query I dont know how to select and display the attribute value, any help would be appricated, have an example below

I want to return the child number,

The xml structure
<Child ChildNumber =1>
<Child ChildNumber =2>

The Tsql/xQuery im using is as follows

Select T1.child.query('data(childName)') as ChildName, 
T1.child.query('data(childAge)') as ChildAge
From FamilyXML
CROSS APPLY XMLField.Nodes('(/parents/parent/child)')
as T1(Child)

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I have now taken a difference approach to the problem


becuase no one else knew the answer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial