XObjectChange Enumeration
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Specifies the event type when an event is raised for an XObject.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
| Member name | Description | |
|---|---|---|
| Add | An XObject has been or will be added to an XContainer. | |
| Name | An XObject has been or will be renamed. | |
| Remove | An XObject has been or will be removed from an XContainer. | |
| Value | The value of an XObject has been or will be changed. In addition, a change in the serialization of an empty element (either from an empty tag to start/end tag pair or vice versa) raises this event. |
This enum specifies the event type when an event is raised for an XObject.
All operations that modify the XML tree break down to a series of primitives. There are four types of primitives. Two of the primitives (Add and Remove) act on collections. Two of them (Name and Value) act on instances. There is a corresponding event for each of these primitives.
You should be careful when modifying an XML tree within one of these events, because doing this might lead to unexpected results. For example, if you receive a Changing event, and while the event is being processed you remove the node from the tree, you might not receive the Changed event. When an event is being processed, it is valid to modify an XML tree other than the one that contains the node that is receiving the event; it is even valid to modify the same tree provided the modifications do not affect the specific nodes on which the event was raised. However, if you modify the area of the tree that contains the node receiving the event, the events that you receive and the impact to the tree are undefined.
The following example raises an event by adding an element to the tree.
StringBuilder output = new StringBuilder(); XElement root = new XElement("Root", "content"); root.Changing += (sender, e) => { output.Append("Changing event raised" + Environment.NewLine); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changing: " + e.ObjectChange + Environment.NewLine); }; root.Changed += (sender, e) => { output.Append("Changed event raised" + Environment.NewLine); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changed: " + e.ObjectChange + Environment.NewLine); }; root.Add(new XElement("Child", "child content")); OutputTextBlock.Text = output.ToString();
The following example raises an event by removing an element from the tree.
StringBuilder output = new StringBuilder(); XElement root = new XElement("Root", new XElement("Child", "content") ); root.Changing += (sender, e) => { output.Append("Changing event raised"); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changing: " + e.ObjectChange); }; root.Changed += (sender, e) => { output.Append("Changed event raised" + Environment.NewLine); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changed: " + e.ObjectChange + Environment.NewLine); }; root.Element("Child").Remove(); OutputTextBlock.Text = output.ToString();
The following example raises an event by changing the name of an element.
StringBuilder output = new StringBuilder(); XElement root = new XElement("Root", "content"); root.Changing += (sender, e) => { output.Append("Changing event raised"); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changing: " + e.ObjectChange); }; root.Changed += (sender, e) => { output.Append("Changed event raised" + Environment.NewLine); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changed: " + e.ObjectChange + Environment.NewLine); }; root.Name = "NewName"; OutputTextBlock.Text = output.ToString();
The following example raises an event by setting the value of an attribute.
StringBuilder output = new StringBuilder(); XElement root = new XElement("Root", new XAttribute("Att", "att value") ); root.Changing += (sender, e) => { output.Append("Changing event raised"); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changing: " + e.ObjectChange); }; root.Changed += (sender, e) => { output.Append("Changed event raised" + Environment.NewLine); output.Append(" Sender: " + sender.GetType() + Environment.NewLine); output.Append(" Changed: " + e.ObjectChange + Environment.NewLine); }; root.FirstAttribute.Value = "new contents"; OutputTextBlock.Text = output.ToString();