本文介绍了用XDocument读取CDATA吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要读取此代码段中的CDATA文本需要进行哪些更改

XDocument connectedPCsXML = XDocument.Load(new StreamReader(Registry.GetValue(@``HKEY_LOCAL_MACHINE \ software \ myCompany \ xml'',"path" ;,@"C:\ xml \")+"ConnectedPCs.xml"));;
名称= PC.Element(名称").Value,
IP = PC.Element("IP")"值",
,DnsName = PC.Element("DnsName").Value
};

< xml版本="1.0" encoding ="utf-8''?
< ConnectedPCs>
< ConnectedPC>
<名称> PC 1</Name>< DnsName> Pc1DnsName</DnsName>
< IP> 127.1.0.1</IP>
< Description 5100#1</Description>
<![CDATA [
Multi line
text 1
]]>
</ConnectedPC>
< ConnectedPC>
名称> PC 2</Name>
< DnsName> Pc2DnsName</DnsName<>
; IP> 127.1.0.2</IP>
< Description> Dell 5100#2</Description>
<![CDATA [多行
文本2
]] >
</ConnectedPC>
</ConnectedPCs>

Hi, what changes are needed to read the CDATA text in this code fragment
           XDocument connectedPCsXML = XDocument.Load(new StreamReader(Registry.GetValue(@"HKEY_LOCAL_MACHINE\software\myCompany\xml", "path",@"C:\xml\") + "ConnectedPCs.xml"));
            var PCs = from PC in connectedPCsXML.Descendants("ConnectedPC")
                      select new
                      {
                          Name = PC.Element("Name").Value,
                          IP = PC.Element("IP").Value,
                          Description = PC.Element("Description").Value,
                          DnsName = PC.Element("DnsName").Value
                      };

<?xml version="1.0" encoding="utf-8"?>
<ConnectedPCs>
  <ConnectedPC>
    <Name>PC 1</Name>
    <DnsName>Pc1DnsName</DnsName>
    <IP>127.1.0.1</IP>
    <Description>Dell 5100 #1</Description>
    <![CDATA[
 Multi line
 text 1
    ]]>
  </ConnectedPC>
  <ConnectedPC>
    <Name>PC 2</Name>
    <DnsName>Pc2DnsName</DnsName>
    <IP>127.1.0.2</IP>
    <Description>Dell 5100 #2</Description>
    <![CDATA[
 Multi line
 text 2
    ]]>
  </ConnectedPC>
</ConnectedPCs>

推荐答案


这篇关于用XDocument读取CDATA吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 00:17