This topic explains how to create or modify a DOM tree by adding nodes and changing their contents.
The following diagram shows a sequence of calls that create a DOM tree from an empty document. There are many functions in the DOM Engine API that add nodes to a tree: refer to the reference documentation of the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]TXmlEngElement class for a comprehensive list.

Figure: Creating a DOM tree
Before you start, you must:
understand the concept of Document Object Model (DOM)
understand the structure and classes of the XML DOM Engine component
RXmlEngDocument myDoc;
_LIT8( KRootName, "playlist" ); TXmlEngElement root = myDoc->CreateDocumentElementL( KRootName );
_LIT8( KChildName, "song" );
_LIT8( KAttrName, "filename" );
for( TInt i=1;i<6;i++ )
{
TXmlEngElement tempElement = root.AddNewElementL( KChildName );
TBuf8<12> value( _L8( "music0" ) );
value.AppendNum( i );
value.Append( _L8( ".mp3" ) );
tempElement.AddNewAttributeL( KAttrName, value );
}
TXmlEngNode swap = root.FirstChild(); swap.MoveAfterSibling( swap.NextSibling() );
The result is a DOM tree corresponding to the following XML structure:
<playlist>
<song filename = "music02.mp3"/>
<song filename = "music01.mp3"/>
<song filename = "music03.mp3"/>
<song filename = "music04.mp3"/>
<song filename = "music05.mp3"/>
</playlist>