Share via


XmlConvert.VerifyXmlChars(String) 메서드

정의

문자열 인수의 모든 문자와 서로게이트 쌍 문자가 올바른 XML 문자인 경우 전달된 문자열을 반환하고 그렇지 않으면 첫 번째 잘못된 문자에 대한 정보로 XmlException을 throw합니다.

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

매개 변수

content
String

확인할 문자가 포함된 String입니다.

반환

String

문자열 인수의 모든 문자와 서로게이트 쌍 문자가 올바른 XML 문자인 경우 전달된 문자열이고, 그렇지 않으면 첫 번째 잘못된 문자에 대한 정보로 XmlException을 throw합니다.

예제

다음 예제에서는 시작 요소에서 잘못된 문자를 검색하는 데 사용되는 메서드를 사용합니다 VerifyXmlChars .

XmlTextWriter writer3 = new XmlTextWriter("outFile.xml", null);
char illegalChar = '\uFFFE';
string charsToVerify = "Test String ";

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

    // Throw an exception due illegal character.
    writer3.WriteStartElement(
        XmlConvert.VerifyXmlChars(charsToVerify + illegalChar));

    writer3.WriteString("ValueText");
    writer3.WriteEndElement();

    // Write the end tag for the root element.
    writer3.WriteEndElement();

    writer3.Close();
}
catch (XmlException e)
{
    Console.WriteLine(e.Message);
    writer3.Close();
}
Dim writer3 As XmlTextWriter = New XmlTextWriter("outFile.xml", Nothing)
Dim illegalChar As Char = ChrW(CInt("&hFFFE"))
Dim charsToVerify As String = "Test String "

Try
    ' Write the root element.
    writer3.WriteStartElement("root")

    ' Throw an exception for name that contains illegal character.
    writer3.WriteStartElement( _
        XmlConvert.VerifyXmlChars(charsToVerify + illegalChar))

    writer3.WriteString("ValueText")
    writer3.WriteEndElement()

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

    writer3.Close()


Catch e As XmlException

    Console.WriteLine(e.Message)
    writer3.Close()
End Try

설명

전달된 인수 이외의 다른 값은 반환되지 않습니다. 허용되는 문자에 대한 자세한 내용은 XML 1.0 사양(네 번째 버전) 프로덕션 [2] Char 을 참조하세요.

매개 변수가 null이면 throw ArgumentNullException 됩니다. 유효한 xml 문자 XmlException 가 없는 문자가 있으면 첫 번째 잘못된 문자에 대한 정보가 throw됩니다.

적용 대상