473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(object sender, EventArgs e)

{

XmlDocument xmlDoc = new XmlDocument();

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

XPathNavigator xpathNav = xmlDoc.CreateNavigator();

xpathNav.MoveToRoot();

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")

{

ItemXmlXPathNavigator (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.HasChildren)

{

node.MoveToFirstChild();

do

{

RecurseNavNodes(node, level + 1);

} while (node.MoveToNext()); node.MoveToParent();

}

}

public void ItemXmlXPathNavigator(XPathNavigator node)

{
if (node.HasChildren)

{

node.MoveToFirstChild();

do

{

if (node.Name == "title")

{

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

}

if (node.Name == "description")

{
//XmlCDataSection cdatas = node.;

//cdatas.InnerXml = node.InnerXml;

string zawartosc = node.InnerXml;

zawartosc = zawartosc.Replace("&lt;", "<");

zawartosc = zawartosc.Replace("&gt;", ">");

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

}

} while (node.MoveToNext()); node.MoveToParent();

}

}

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 7539
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("http://www.e-biznes.pl/out/rss-ebiz-full-
html.xml");

Regex CDATA = new Regex("<!\\[CDATA\\[ ?(.*?)\\ ?]\\]>",
RegexOptions.Singleline);
StringBuilder output = new StringBuilder();
foreach (XmlNode node in
xmlDoc.GetElementsByTagName("item"))
{
string description =
CDATA.Match(node.InnerXml).Groups[1].Value;
output.AppendFormat("<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
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...
6
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,...
10
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,...
4
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
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);...
2
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...
6
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...
1
!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...
1
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> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.