DocumentBase.XMLSchemaViolations 属性

获取一个 Microsoft.Office.Interop.Word.XMLNodes 集合,该集合表示文档中有验证错误的所有节点。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v4.0.Utilities(在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

语法

声明
Public ReadOnly Property XMLSchemaViolations As XMLNodes
public XMLNodes XMLSchemaViolations { get; }

属性值

类型:Microsoft.Office.Interop.Word.XMLNodes
一个 Microsoft.Office.Interop.Word.XMLNodes 集合,表示文档中有验证错误的所有节点。

示例

下面的代码示例将文档中根元素每个子节点的值设置为字符串,然后显示有验证错误的节点的名称。 例如,对于映射到整数类型架构元素的任何节点,都将报告冲突错误。 若要使用此示例,请从文档级项目内的 ThisDocument 类中运行此示例。

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

}

.NET Framework 安全性

请参见

参考

DocumentBase 类

Microsoft.Office.Tools.Word 命名空间