Hi
I am using xml in this way and also reading in right but when i add CDATA and reading it giving me exception but why i don't know can any one help me...?
how can i read at a time cdata and attributes ...?
Xml file is
prakash nagar
begumpet
hyderabad
andhra pradesh
srnagar
ameerpet
hyderabad
andhra pradesh
anna salai
t nagar
chennai
tamilnadu
Cs File is
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/XMLFile.xml"));
//XmlNodeList node = doc.GetElementsByTagName("Books");
XmlNode node = doc.DocumentElement;
foreach (XmlNode cnode in node)
{
if (cnode.HasChildNodes)
{
foreach (XmlNode ChildNode in cnode.ChildNodes)
{
Response.Write("
Child node is" + cnode.InnerText + "
"+cnode.NodeType);
foreach (XmlAttribute nodeAttribute in ChildNode.Attributes) //Excetptio occured here...// Object reference not set to an instance of an object.
{
Response.Write("
Attributes is" + nodeAttribute.InnerXml + "
");
}
////Response.Write("
Child node is"+cnode.InnerText+"
");
}
if (cnode is XmlCDataSection)
{
XmlCDataSection cdatasection = cnode as XmlCDataSection;
Response.Write("
CDATA" + cdatasection.InnerText + "
");
}
}
//Response.Write(cnode.InnerText);
}
}
I am using xml in this way and also reading in right but when i add CDATA and reading it giving me exception but why i don't know can any one help me...?
how can i read at a time cdata and attributes ...?
Xml file is
begumpet
ameerpet
t nagar
Cs File is
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/XMLFile.xml"));
//XmlNodeList node = doc.GetElementsByTagName("Books");
XmlNode node = doc.DocumentElement;
foreach (XmlNode cnode in node)
{
if (cnode.HasChildNodes)
{
foreach (XmlNode ChildNode in cnode.ChildNodes)
{
Response.Write("
Child node is" + cnode.InnerText + "
"+cnode.NodeType);
foreach (XmlAttribute nodeAttribute in ChildNode.Attributes) //Excetptio occured here...// Object reference not set to an instance of an object.
{
Response.Write("
Attributes is" + nodeAttribute.InnerXml + "
");
}
////Response.Write("
Child node is"+cnode.InnerText+"
");
}
if (cnode is XmlCDataSection)
{
XmlCDataSection cdatasection = cnode as XmlCDataSection;
Response.Write("
CDATA" + cdatasection.InnerText + "
");
}
}
//Response.Write(cnode.InnerText);
}
}

VulpesPosted Aug 15, 2011, 6:22 AM
Try it like this:
Attributes is " + nodeAttribute.InnerXml + "
");
CDATA " + cdatasection.InnerText + "
");
Child node is " + ChildNode.InnerText + "
"+cnode.NodeType);
Child node is"+cnode.InnerText+"
");