共用方式為


修改 XML 樹狀結構中的項目、屬性和節點

下表摘要說明您可以用於修改項目、其子項目或其屬性的方法和屬性。

下列方法會修改 XElement

方法

描述

XElement.Parse

以剖析的 XML 取代項目。

XElement.RemoveAll

移除項目的所有內容 (子節點和屬性)。

XElement.RemoveAttributes

移除項目的屬性。

XElement.ReplaceAll

取代項目的所有內容 (子節點和屬性)。

XElement.ReplaceAttributes

取代項目的屬性。

XElement.SetAttributeValue

設定屬性的值。 建立屬性 (如果不存在)。 如果值設定為 null,移除屬性。

XElement.SetElementValue

設定子項目的值。 建立項目 (如果不存在)。 如果值設定為 null,移除項目。

XElement.Value

以指定的文字取代項目的內容 (子節點)。

XElement.SetValue

設定項目的值。

下列方法會修改 XAttribute

方法

描述

XAttribute.Value

設定屬性的值。

XAttribute.SetValue

設定屬性的值。

下列方法會修改 XNode (包括 XElementXDocument)。

方法

描述

XNode.ReplaceWith

以新內容取代節點。

下列方法會修改 XContainer (XElementXDocument)。

方法

描述

XContainer.ReplaceNodes

以新的內容取代子節點。

請參閱

其他資源

修改 XML 樹狀結構 (LINQ to XML)