Export (0) Print
Expand All

XmlConvert.VerifyWhitespace Method

Returns the passed-in string instance if all the characters in the string argument are valid whitespace characters.

Namespace:  System.Xml
Assemblies:   System.Xml (in System.Xml.dll)
  System.Xml.ReaderWriter (in System.Xml.ReaderWriter.dll)

public static string VerifyWhitespace(
	string content


Type: System.String

String to verify.

Return Value

Type: System.String
Returns the passed-in string instance if all the characters in the string argument are valid whitespace characters, otherwise null.

No other values than the passed in argument should be returned. The characters that are valid for whitespace do not vary between XML editions, so no xml version overload is required.

See XML 1.0 spec (fourth edition) production [3] S for details on the allowed characters.

If the parameter is null, an ArgumentNullException will be thrown.

If any of the characters are not valid whitespace characters, an XmlException is thrown with information about the first invalid character encountered.

The following example uses the VerifyWhitespace method to detect the presence of an invalid character in a value assigned to the start element.

            XmlTextWriter writer5 = new XmlTextWriter("outFile.xml", null);
            char illegalWhiteSpaceChar = '_';

                // Write the root element.

                // Throw an exception due illegal white space character.
                writer5.WriteString("ValueText" + 
                    XmlConvert.VerifyWhitespace("\t" + illegalWhiteSpaceChar));

                // Write the end tag for the legal element.
                // Write the end tag for the root element.

            catch (Exception e)

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft