Updating an X-DOM
You can update elements and attributes in the following ways:
Call
SetValueor reassign theValueproperty.Call
SetElementValueorSetAttributeValue.Call one of the
RemoveXXXmethods.Call one the of the
AddXXXorReplaceXXXmethods, specifying fresh content.
You can also reassign the Name
property on XElement objects.
Simple Value Updates
Members | Works on |
|---|---|
| |
| |
The SetValue method replaces
an element or attribute’s content with a simple value. Setting the Value property does the same, but accepts
string data only. We describe both of these functions in detail later
(see the upcoming “Working with Values” section).
An effect of calling SetValue
(or reassigning Value ) is that it
replaces all child nodes:
XElement settings = new XElement ("settings",
new XElement ("timeout", 30)
);
settings.SetValue ("blah");
Console.WriteLine (settings.ToString( ));
// RESULT: <settings>blah</settings>Updating Child Nodes and Attributes
Category | Members | Works on |
|---|---|---|
Add | | |
| | |
Remove | | |
| | |
| | |
Update | | |
| | |
| | |
| | |
| |
The most convenient methods in this group are the last two:
SetElementValue ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access