Adding Nodes to a Tree

In this section, you'll load the data from an XML tree and then dynamically add additional nodes to that tree. This operation would be done when there's additional code that will write the modified tree back to a database file.

To add nodes to a tree, first you must have a tree. So let's start with Listing 8.3, which will be your imported XML file.

Listing 8.3 An XML File That You'll Add Nodes To
 1: <?xml version="1.0"?> 2: <!-- This file has a small number of nodes and is being 3: used as the basis for the addition of nodes to the 4: node tree. --> 5: <Book xmlns:dt="urn:schemas-microsoft-com:datatypes"> 6: <Grade dt:dt="char">A</Grade> 7: <OneSignedInteger dt:dt="i1">12</OneSignedInteger> 8: <TwoSignedInteger dt:dt="i2">-12</TwoSignedInteger> ...

Get Sams Teach Yourself XML in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.