Udostępnij za pośrednictwem


DocumentBase.XMLSchemaViolations Property

Definition

Gets a XMLNodes collection that represents all nodes in the document that have validation errors.

public:
 property Microsoft::Office::Interop::Word::XMLNodes ^ XMLSchemaViolations { Microsoft::Office::Interop::Word::XMLNodes ^ get(); };
public Microsoft.Office.Interop.Word.XMLNodes XMLSchemaViolations { get; }
member this.XMLSchemaViolations : Microsoft.Office.Interop.Word.XMLNodes
Public ReadOnly Property XMLSchemaViolations As XMLNodes

Property Value

A XMLNodes collection that represents all nodes in the document that have validation errors.

Examples

The following code example sets the value of each child node of the root element in the document to a string, and then displays the names of the nodes that have validation errors. For example, any node that maps to a schema element with an integer type will report a violation error. To use this example, run it from the ThisDocument class in a document-level project.

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 

Applies to