471,330 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

read CDATA section in XML with XDocument?

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_MACHIN E\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
};
Aug 17 '08 #1
2 13094
On Aug 18, 3:10*am, viepia wrote:
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_MACHIN E\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
Aug 18 '08 #2
viepia wrote:
How would I edit the code below to read XML CData text?
XDocument connectedPCsXML = XDocument.Load(new
StreamReader(Registry.GetValue(@"HKEY_LOCAL_MACHIN E\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.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 18 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Xah Lee | last post: by
6 posts views Thread by Cade Perkins | last post: by
4 posts views Thread by Rich Wallace | last post: by
10 posts views Thread by Simon Brooke | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.