XmlConvert.VerifyWhitespace(String) メソッド

定義

文字列引数のすべての文字が有効な空白文字の場合、渡された文字列インスタンスを返します。

public:
 static System::String ^ VerifyWhitespace(System::String ^ content);
public static string VerifyWhitespace (string content);
static member VerifyWhitespace : string -> string
Public Shared Function VerifyWhitespace (content As String) As String

パラメーター

content
String

検証する String

戻り値

String

文字列引数のすべての文字が有効な空白文字の場合は渡された文字列インスタンス。それ以外の場合は null

次の例では、このメソッドを VerifyWhitespace 使用して、start 要素に割り当てられた値に無効な文字が存在することを検出します。

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

try
{
    // Write the root element.
    writer5.WriteStartElement("root");

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

    // Write the end tag for the legal element.
    writer5.WriteEndElement();
    // Write the end tag for the root element.
    writer5.WriteEndElement();
    writer5.Close();
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
    writer5.Close();
}
Dim writer5 As XmlTextWriter = New XmlTextWriter("outFile.xml", Nothing)
Dim illegalWhiteSpaceChar As Char = "_"

Try
    ' Write the root element.
    writer5.WriteStartElement("root")
    writer5.WriteStartElement("legalElement")
    ' Throw an exception due illegal white space character.
    writer5.WriteString("ValueText" + _
        XmlConvert.VerifyWhitespace("   " + illegalWhiteSpaceChar))

    writer5.WriteEndElement()

    ' Write the end tag for the root element.
    writer5.WriteEndElement()

    writer5.Close()

Catch e As XmlException
    Console.WriteLine(e.Message)
    writer5.Close()
End Try

注釈

渡された引数以外の値は返されません。 空白文字に対して有効な文字は XML エディションによって異なるため、XML バージョンのオーバーロードは必要ありません。

使用できる文字の詳細については、 XML 1.0 仕様 (第 4 版) の運用環境 [3] S を参照してください。

パラメーターが null の場合は、an ArgumentNullException がスローされます。

いずれかの文字が有効な空白文字でない場合は、最初に無効な文字が検出された情報を XmlException 含む an がスローされます。

適用対象