473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to retrieve section CDATA from xml file

Hi,

I have got xml document with CDATA sections containing special characters
like links to images. All Iwant is to display the content in my div
section.

I tried like this:

protected void Button2_Click(o bject sender, EventArgs e)

{

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load("ht tp://www.e-biznes.pl/out/rss-ebiz-full-html.xml");

XPathNavigator xpathNav = xmlDoc.CreateNa vigator();

xpathNav.MoveTo Root();

RecurseNavNodes (xpathNav);

}

public void RecurseNavNodes (XPathNavigator node)

{

//start recursive loop with level 0

RecurseNavNodes (node, 0);

}

public void RecurseNavNodes (XPathNavigator node, int level)

{

if (node.Name == "item")

{

ItemXmlXPathNav igator (node);

}

string s = null;

s = string.Format(" {0} <b>Type:</b>{1} <b>Name:</b>{2} <b>Attr:</b", new
string('-', level), node.NodeType, node.Name);

if (node.InnerXml. Length 0 && level>0)

{

s += "</BR>" + node.InnerXml;

}

if (node.HasChildr en)

{

node.MoveToFirs tChild();

do

{

RecurseNavNodes (node, level + 1);

} while (node.MoveToNex t()); node.MoveToPare nt();

}

}

public void ItemXmlXPathNav igator(XPathNav igator node)

{
if (node.HasChildr en)

{

node.MoveToFirs tChild();

do

{

if (node.Name == "title")

{

lbl.Text += node.InnerXml + "<BR/><BR/>";

}

if (node.Name == "descriptio n")

{
//XmlCDataSection cdatas = node.;

//cdatas.InnerXml = node.InnerXml;

string zawartosc = node.InnerXml;

zawartosc = zawartosc.Repla ce("&lt;", "<");

zawartosc = zawartosc.Repla ce("&gt;", ">");

lbl.Text += "<font color='blue'>" + zawartosc + "</font>" + "<BR/><BR/>";

}

} while (node.MoveToNex t()); node.MoveToPare nt();

}

}

But I got escaped characters instead of html tags.

I have got html tags like <img src=.... oraz embadded swfs, so I need to
retrieve CDATA section in other way than normal

node.InnerXml

Can you provide me a snippet of a code.

Thank you in advance.

Darek T.
May 28 '07 #1
1 7556
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("ht tp://www.e-biznes.pl/out/rss-ebiz-full-
html.xml");

Regex CDATA = new Regex("<!\\[CDATA\\[ ?(.*?)\\ ?]\\]>",
RegexOptions.Si ngleline);
StringBuilder output = new StringBuilder() ;
foreach (XmlNode node in
xmlDoc.GetEleme ntsByTagName("i tem"))
{
string description =
CDATA.Match(nod e.InnerXml).Gro ups[1].Value;
output.AppendFo rmat("<h3><a href=\"{1}\">{0 }</a></
h3>{2}<br/><br/>{3}<br/><br/><hr/>", node["title"].InnerText,
node["link"].InnerText, node["pubDate"].InnerText, description);
}

HTH :)

May 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6472
by: nowhere | last post by:
Hi, I need to preserve some ASCII control characters (CR and LF) within an XML file so I have included the data in a CDATA section. However, when parsing it using expat, I lose the CR characters. My question is: Should I be using a different character set (not UTF-8) or is this a bug in expat? TIA, Mark
6
8335
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally, the easiest way to represent it would be to put the embedded XML example inside a CDATA section. But if the example has a CDATA section itself, then...
10
42936
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA...
4
2245
by: troppfigo | last post by:
I have this example of xml <?xml version="1.0"?> <xml> <!]> </xml> I want to extract the contained data from <body> tag using an xslt transformation. I want to obtain this
11
6429
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem =...
2
5228
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL reformats the XML to another format (still XML, not HTML). This works fine, but whatever I do, I can't get the finally output section to have CDATA...
6
4783
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all city values should display in city selection field and when user select any one city value then this state of this city should be display auto in state ...
1
4076
!NoItAll
by: !NoItAll | last post by:
The MSXML parser is choking on a single character that often appears in my data within a CDATA section. Try this: Dim bRet As Boolean Dim lRet as long Dim xmlDoc As MSXML2.DOMDocument Set xmlDoc = New MSXML2.DOMDocument
1
2324
by: Kapil Choubisa | last post by:
I have a XML file. In it I have a CDATA section for HTML Information. I need that Information in a browser. Can any body help me to find out it. My XML an HTML are in this format <paragraph> <position>1</position> <title>Title</title> <text> <!]>
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.