Recently, my team assigned one requirement to import XML file. To read an XML file is achieved by following this POST but here, we have a requirement to read each Attribute name and Attribute Value to store that info in normalized table by comparing Attribute Name. Let me explain with example.
DECLARE @XML AS XML SELECT @XML = '' SELECT CAST(x.v.query('local-name(.)') AS VARCHAR(100)) AS AttributeName ,x.v.value('.', 'VARCHAR(100)') AttributeValue FROM @XML.nodes('//@*') x(v) ORDER BY AttributeName
Here, We have used “@*”, which gives us way to read the attributes for the ROOT tag and “local-name” gives is the Attribute name. That’s it.
Posted by Tejas Shah on November 22, 2017
Posted by Tejas Shah on November 11, 2017
Posted by Tejas Shah on August 12, 2015
Posted by Tejas Shah on June 26, 2015
Posted by Tejas Shah on April 20, 2015