共用方式為


XPathNavigator.CanEdit 屬性

定義

取得值,指出 XPathNavigator 是否可以編輯底層 XML 資料。

public:
 virtual property bool CanEdit { bool get(); };
public virtual bool CanEdit { get; }
member this.CanEdit : bool
Public Overridable ReadOnly Property CanEdit As Boolean

屬性值

true XPathNavigator如果 可以編輯基礎 XML 資料,則為 ,否則為 false

範例

下列範例會 CanEdit 使用 屬性來顯示 CanEditXmlDocument 類別的值 XPathDocument

XPathDocument^ readOnlyDocument = gcnew XPathDocument("books.xml");
XPathNavigator^ readOnlyNavigator = readOnlyDocument->CreateNavigator();

XmlDocument^ editableDocument = gcnew XmlDocument();
editableDocument->Load("books.xml");
XPathNavigator^ editableNavigator = editableDocument->CreateNavigator();

Console::WriteLine("XPathNavigator.CanEdit from XPathDocument: {0}", readOnlyNavigator->CanEdit);
Console::WriteLine("XPathNavigator.CanEdit from XmlDocument: {0}", editableNavigator->CanEdit);
XPathDocument readOnlyDocument = new XPathDocument("books.xml");
XPathNavigator readOnlyNavigator = readOnlyDocument.CreateNavigator();

XmlDocument editableDocument = new XmlDocument();
editableDocument.Load("books.xml");
XPathNavigator editableNavigator = editableDocument.CreateNavigator();

Console.WriteLine("XPathNavigator.CanEdit from XPathDocument: {0}", readOnlyNavigator.CanEdit);
Console.WriteLine("XPathNavigator.CanEdit from XmlDocument: {0}", editableNavigator.CanEdit);
Dim readOnlyDocument As XPathDocument = New XPathDocument("books.xml")
Dim readOnlyNavigator As XPathNavigator = readOnlyDocument.CreateNavigator()

Dim editableDocument As XmlDocument = New XmlDocument()
editableDocument.Load("books.xml")
Dim editableNavigator As XPathNavigator = editableDocument.CreateNavigator()

Console.WriteLine("XPathNavigator.CanEdit from XPathDocument: {0}", readOnlyNavigator.CanEdit)
Console.WriteLine("XPathNavigator.CanEdit from XmlDocument: {0}", editableNavigator.CanEdit)

範例將 books.xml 檔案做為輸入。

<?xml version="1.0" encoding="utf-8" ?>   
<bookstore>  
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">  
        <title>The Autobiography of Benjamin Franklin</title>  
        <author>  
            <first-name>Benjamin</first-name>  
            <last-name>Franklin</last-name>  
        </author>  
        <price>8.99</price>  
    </book>  
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">  
        <title>The Confidence Man</title>  
        <author>  
            <first-name>Herman</first-name>  
            <last-name>Melville</last-name>  
        </author>  
        <price>11.99</price>  
    </book>  
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">  
        <title>The Gorgias</title>  
        <author>  
            <name>Plato</name>  
        </author>  
        <price>9.99</price>  
    </book>  
</bookstore>  

備註

屬性 CanEdit 根據 .NET 中介面的三個不同實作 IXPathNavigable ,有不同的值。 CanEdit下表列出每個實作 XPathNavigator 所建立物件的值。

IXPathNavigable 實作 CanEdit
XPathDocument false
XmlDocument true

適用於