house plans
FREE Shipping on All House Plans!
Question or to order
Home >> Technology >> Article
Search entire site
DREAM. LEARN. DISCOVER... GET STARTED.
Technology
Technology

XML Encoding Problems - Hexadecimal Value 0x1A, is an Invalid Character

Tags : ,
Published On : 03-03-2008
Author : Steve Donegan
19630 Views
ShareThis

Recently I started noticing exceptions in my log files that stated "hexadecimal value 0x1A, is an invalid character". I did some searching and a lot of other people have had the same problem. It occurs when someone pastes in text that contains specific unicode characters that are invalid in XML. From what I gather this frequently happens when someone copies in text from Microsoft Word.

The trick was to find out which characters are invalid and then use a regular expression to remove them.

You can look at the specs for all the details:

But it is probably easier to just get the code:

        /// <summary>
        /// This removes characters that are invalid for xml encoding
        /// </summary>
        /// <param name="text">Text to be encoded.</param>
        /// <returns>Text with invalid xml characters removed.</returns>
        public static string CleanInvalidXmlChars(string text)
        {
            // From xml spec valid chars:
            // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]    
            // any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
            string re = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";
            return Regex.Replace(text, re, "");
        }
COMMENTS
RELATED ARTICLES
XML Encoding Problems - Hexadecimal Value 0x1A, is an Invalid Character
Technology

Search House Plans

Bedrooms
 1  2  3  4  5+
Bathrooms
 1  1½  2  2½  3  3½  4+
Stories Garage Bays
 1  1½  2  1  2  3+
Square Feet
to
View Results
Enter Plan #:
HOUSE PLANS 101
FAQ
Glossary of Terms
Understanding Blueprints
Understanding Copyright
What's included in a set of house plans?
Why pre-drawn house plans?
MOST POPULAR ARTICLES
Plans with Indoor Basketball Courts
House Plans
1. Building on slab vs. crawl space vs. basement? Advantages / disadvantage
House Plans
Building a home plan with an indoor basketball court
House Plans
Garage Plans with Shops, Mother In-Law Suites, Apartments and Bonus Square Footage
House Plans
Luxurious Mountain Craftsman House Plans
House Plans
XML Encoding Problems - Hexadecimal Value 0x1A, is an Invalid Character
Technology
Beachfront, Coastal and Key West Home Plans
House Plans
The Finest Duplex, Town House, and Multi Unit Home Plans
House Plans
European and Luxury House Plans, Large and Small!
House Plans
The In-Law Suite Revolution
House Plans
ARTICLES BY TOPIC
A Frame House Plans A Home Builders Opinion Air Conditioning Tips Architecture Beachfront Houseplans blueprints building log building lots building mistakes bungalow Bungalow House Plans Cape Cod House Plans celebrity home designs Coastal House Plans Color Photos Color Schemes Considerations for Building Foundations in a New House Plan Contemporary Style country house plans craftsman house plans Curb Appeal Custom vs Stock House Plans Customer Service Design
RECENT ARTICLES
Is Tiny Living For You? The Tiny House: A Look at a Minimalist Style
House Plans
Best House Plans: Traffic Patterns, Doors and Windows
House Plans 101
Mold Growth from Poor Construction on your Modern House Plan
House Plans 101
Classic Georgian Colonial House Plan for Growing Families
House Plans
Installing the Proper Insulation
House Plans 101
Considerations for Building Foundations in a New House Plan
House Plans 101
Award-Winning TV Celebrity Home Designs
House Plans
Avoid Costly Home Building Mistakes
House Plans 101
Single Level House Plans for Now and Your Future
House Plans 101
Country House Design: An Expression of Picturesque and Rustic Simplicity
House Plans
© 2014 The Plan Collection, LLC