Proprietà DocumentBase.XMLSchemaViolations

Ottiene un insieme di Microsoft.Office.Interop.Word.XMLNodes che rappresenta tutti i nodi del documento per cui si sono verificati errori di convalida.

Spazio dei nomi:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Sintassi

'Dichiarazione
Public ReadOnly Property XMLSchemaViolations As XMLNodes
    Get
public XMLNodes XMLSchemaViolations { get; }

Valore proprietà

Tipo: Microsoft.Office.Interop.Word.XMLNodes
Insieme di Microsoft.Office.Interop.Word.XMLNodes che rappresenta tutti i nodi del documento per cui si sono verificati errori di convalida.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come impostare su una stringa il valore di ogni nodo figlio dell'elemento radice del documento e come visualizzare i nomi dei nodi per cui si sono verificati errori di convalida. Ad esempio, viene segnalato un errore di violazione per tutti i nodi mappati a un elemento schema con un tipo Integer. Per utilizzare questo esempio, eseguirlo dalla classe ThisDocument in un progetto a livello di documento.

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 
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());

}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

DocumentBase Classe

Spazio dei nomi Microsoft.Office.Tools.Word