R
Richard Lewis Haggard
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 "<Actor1>", 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><Actor0></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?
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 "<Actor1>", 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><Actor0></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?