house plans
FREE Shipping on All House Plans!
Home >> Technology >> Article
Search entire site

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

Tags : ,
Published On : 03-03-2008
Author : Steve Donegan

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, "");
XML Encoding Problems - Hexadecimal Value 0x1A, is an Invalid Character
Glossary of Terms
Understanding Blueprints
Understanding Copyright
What's included in a set of house plans?
Why pre-drawn house plans?
1. Building on slab vs. crawl space vs. basement? Advantages / disadvantage
House Plans
Luxurious Mountain Craftsman House Plans
House Plans
The Finest Duplex, Town House, and Multi Unit Home Plans
House Plans
The In-Law Suite Revolution
House Plans
Florida and California House Plans With a Tuscan Style
House Plans
European and Luxury House Plans, Large and Small!
House Plans
Country Porches and Beautiful Farmhouses
House Plans
2x4 or 2x6 construction?
House Plans
Craftsman House Plans from Extreme Makeover: Home Edition
House Plans
Luxury House Plans
House Plans
A Frame House Plans A Home Builders Opinion Air Conditioning Tips Architecture Beachfront Houseplans blueprints building lots bungalow Bungalow House Plans Cape Cod House Plans Coastal House Plans Color Photos Color Schemes Contemporary Style country house plans craftsman house plans Curb Appeal Custom vs Stock House Plans Customer Service Design design trends Do-It-Yourself Door Hardware Door knobs Doorknobs Dream Homes Engineering House Plans european house plans Exterior Materials Extreme Makeover Farmhouse House Plans Feng Shui Floor plans Floorplan Layout Frank Lloyd Wright French Country Home Design french house plans Garage Plans Garages green design green house plans Halloween house high performance house plans Home Builders home buying home design Home Design Trends Home Designers Home Designs
Trends to Build Home Plans that Embrace Nature and the Environment
House Plans
From Log Cabins to Southfork Ranch and Everything in Between… Variety Spices Texas Style Homes
House Plans
The Great Room: A Throwback to Medieval Times Finds Its Way in the Modern Age
House Plans
“Girl Power” in the 1900s: The First Women Architects Find Success in a Man’s World
House Plans
New Technologies for the Conscious Home Save Energy
Ready for Your Own Vacation Home? Here Is What to Look For
House Plans
Historical Progression of 3D Printing From Prototypes to 3D House Plans to Robotics
House Plans
What to Look for in an Affordable House Plan: Simplicity, Efficiency and Practicality –With Style!
House Plans
Design Trends in Renovation & House Plans for Home Builders
House Plans
The French House Plan: An Eclectic Mix of the Romantic, Rustic, and Majestic
House Plans
© 2014 The Plan Collection, LLC