Strip Non Valid XML Characters. : Schema « XML « C# / C Sharp






Strip Non Valid XML Characters.

   

//http://facebooktoolkit.codeplex.com/
//http://facebooktoolkit.codeplex.com/license
using System.Collections.Generic;
using System.Text;

namespace Facebook.Utility
{
    /// <summary>
    /// Helper functions for string manipulation
    /// </summary>
    public static class StringHelper
    {
        /// <summary>
        /// Strip Non Valid XML Characters.
        /// </summary>
        public static string StripNonValidXMLCharacters(string s)
        {
            StringBuilder _validXML = new StringBuilder(s.Length, s.Length); // Used to hold the output.
            char[] charArray = s.ToCharArray();

            if (string.IsNullOrEmpty(s)) return string.Empty; // vacancy test.

            for (int i = 0; i < charArray.Length; i++)
            {
                char current = charArray[i];
                if ((current == 0x9) ||
                (current == 0xA) ||
                (current == 0xD) ||
                ((current >= 0x20) && (current <= 0xD7FF)) ||
                ((current >= 0xE000) && (current <= 0xFFFD)))
                    _validXML.Append(current);
            }
            return _validXML.ToString();
        }
   }
}        

   
    
    
  








Related examples in the same category

1.Set XmlReaderSettings
2.Choose ValidationType
3.Validate an XML Document Against a Schema
4.Validate Schema
5.Use XML schema to validate XML documents
6.Use XmlReaderSettings to validate the Xml document
7.Is Well Formed Xml
8.XmlSchema is an in-memory representation of an XML Schema
9.Is Xml Valid
10.Xml Validation Helper
11.Get Intrinsic Simple Types Names from System.Xml.Schema.DatatypeImplementation
12.Reads a XML schema file and returns the information found in that.
13.XML reading functionality