469,579 Members | 1,899 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Retreiving Xml child nodes using DataSet and XmlDataDocument

I am loading an Xml file from a sql server. I have one field that
contains child nodes stored as text. The problem is, when I try to imort
the dataset into a XmlDataDocument, it loads the whole thing as a text
element. (with all of the special characters converted) The best
solution I've found so far is to do a string replace on all of the
special characters. Like so:

DataSet ds = new DataSet();
ds.EnforceConstraints = false;
SqlDataAdapter da = new SqlDataAdapter(query, connStr);
da.Fill(ds, "Keywords");
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
string s = xmlDoc.SelectSingleNode("NewDataSet/Keywords/Entry").InnerText;
s = UnConvertEntities(s);
xmlDoc.SelectSingleNode("NewDataSet/Keywords/Entry").InnerXml = s;

// UnConvertEntities(string s)
s.Trim();
s.Replace("&", "&");
s.Replace("&lt;", "<");
s.Replace("&gt;", ">");
s.Replace("&apos;", "'");
s.Replace("&quot;", "\"");
return s;

Is there any better way to do this, or am I stuck with this method?
Also, I've found that this method adds a large amount of whitespace at
the end of the last element, but that may be a seperate problem.

Nov 12 '05 #1
2 5285
Anas M. Nebuchadnezzar XXXVII wrote:
I am loading an Xml file from a sql server. I have one field that
contains child nodes stored as text. The problem is, when I try to imort
the dataset into a XmlDataDocument, it loads the whole thing as a text
element.

I don't see any problem here. If it is stored as text, why it should be
not text node? Escaped markup is always a trouble waiting to happen,
always avoid it.
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg Tkachenko wrote:
Anas M. Nebuchadnezzar XXXVII wrote:
I am loading an Xml file from a sql server. I have one field that
contains child nodes stored as text. The problem is, when I try to
imort the dataset into a XmlDataDocument, it loads the whole thing as
a text element.


I don't see any problem here. If it is stored as text, why it should be
not text node? Escaped markup is always a trouble waiting to happen,
always avoid it.


My problem is, It's not stored in the database escaped. I'm storing it
in a char field for lack of knowing which type works better. I've stored
the literal characters (ie. '<') and keep getting the escaped characters
(ie. '&lt;') I was wondering if there was a better way to store this
data, and convert it from text, to part of the document.

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by kevin_Eld | last post: by
3 posts views Thread by Tom Vukovich | last post: by
1 post views Thread by Geoffrey Gallaway | last post: by
reply views Thread by gilly3 | last post: by
1 post views Thread by =?Utf-8?B?TmFjaA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.