开发者

How can we query XCData under a particular XElment Node?

开发者 https://www.devze.com 2022-12-11 10:11 出处:网络
<XMLDOC> <OPTIONA> <![CDATA[ aaaaaaaaaaaaa开发者_运维百科 ]]> <![CDATA[ bbbbbbbb]]>
<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
0

精彩评论

暂无评论...
验证码 换一张
取 消