house plans
HAPPY SPRING! We are offering Free Ground Shipping.
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
12732 Views

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
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
Garage Plans with Shops, Mother In-Law Suites, Apartments and Bonus Square Footage
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
Luxurious Mountain Craftsman House Plans
House Plans
The In-Law Suite Revolution
House Plans
The Finest Duplex, Town House, and Multi Unit Home Plans
House Plans
Florida and California House Plans With a Tuscan Style
House Plans
Beachfront, Coastal and Key West Home Plans
House Plans
Country Porches and Beautiful Farmhouses
House Plans
ARTICLES BY TOPIC
A Home Builders Opinion Air Conditioning Tips Architecture Beachfront Houseplans building lots bungalow Cape Cod House Plans Color Photos Color Schemes Contemporary Style country house plans craftsman house plans Curb Appeal Custom vs Stock House Plans Customer Service Design Do-It-Yourself Door Hardware Door knobs Doorknobs Dream Homes Engineering House Plans european house plans Exterior Materials Extreme Makeover Feng Shui Floorplan Layout Frank Lloyd Wright French Country Home Design Garage Plans Garages green design Home Builders Home Designers Home plans Homebuilding activity homeplans house plan styles house plans House Plans with Photos Housing Market Indoor Gyms in-law suites Jake England Landscaping Log Cabins luxury home plans Luxury House Plans Mediterranean Homeplans
RECENT ARTICLES
Landscape Architecture: Influences and Trends in Whole House Design
House Plans
Thomas Jefferson: The Architect and The Landscape Artist
House Plans
Luxury House Plans from The Plan Collection Featured in Wall Street Journal
House Plans
Great Women in Architecture: Hearst Castle's Julia Morgan
House Plans
TPC Salutes Great Women Architects: Anna Keichline
House Plans
Profiles in Architecture & Design: African American Architects Who Changed Our World
House Plans
The Plan Collection Announces the Best Price Guarantee in the House Plans Industry
House Plans
Architecture and the Presidents: Abraham Lincoln
House Plans
Great 4 bedroom house plan for growing families
House Plans
Developing a Budget to Build Your House Plan
Business
© 2013 The Plan Collection, LLC