Strip Non Valid XML Characters.

image_pdfimage_print

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

namespace Facebook.Utility
{
///

/// Helper functions for string manipulation
///

public static class StringHelper
{
///

/// Strip Non Valid XML Characters.
///

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(); } } } [/csharp]

This entry was posted in XML-RPC. Bookmark the permalink.