473,414 Members | 1,590 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,414 software developers and data experts.

How to decode 'safe' html back to original raw text?

Is it possible to use features from XmlDocument to unescape text back to its
original raw text format after it has been escaped to handle non-HTML
compliant character strings?

I have code that serializes text to an XML file and then deserializes back
to text. If the user enters XML illegal text like "<Actor1>", the code
properly escapes it to "&lt;Actor1&gt;", something that doesn't interfere
with the XML syntax, and writes it into the Xml document, but the extracted
text from the node is not being 'unescaped' back to its original text. Is
there some way to use the built in features to restore the text data without
having to write yet another XML decoder parser?

Here's how the serialization works - Assuming that an XmlDocument object has
been created and it has some node already associated with it named
nodeParent, this is how a text node will be appended to that node.

public static XmlNode AppendText( XmlNode nodeParent, string nodeName,
string nodeValue )
{
XmlNode nodeText = nodeParent.OwnerDocument.CreateElement( nodeName );
nodeParent.AppendChild( nodeText );
nodeParent.Appendchild( nodeParent.OwnerDocument.CreateTextElement(
nodeValue ) );
return nodeText;
}

Assume that the text string "<Actor0>" is saved to node "Label". The result
in the XML file is

<Label>&lt;Actor0&gt;</Label>

To get the data out, I'm (incorrectly) using the XmlNode's InnerText
property, which simply returns the serialized text as it was written to the
file instead of converting it back to the original text. Is there an XmlNode
function that will unescape the text, thus returning the original text?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
Feb 12 '07 #1
2 10923
check this out:
http://msdn.microsoft.com/msdnmag/issues/01/01/xml/

chanmm

"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Is it possible to use features from XmlDocument to unescape text back to
its original raw text format after it has been escaped to handle non-HTML
compliant character strings?

I have code that serializes text to an XML file and then deserializes back
to text. If the user enters XML illegal text like "<Actor1>", the code
properly escapes it to "&lt;Actor1&gt;", something that doesn't interfere
with the XML syntax, and writes it into the Xml document, but the
extracted text from the node is not being 'unescaped' back to its original
text. Is there some way to use the built in features to restore the text
data without having to write yet another XML decoder parser?

Here's how the serialization works - Assuming that an XmlDocument object
has been created and it has some node already associated with it named
nodeParent, this is how a text node will be appended to that node.

public static XmlNode AppendText( XmlNode nodeParent, string nodeName,
string nodeValue )
{
XmlNode nodeText = nodeParent.OwnerDocument.CreateElement( nodeName );
nodeParent.AppendChild( nodeText );
nodeParent.Appendchild( nodeParent.OwnerDocument.CreateTextElement(
nodeValue ) );
return nodeText;
}

Assume that the text string "<Actor0>" is saved to node "Label". The
result in the XML file is

<Label>&lt;Actor0&gt;</Label>

To get the data out, I'm (incorrectly) using the XmlNode's InnerText
property, which simply returns the serialized text as it was written to
the file instead of converting it back to the original text. Is there an
XmlNode function that will unescape the text, thus returning the original
text?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
Feb 13 '07 #2
XmlNode.InnerText is supposed to unescape text. However, XmlNode.InnerXml
does not. Some of the code branches were incorrectly using node.InnerXml.
Once this was fixed then everything worked in the desired manner.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Is it possible to use features from XmlDocument to unescape text back to
its original raw text format after it has been escaped to handle non-HTML
compliant character strings?

I have code that serializes text to an XML file and then deserializes back
to text. If the user enters XML illegal text like "<Actor1>", the code
properly escapes it to "&lt;Actor1&gt;", something that doesn't interfere
with the XML syntax, and writes it into the Xml document, but the
extracted text from the node is not being 'unescaped' back to its original
text. Is there some way to use the built in features to restore the text
data without having to write yet another XML decoder parser?

Here's how the serialization works - Assuming that an XmlDocument object
has been created and it has some node already associated with it named
nodeParent, this is how a text node will be appended to that node.

public static XmlNode AppendText( XmlNode nodeParent, string nodeName,
string nodeValue )
{
XmlNode nodeText = nodeParent.OwnerDocument.CreateElement( nodeName );
nodeParent.AppendChild( nodeText );
nodeParent.Appendchild( nodeParent.OwnerDocument.CreateTextElement(
nodeValue ) );
return nodeText;
}

Assume that the text string "<Actor0>" is saved to node "Label". The
result in the XML file is

<Label>&lt;Actor0&gt;</Label>

To get the data out, I'm (incorrectly) using the XmlNode's InnerText
property, which simply returns the serialized text as it was written to
the file instead of converting it back to the original text. Is there an
XmlNode function that will unescape the text, thus returning the original
text?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Feb 13 '07 #3

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

Similar topics

11
by: Derek Fountain | last post by:
I was just writing a sanitisation route for a bit of user input. The data is an English text description of a product, and will go into a DB, then back out to other user's browsers. As per...
2
by: Chris | last post by:
Wondering if anyone can help me... I have a text node that has been HTML encoded. The text is has CDATA tags around it. The problem is I can't seem to decode the text. When the CDATA is gone, I...
9
by: Paul Morrow | last post by:
I have seen the technique where a number of rows in a database are displayed in an html table so that each column of each row is editable. They use a single form surrounding the table, where each...
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
11
by: Brett | last post by:
In Yahoo mail, I click the Inbox link and see my messages. If I view source, I don't have HTML which contains the URL of each message. The source HTML contains javascripting and framesets. This...
4
by: MB | last post by:
Hello everyone! These lines were inspired by the "DIV without line breaks" posted by Johnny Two Dogs on June 22. I know it is an old issue, but I want to share a few remarks that could be of...
0
by: cdonyi | last post by:
Hi I am looking for a clean way to scrub HTML encoded strings and display only certain tags back to the browser. I am thinking of using HttpUtility.HTMLEncode/Decode methods. My plan is to...
6
by: Susan Geller | last post by:
I have an c#.net app which writes to a sql server db and in one table, stores data with html coding. (string strNote = HttpUtility.HtmlEncode(txtNote.Text);) I want to report on this data from...
1
by: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.