This is my column value in sql:
<ProductId>101</ProductId>
<ProductName>TShirt</ProductName>
<Description>UCB</Description>
<Category>199</Category>
<Weight>150</Weight>
<Price>2500</Price>
<images></images>
Sometimes it looks like this also:
<ProductId xsi:nil="true" ></ProductId>
<ProductName>Toys</ProductName>
<Description xsi:nil="true" ></Description>
<Category xsi:nil="true" ></Category>
<Weight xsi:nil="true" ></Weight>
<Price xsi:nil="true" ></Price>
<images></images>
I want to extract 'ProductName' value i.e. TShirt from this column. It could be any node, How do I do this?
This is my c# code
var xml = XElement.Parse(xmlString);
string fieldValue = xml.Element(fieldToSearch).ToString();
But since it is not proper xml string it gives error so I wrote explicitly
string xmlString = "<root>" + columnValue + "</root>";
What is the correct way to find the node value?
Edit: The value can be extrtacted for Weight/Description/Price, any node. The error comes when xsi:nil is found.
It could be any nodethat means yourTShirtvalue present on any column? or in<ProductName>ToString()will fail if the element is null, which will only happen if it's missing. If the value is null or empty, there's no problem.