read CDATA section in XML with XDocument?

  • Thread starter Thread starter viepia
  • Start date Start date
V

viepia

Hi,

How would I edit the code below to read XML CData text?

Thanks,
Viepia

XDocument connectedPCsXML = XDocument.Load(new
StreamReader(Registry.GetValue(@"HKEY_LOCAL_MACHINE\software\myCompany\configDir",
"path",@"C:\ConfigDir\") + "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
};
 
Hi,

   How would I edit the code below to read  XML CData text?

Thanks,
Viepia

            XDocument connectedPCsXML = XDocument.Load(new
StreamReader(Registry.GetValue(@"HKEY_LOCAL_MACHINE\software\myCompany\conf­igDir",
"path",@"C:\ConfigDir\") + "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
                      };

Where is CData section?? Please post the query little clearly

-Cnu
 
viepia said:
How would I edit the code below to read XML CData text?
XDocument connectedPCsXML = XDocument.Load(new
StreamReader(Registry.GetValue(@"HKEY_LOCAL_MACHINE\software\myCompany\configDir",
"path",@"C:\ConfigDir\") + "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
};

For your query with e.g. PC.Element("Description").Value it should not
make a difference whether the XML looks like e.g.
<Description>foo &amp; bar</Description>
or
<Description><![CDATA[foo & bar]]></Description>
the Value of the 'Description' remains the same.

If that does not help then show us the relevant XML.
 
Back
Top