house plans
Thanksgiving Sale: 10% Off All Plans. Use Promo Code THANK14 at checkout. Ends 12/1. Plus - Free shipping.
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
20711 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
Building a home plan with an indoor basketball court
House Plans
1. Building on slab vs. crawl space vs. basement? Advantages / disadvantage
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 house plans 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
RECENT ARTICLES
Built-in Storage Tips for your New House Plan
House Plans
Make Your Thanksgiving Home Décor Fun and Fanciful
House Plans
Home Design Trends to Watch For in 2015
House Plans
The Right Appliances for your New Home Plan
House Plans 101
The Open Floor Plan: Stylish Living without Walls
House Plans
Regional Trends in Single Family Homes: Size, Price and Design Features Vary
House Plans 101
What to Expect from a New Home Inspection
House Plans 101
Pacific Northwest Style Adapts Architectural Designs to Region’s Landscape & Climate
House Plans
Put Some Halloween Magic and Mystery in Your Home
House Plans
Window Designs for Your New House Plan
House Plans 101
© 2014 The Plan Collection, LLC