I want to parse XML which is stored in a column in SQL Server:
Table column with XML in this picture
and the XML is:
<?xml version="1.0" encoding="UTF-8"?>
<propertylist id="root">
<property expanded="Y" id="createsdi" selectedindex="0" type="collection">
<collection>
<propertylist id="1305619640064">
<property expanded="Y" id="columnvalues" selectedindex="0" type="collection">
<collection>
<propertylist id="1396440519721" />
</collection>
</property>
<property expanded="Y" id="tests" selectedindex="0" type="collection">
<collection>
<propertylist id="p1602059752707" sequence="1000000">
<property id="id" type="simple"><![CDATA[item1]]></property>
<property id="workitemid" type="simple"><![CDATA[SOURAVTESTER|1]]></property>
</propertylist>
</collection>
</property>
<property expanded="Y" id="specs" selectedindex="0" type="collection">
<collection>
<propertylist id="p1602059825237" sequence="1000000">
<property id="id" type="simple"><![CDATA[item1]]></property>
<property id="specid" type="simple"><![CDATA[EMSpec|1]]></property>
</propertylist>
</collection>
</property>
</propertylist>
</collection>
</property>
<property expanded="Y" id="workorder" type="propertylist">
<propertylist id="root_0">
<property expanded="Y" id="graceperiod" type="propertylist">
<propertylist id="root_0_workorder_0">
<property expanded="Y" id="graceperiod" type="propertylist">
<propertylist id="root_0_workorder_0_graceperiod_0" />
</property>
<property expanded="Y" id="deviation" type="propertylist">
<propertylist id="root_0_workorder_0_graceperiod_0" />
</property>
</propertylist>
</property>
</propertylist>
</property>
</propertylist>
How can I parse the values of workitemid, specid?
I have written the following code
SELECT
ID,
ParentPropertyId = xc.value('(../@id)[1]', 'varchar(100)'),
WorkItemId = xc.value('(.)[1]', 'varchar(100)')
FROM
scheduleplanitem
CROSS APPLY
valuetree.nodes('//propertylist/property[@id="workitemid"]') xt(xc)
but I get an error
The XMLDT method 'nodes' can only be invoked on columns of type xml
The result should be:
workitemid SOURAVTESTER
specid EMSpec