Hi Lesek,
Below is some sample code to acess a CDATA section:
string fileName = "test.xml";
XmlDocument doc = new XmlDocument();
doc.Load(fileName);
XmlElement root = doc.DocumentElement;
XmlNode node = doc.DocumentElement.SelectSingleNode(
@"/Computers/Computer[@Manufacturer='Gateway']/CPU");
XmlNode childNode = node.ChildNodes[0];
if (childNode is XmlCDataSection)
{
XmlCDataSection cdataSection = childNode as XmlCDataSection;
Console.WriteLine(cdataSection.Value);
}
The XML File is shown below:
<Computers>
<Computer Manufacturer="Dell">
<CPU>
Intel Pentium 4
</CPU>
</Computer>
<Computer Manufacturer="Gateway">
<CPU>
<![CDATA[
this is the <CData Text>
]]>
</CPU>
</Computer>
</Computers>
I hope this helps,
Bennie Haelen
"Leszek" <ta******@5thbusiness.com> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
Hello,
I have the following code:
// Read the XML document from the hard-drive.
XmlDocument doc = new XmlDocument();
doc.Load("doc.xml");
// Create the document's root.
XmlElement root = doc.DocumentElement;
// Filter the node we want.
XmlNodeList nodes;
nodes = root.SelectNodes("/Pages/Page[@Filename='" + id + "']");
XmlNode node = nodes[0];
// Retrieve data from the node
m_Filename = id;
m_Caption = node["Caption"].InnerText;
m_Content = node["CDATA"].InnerText; // ??????????????
The problem is that m_Content needs to be populated from CDATA section of
the selected node. There is no <CDATA></CDATA> element so this code fails.
How to do this?
Thanks,
Leszek Taratuta