O'Reilly logo

Microsoft® Visual J#™ .NET (Core Reference) by John/Longshaw, Andy Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing and Manipulating In-Memory XML Documents

One of the powerful features of the DOM is the ability to manipulate the XML document in memory. Let’s now look at how to add, remove, and alter information in the DOM tree and how to write out the contents of the DOM once they’ve been changed.

Altering Content in a DOM Tree

The simplest thing you can do to alter the contents of a DOM tree is to delete part of it. The RemoveChild method of the XmlNode class allows you to remove a child of a given node. This operation will also delete any nodes below the given child. For example, the following code removes the first Sizes element in a CakeCatalog node together with the Option elements below it:

XmlElement root = doc.get_DocumentElement(); XmlNodeList nodes = root.GetElementsByTagName("Sizes", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required