I have the following xml file and cannot seem to figure out how to get the value in the elements (which are buried in a CDATA). I am trying to use linq to xml for this. If someone knows how you would convert this into a “Product” object (assume we have a product object that has properties with the same names as the elements). Thanks in advance.
bob
<CNETResponse realm="cnet" version="1.0" xmlns="http://api.cnet.com/rest/v1.0/ns" xmlns:xlink="http://www.w3.org/1999/xlink">
<TechProduct id="33517677">
<Name><![CDATA[Nikon CoolPix L20 (deep red)]]></Name>
<Topic id="1670"></Topic>
<ImageURL width="60"><![CDATA[http://i.i.com.com/cnwk.1d/sc/33517677-2-60-0.gif]]></ImageURL>
</TechProduct>
</CNETResponse>
The problem is the namespaces – for example, something like:
You might also prefer
XmlSerializer– something like:With class definitions like:
Or alternatively, just run the xml through
xsd.exeto get C# code to suit: