XmlConvert.VerifyWhitespace(String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve a instância de string passada se todos os caracteres no argumento da string forem caracteres de espaço em branco válidos.
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
Parâmetros
Devoluções
A instância de string passed-in se todos os caracteres no argumento string são caracteres de espaço em branco válidos, caso contrário null.
Exemplos
O exemplo seguinte utiliza o VerifyWhitespace método para detetar a presença de um carácter inválido num valor atribuído ao elemento inicial.
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
Observações
Nenhum outro valor além do argumento passado deve ser devolvido. Os caracteres válidos para espaços em branco não variam entre as edições XML, pelo que não é necessária sobrecarga de versões em xml.
Consulte especificação XML 1.0 (quarta edição) produção [3] S para detalhes sobre os caracteres permitidos.
Se o parâmetro for nulo, um ArgumentNullException será lançado.
Se algum dos caracteres não for espaço em branco válido, um XmlException é apresentado com informação sobre o primeiro carácter inválido encontrado.