Hi all,I want to import a XML file like:<node> <code>555555</code> <definition>Definition</definition> <name>Name</name> <attribute> <code>6666</code> <name>Brown</name> <definition>Brown 6666</definition> <attributeValue> <code>1111111</code> <name>yyyyyyyy</name> </attributeValue> </attribute> <attribute> <code>7777</code> <name>Black</name> <definition>Black 7777</definition> <attributeValue> <code>2222222</code> <name>xxxxxxxx</name> </attributeValue> </attribute></node>
I'm using the following code:declare @XMLDocument xmlselect @XMLDocument = CONVERT(XML, replace(Bulkcolumn, '%', ''), 2) FROM OPENROWSET(BULK 'D:\xmlfile.xml', SINGLE_BLOB) AS ResultSELECT X.a.query('code').value('.', 'varchar(1000)') as code,X.a.query('definition').value('.', 'varchar(1000)') as definition,X.a.query('name').value('.', 'varchar(1000)') as name,X.a.query('attribute/code').value('.', 'varchar(1000)') as code,X.a.query('attribute/name').value('.', 'varchar(1000)') as name,X.a.query('attribute/definition').value('.', 'varchar(1000)') as definition,X.a.query('attribute/attributeValue/code').value('.', 'varchar(1000)') as code,X.a.query('attribute/attributeValue/name').value('.', 'varchar(1000)') as nameFROM @XMLDocument.nodes('node') AS x(a)
The problem is the result, see:code definition name code name definition code name555555 Definition Name 66667777 BrownBlack Brown 6666Black 7777 11111112222222 yyyyyyyyxxxxxxxxIt concats values like the code-column (4th column). I expect two result records, I get one result. What can I do?Thank you