diff -r 000000000000 -r 89d6a7a84779 Symbian3/SDK/Source/GUID-61056CE2-97BF-5D32-8AC5-E625FBC7D0EC.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-61056CE2-97BF-5D32-8AC5-E625FBC7D0EC.dita Thu Jan 21 18:18:20 2010 +0000 @@ -0,0 +1,80 @@ + + + + + +Modifying +DOM TreeThis topic explains how to create or modify a DOM tree by adding +nodes and changing their contents. +

Before you start, you must:

    +
  • understand the concept +of Document Object Model +(DOM)

  • +
  • understand the structure +and classes of the XML +DOM Engine component

  • +
+

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 TXmlEngElement class for a comprehensive +list.

+ Creating a DOM tree + +
+ + +Create an instance of RXmlEngDocument. +RXmlEngDocument myDoc; + + +Set the root node with the RXmlEngDocument::CreateDocumentElementL() function. +_LIT8( KRootName, "playlist" ); +TXmlEngElement root = myDoc->CreateDocumentElementL( KRootName ); + + +Add child nodes and attributes by calling the TXmlEngElement::AddNewElementL() and TXmlEngElement::AddNewAttributeL() functions. +_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 ); + } + + +Swap the first two song elements by calling the TXmlEngElement::MoveAfterSibling() function. +TXmlEngNode swap = root.FirstChild(); +swap.MoveAfterSibling( swap.NextSibling() ); + + +If you want to save the DOM tree into a file, call the XmlEnginePushL() method +first. +You must call the XmlEnginePushL() method +before parsing or saving an XML file, and the XmlEnginePopAndClose() method +after these operations. + + +

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> +
+
+Parsing XML +DOM +
\ No newline at end of file