SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 197 | Next

Scott Klein

"Professional LINQ"


112
Chapter 5: Understanding LINQ to XML
Insert
Content can be added to an XML tree easily by using one of the add methods available via the XNode
class, depending on where you want to insert the XML:
??‘ AddAfterSelf??”Adds the specified content after the current node.
??‘ AddBeforeSelf??”Adds the specified content before the current node.
The following code defines an initial XML tree, then uses the AddAfterSelf() method to add an
additional node after the State element.
XElement employee = new XElement("Root",
new XElement("Employee",
new XElement("Name", "Scott"),
new XElement("Address", "555 Main St."),
new XElement("City", "Wellington"),
new XElement("State", "FL")
)
);
XElement zip = employee.Element("Employee").Element("State");
zip.AddAfterSelf(new XElement("Zip","33414"));
Here??™s the resulting XML:


Scott
555 Main St.

Wellington
FL
33414


Notice that the element follows the element as you instructed.


Pages:
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6