Hi Lesek,
Below is some sample code to acess a CDATA section:
string fileName = "test.xml";
XmlDocument doc = new XmlDocument();
doc.Load(fileNa me);
XmlElement root = doc.DocumentEle ment;
XmlNode node = doc.DocumentEle ment.SelectSing leNode(
@"/Computers/Computer[@Manufacturer=' Gateway']/CPU");
XmlNode childNode = node.ChildNodes[0];
if (childNode is XmlCDataSection )
{
XmlCDataSection cdataSection = childNode as XmlCDataSection ;
Console.WriteLi ne(cdataSection .Value);
}
The XML File is shown below:
<Computers>
<Computer Manufacturer="D ell">
<CPU>
Intel Pentium 4
</CPU>
</Computer>
<Computer Manufacturer="G ateway">
<CPU>
<![CDATA[
this is the <CData Text>
]]>
</CPU>
</Computer>
</Computers>
I hope this helps,
Bennie Haelen
"Leszek" <ta******@5thbu siness.com> wrote in message
news:OK******** ******@TK2MSFTN GP09.phx.gbl...
Hello,
I have the following code:
// Read the XML document from the hard-drive.
XmlDocument doc = new XmlDocument();
doc.Load("doc.x ml");
// Create the document's root.
XmlElement root = doc.DocumentEle ment;
// Filter the node we want.
XmlNodeList nodes;
nodes = root.SelectNode s("/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