|
| |
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/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAAR]]></Picture> </Content></Contents> |
.NET Force is optimised for
Microsoft Internet Explorer 5 browsers.
Copyright © 2004 .NET Force.
Terms and Condition. All rights reserved.
|
 |
|