read CDATA section in XML with XDocument?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • viepia

    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(Re gistry.GetValue (@"HKEY_LOCAL_M ACHINE\software \myCompany\conf igDir",
    "path",@"C:\Con figDir\") + "ConnectedPCs.x ml"));
    var PCs = from PC in connectedPCsXML .Descendants("C onnectedPC")
    select new
    {
    Name = PC.Element("Nam e").Value,
    IP = PC.Element("IP" ).Value,
    Description = PC.Element("Des cription").Valu e,
    DnsName = PC.Element("Dns Name").Value
    };
  • Duggi

    #2
    Re: read CDATA section in XML with XDocument?

    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(Re gistry.GetValue (@"HKEY_LOCAL_M ACHINE\software \myCompany\conf ­igDir",
    "path",@"C:\Con figDir\") + "ConnectedPCs.x ml"));
                var PCs = from PC in connectedPCsXML .Descendants("C onnectedPC")
                          select new
                          {
                              Name = PC.Element("Nam e").Value,
                              IP = PC.Element("IP" ).Value,
                              Description = PC.Element("Des cription").Valu e,
                              DnsName = PC.Element("Dns Name").Value
                          };
    Where is CData section?? Please post the query little clearly

    -Cnu

    Comment

    • Martin Honnen

      #3
      Re: read CDATA section in XML with XDocument?

      viepia wrote:
      How would I edit the code below to read XML CData text?
      XDocument connectedPCsXML = XDocument.Load( new
      StreamReader(Re gistry.GetValue (@"HKEY_LOCAL_M ACHINE\software \myCompany\conf igDir",
      "path",@"C:\Con figDir\") + "ConnectedPCs.x ml"));
      var PCs = from PC in connectedPCsXML .Descendants("C onnectedPC")
      select new
      {
      Name = PC.Element("Nam e").Value,
      IP = PC.Element("IP" ).Value,
      Description = PC.Element("Des cription").Valu e,
      DnsName = PC.Element("Dns Name").Value
      };
      For your query with e.g. PC.Element("Des cription").Valu e it should not
      make a difference whether the XML looks like e.g.
      <Description>fo o &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

      Comment

      Working...