DocumentBase.XMLSchemaViolations Propriedade

Definição

Obtém uma coleção XMLNodes que representa todos os nós no documento que têm erros de validação.

public Microsoft.Office.Interop.Word.XMLNodes XMLSchemaViolations { get; }

Valor da propriedade

XMLNodes

Uma coleção XMLNodes que representa todos os nós no documento que têm erros de validação.

Exemplos

O exemplo de código a seguir define o valor de cada nó filho do elemento raiz no documento para uma cadeia de caracteres e, em seguida, exibe os nomes dos nós que têm erros de validação. Por exemplo, qualquer nó que mapeia para um elemento de esquema com um tipo inteiro relatará um erro de violação. Para usar esse exemplo, execute-o na classe ThisDocument em um projeto no nível de documento.

private void DocumentXMLSchemaViolations()
{
    System.Text.StringBuilder stringBuilder1 =
        new System.Text.StringBuilder();

    // Set the node text for all child nodes of the 
    // root element.
    foreach (Word.XMLNode node in this.XMLNodes[1].ChildNodes)
    {
        node.Text = "A string value";
    }

    // Add the names of the nodes with violations to 
    // the StringBuilder.
    foreach (Word.XMLNode node in this.XMLSchemaViolations)
    {
        stringBuilder1.Append(
            node.BaseName + ", ");
    }

    // End the StringBuilder with a period.
    stringBuilder1.Remove(stringBuilder1.Length - 2, 2);
    stringBuilder1.Append(".");

    MessageBox.Show("The document contains " +
        this.XMLSchemaViolations.Count.ToString() +
        " element(s) with errors: " + stringBuilder1.ToString());

}
Private Sub DocumentXMLSchemaViolations()
    Dim stringBuilder1 As New System.Text.StringBuilder()

    ' Set the node text for all child nodes of the 
    ' root element.
    Dim node As Word.XMLNode
    For Each node In Me.XMLNodes(1).ChildNodes
        node.Text = "A string value"
    Next node

    ' Add the names of the nodes with violations to 
    ' the StringBuilder.
    Dim node2 As Word.XMLNode
    For Each node2 In Me.XMLSchemaViolations
        stringBuilder1.Append(node2.BaseName & ", ")
    Next node2

    ' End the StringBuilder with a period.
    stringBuilder1.Remove(stringBuilder1.Length - 2, 2)
    stringBuilder1.Append(".")

    MessageBox.Show("The document contains " & Me.XMLSchemaViolations.Count.ToString() _
        & " element(s) with errors: " & stringBuilder1.ToString())
End Sub 

Aplica-se a