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
Get
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。