<XMLDOC>
<OPTIONA>
<![CDATA[
aaaaaaaaaaaaa 开发者_运维百科
]]>
<![CDATA[
bbbbbbbb]]>
<OPTIONA>
<OPTIONB>
<![CDATA[
cccccccccccccccccccc
]]>
<![CDATA[
dddddddddddddd]]>
</OPTIONB>
</XMLDOC>
How do I query say all CDATA's under OPTIONB?? using Linq-to-XML???
The OPTIONB
node is equivalent to:
<OPTIONB>
<![CDATA[
cccccccccccccccccccc
dddddddddddddd]]>
</OPTIONB>
So to get the value inside the CData section you could use the following:
var cdata = XElement.Load("test.xml").Element("OPTIONB").Value;
You will not be able to get the CData values separately because they have the same semantics as if it was a single CData section for a XML parser.
XElement.Load("test.xml")
.Element("OPTIONB")
.Nodes()
.Where(x=>x is XCData).First().Cast<XCData>().Value
精彩评论