Wednesday, September 08, 2010
Search:
Article
48Hrs Help PAQ's
FAQ's
Download
Books
MS Alerts
Write to Us
Feedback
Link




a) What are .NET My Services?
b) Why use .NET My Services?

Get This Blog via Email:


Email This Feed Using Squeet




Reading data from CData Section in XML


By Vinodh Kumar
November 3, 2004
Page is Viewed 22550 times


  
Vinod Kumar[MVP]

In this article we will see the way to read the data from CData section of an XML file. The CData sections are used to quote or escape blocks of text to keep that text from being interpreted as markup language.

To get the data from CData we should use XmlCDataSection class in the System.Xml Namespace the below code will get the image stored in binary format in XML CData Section and display the image.

string strPath = Server.MapPath(".") + @"\Sports.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
XmlElement root = doc.DocumentElement;
XmlNode node = doc.DocumentElement.SelectSingleNode(
@"/Contents/Content/Picture");
XmlNode childNode = node.ChildNodes[0];
if (childNode is XmlCDataSection)
{
XmlCDataSection cdataSection = childNode as XmlCDataSection;
Response.BinaryWrite(Convert.FromBase64String(cdataSection.Value));
}

The XML file structure looks like the one shown below.

<?xml version="1.0" encoding="utf-8" ?>
<Contents>
<Content>
<Title>Major League Baseball</Title>
<Picture><![CDATA[/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwh
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAAR]]></Picture>
</Content>
</Contents>


Class:
A reference type that encapsulates data (constants and fields) and behavior (methods, properties, indexers, events, operators, instance constructors, static constructors, and destructors), and can contain nested types. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a base class. See also: encapsulation, indexer, property, reference type.
Namespace:
A logical naming scheme for grouping related types. The .NET Framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as the ASP.NET technology or remoting functionality. Design tools can use namespaces to make it easier for developers to browse and reference types in their code. A single assembly can contain types whose hierarchical names have different namespace roots, and a logical namespace root can span multiple assemblies. In the .NET Framework, a namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time. See also: assembly.
.NET Force is optimised for Microsoft Internet Explorer 5 browsers.
Copyright © 2004 .NET Force.
Terms and Condition. All rights reserved.