Document.XMLSchemaViolations, propriété (System 2007)

Mise à jour : novembre 2007

Obtient une collection Microsoft.Office.Interop.Word.XMLNodes qui représente tous les nœuds présentant des erreurs de validation dans le document.

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word.v9.0 (dans Microsoft.Office.Tools.Word.v9.0.dll)

Syntaxe

<BrowsableAttribute(False)> _
Public ReadOnly Property XMLSchemaViolations As XMLNodes

Dim instance As Document
Dim value As XMLNodes

value = instance.XMLSchemaViolations
[BrowsableAttribute(false)]
public XMLNodes XMLSchemaViolations { get; }

Valeur de propriété

Type : Microsoft.Office.Interop.Word.XMLNodes

Collection Microsoft.Office.Interop.Word.XMLNodes qui représente tous les nœuds présentant des erreurs de validation dans le document.

Exemples

L'exemple de code suivant affecte la valeur de chaque nœud enfant de l'élément racine dans le document à une chaîne, puis affiche les noms des nœuds qui présentent des erreurs de validation. Par exemple, tout nœud qui mappe à un élément de schéma avec un type entier rapportera une erreur de violation.

Cet exemple illustre une personnalisation au niveau du document.

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

}

Autorisations

Voir aussi

Référence

Document, classe

Membres Document

Microsoft.Office.Tools.Word, espace de noms