Monthly Archives: July 2016

Select all elements regardless of level in XML

We have already published a post on “Read XML Data as a table in SQL Server” and “Read and compare XML nodes dynamically with unknown elements“. In this post, we will see that how we can skip levels in XML string to read all the elements at a given level regardless of the level name. A wildcard character * (asterisk) can be used to extract all the elements of a XML string regardless of the level name. Lets have a demo to understand this.

Suppose, we have below XML data:

<EmpName>Employee 1</EmpName>
<EmpName>Employee 2</EmpName>
<EmpName>Employee 3</EmpName>
<EmpName>Employee 4</EmpName>
<EmpName>Employee 5</EmpName>

In this data, the root level node is <Department> which has <HR>, <Admin>, and <Engineering> as their children … More