使用 LINQ to XML 从 CDATA 提取数据
我有以下 xml 文件,我尝试使用 linq to xml 来获取驻留在 CDATA 部分内的元素。有什么建议请。
<?xml version = "1.0" encoding = "UTF-8"?>
<result final = "true" transaction-id="84WO" xmlns="http://cp.com/rules/client">
<client id = "CustName'>
<quoteback>
</client>
<report format = "CP XML">
<![CDATA[<?xml version="1.0" encoding = "UTF-8" standalone = "yes"?>
<personal_auto xmlns = "http://cp.com/rules/client">
<admin>
</admin>
<report>
</report>
</personal_auto>
]]>
</report> </result>
I have the following xml file and I am trying to use linq to xml to get the Elements which are residing inside the CDATA section. Any suggestions please.
<?xml version = "1.0" encoding = "UTF-8"?>
<result final = "true" transaction-id="84WO" xmlns="http://cp.com/rules/client">
<client id = "CustName'>
<quoteback>
</client>
<report format = "CP XML">
<![CDATA[<?xml version="1.0" encoding = "UTF-8" standalone = "yes"?>
<personal_auto xmlns = "http://cp.com/rules/client">
<admin>
</admin>
<report>
</report>
</personal_auto>
]]>
</report> </result>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是标准 LINQ 功能 - 请参阅 http://msdn .microsoft.com/en-us/library/system.xml.linq.xcdata.aspx
如果这不能解决问题,您能否更详细地解释一下问题?
This is standard LINQ functionality - see http://msdn.microsoft.com/en-us/library/system.xml.linq.xcdata.aspx
Could you please explain the problem in more detail if this doesn't solve it?
我想做一些稍微不同的事情 - 我使用 cdata 在其自己的名为“sql”的专用元素中将 sql 嵌入到 xml 中,
只是为了澄清 cdata 内容将被透明地读取。
如果这样做,
您将获得标记中的任何字符串,
而无需在其之上实例化不同的节点类型或执行任何奇特的操作,
因此在上述情况下,cdataContent 将只是“..”。
Linq to sql 确实不错!我总是希望有更多的混乱参与其中。向开发该 API 的人们致敬。
I was looking to do something slightly different - I'm embedding sql in xml using cdata in its own dedicated element named 'sql'
Just to clarify cdata content will be read transparently.
if you do
you get whatever string is in the
tag without having to instantiate a different node type on top of it or do anything fancy
so in the above case cdataContent would just be "..".
Linq to sql really is nice! I always expect there to be more messing about involved. Hats off to the guys who made that API.