XML Exception if text contains xml characters
Status: Beta
Brought to you by:
larsbm
Hi Lars,
if you pass a text like "A&O" to the method
CreateParagraphCollection of the ParagraphBuilder (and
probably that happens in other methods too), an
XmlException is thrown (here: Entity error).
The text must be parsed for the special xml chars that
have to be replaced (here "&" by "&").
Michael
Logged In: YES
user_id=1574489
TextBuilder.BuildTextCollection does also throw an exception.
Do something like this:
string xmlStartTag = "<?xml version=\"1.0\"
encoding=\"UTF-8\" ?>";
ITextCollection txtCollection = new ITextCollection();
text = WhiteSpaceHelper.GetWhiteSpaceXml(text);
text = XXX.ReplaceXmlEntityChars(text);
text = text.Replace("\t", "<t/>");
text = text.Replace("\n", "<n/>");
xmlStartTag += "<txt>"+text+"</txt>";
where XXX is a helper class and the method could look like this:
public static string ReplaceXmlEntityChars(string text)
{
text = text.Replace("&", "&");
text = text.Replace("\"", """);
text = text.Replace("'", "'");
text = text.Replace("<", "<");
text = text.Replace(">", ">");
return text;
}