Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 813725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:24:25+00:00 2026-05-15T01:24:25+00:00

I have a webpage that accepts HTML-input from users. The input is converted into

  • 0

I have a webpage that accepts HTML-input from users. The input is converted into an xml document using the System.Xml namespace, like this:

var doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("root"));
doc.DocumentElement.SetAttribute("BodyHTML", theTextBox.Text);

Afterwards an Xsl transformation (System.Xml.Xsl.XslCompiledTransform) is used on the data.

Users tend to write text in Microsoft Word, using bullets, quotes etc. When pasting to my page, their text includes invalid characters such as 0x0C, 0x03 and so on. When using the xsl transformation, this error occurs “hexadecimal value 0x0C, is an invalid character.”

My fix so far has been to eliminate the characters that I’ve found to be offensive, using loops and String.Replace:
All characters from 0 to 31, except 9, 10 and 13 are replaced with String.Empty.

What I’m looking for is a better way to do this. A built-in .Net method? Or perhaps just a complete list of illegal unicode characters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:24:26+00:00Added an answer on May 15, 2026 at 1:24 am

    Found two answers which do the same thing

    1. http://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/
    2. http://www.theplancollection.com/house-plan-related-articles/hexadecimal-value-invalid-character

    The first uses a StringBuilder, loops through characters one by one and filters out illegal chars.
    The second one uses a Regex and .Replace to accomplish the same thing.
    Both authors looked at the Xml standard to find out which characters are illegal.

    I did some timings on a long string (1.8 MB file run 1,000 times) and a short string (“Hello world” run 10,000,000 times). The StringBuilder method was ~ 3 times faster than the regex. The regex was of course only compiled once, unlike the code to which I linked.

    Long string:

    CleanInvalidXmlChars time: 00:00:07.4356230
    SanitizeXmlString    time: 00:00:02.3703305
    

    Short string:

    CleanInvalidXmlChars time: 00:00:05.2805834
    SanitizeXmlString    time: 00:00:01.8319114
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a program that basically reads html from a webpage. After sending
We have a form that lets people input html formatted text and that input
I have a web page that accepts an excel file, reads data from it
I have a webpage that is transferring A stylesheet as a text/plain MIME type.
I have a webpage that when landed on, will detect a user's physical location
I have a webpage that retrieves data (via ajax/php) and shows it in an
I have a webpage that redirects to another webpage like this: http://www.myOtherServer.com/Sponsor.php?RedirectPage=http://mylink.com/whereIwasgoingtogo.html Then the
I have a webpage that displays a very large list of data. Since this
I have a webpage that I don't have the ability to change the underlying
I have a webpage that activates a print job on a printer. This works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.