epoc32/include/xmlengelement.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 xmlengelement.h
     1 /*
       
     2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:       Element node functions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #ifndef XMLENGINE_ELEMENT_H_INCLUDED
       
    25 #define XMLENGINE_ELEMENT_H_INCLUDED
       
    26 
       
    27 #include "XmlEngAttr.h"
       
    28 #include "XmlEngNamespace.h"
       
    29 
       
    30 template<class T> class RXmlEngNodeList;
       
    31 
       
    32 
       
    33 /**
       
    34  * Instance of TXmlEngElement class represents an XML element in the DOM tree.
       
    35  *
       
    36  * <b>Namespace handling:</b>
       
    37  *
       
    38  * Namespace of XML element is an URI that in pair with <i>local part</i> of
       
    39  * element's name consistute <b>expanded-name</b> of element. It is said that "the element
       
    40  * is of <i>NNN</i> namespace".
       
    41  *
       
    42  * XML elements are shown as belonging to a specific namespace by using <i>prefixes</i>
       
    43  * that previously were bound to some namespace URIs. The scope of a prefix is the
       
    44  * element, where it was declared and all its child (sub-)elements.
       
    45  *      
       
    46  * Namespace declaration is created by using special <b>xmlns:<i>{prefix-name}</i></b>
       
    47  * attribute (which is not really considered as attribute in DOM):
       
    48  * @code 
       
    49  *    <a xmlns:pr="http://some.uri.com/"> ... </a>
       
    50  * OR
       
    51  *    <pr:a xmlns:pr="http://some.uri.com/"> ... </a>
       
    52  *    <a xmlns="http://some.uri.com/"> ... </a>
       
    53  * @endcode
       
    54  *
       
    55  * The latter two examples are equivalent and show the use of <i>default namespace</i>.
       
    56  *    
       
    57  * Implementation notes:
       
    58  *	- Element having no namespace is either presented with a NULL TXmlEngNamespace node 
       
    59  *    or a TXmlEngNamespace node that has NULL prefix and namespace URI set to "". 
       
    60  *    The former is used by default on all nodes, whereas the latter is for cases
       
    61  *    when some node contains undeclaration of the default namespace:
       
    62  * @code
       
    63  *	   <a xmlns=""> .. </a>
       
    64  * @endcode
       
    65  *
       
    66  * - The prefix of the default attribute is NULL, not "" (zero-length string)
       
    67  *	 "" corresponds to  
       
    68  *   @code
       
    69  *       <a xmlns:="http://some.uri.com/"> ... </a>
       
    70  *   @endcode
       
    71  *   (it does not contradict XML spec, but you are strongly advised against using this)
       
    72  *
       
    73  * - Prefix <b>"xml"</b> is reserved by XML Namespace spec for special purposes; it is implicitly bound
       
    74  *   to XML's namespace <i>"http://www.w3.org/XML/1998/namespace"</i> and no one is allowed
       
    75  *   to use this prefix except as with spec-defined elements and attributes or to rebind this 
       
    76  *   prefix to other namespaces
       
    77  *
       
    78  * - Namespace URI may be "" only for default namespace. In other words,
       
    79  *   "" namespace URI may not be bound to non-NULL prefix. 
       
    80  *          
       
    81  *   Declaration of "" namespace with NULL prefix results in:
       
    82  *   @code
       
    83  *       <a xmlns=""> ... </a>
       
    84  *   @endcode
       
    85  *   which <i>undeclares</i> any existing (in some parent element) default namespace
       
    86  *   for the scope of element 'a': element, its attributes and all child nodes of DOM tree.
       
    87  *   Note, that such "undeclaration" will be added only if neccessary. 
       
    88  *        
       
    89  * - Unneccessary namespace declaration are ignored. Attemps to add namespace binding 
       
    90  *   using same namespace URI and prefix if such binding already exists in the scope
       
    91  *   will have no effect.
       
    92  *
       
    93  * - <b>IMPORTANT!</b> Attributes DO NOT HAVE default namespaces. If an attribute has no
       
    94  *   prefix, its namespace is <b>undeclared</b> even if there is some default namespaces for
       
    95  *   the scope of the element, which contains the attribute.
       
    96  *
       
    97  * So, it is wrong to write something like this:
       
    98  * @code
       
    99  *     <a xmlns="ns_uri"  attr="value"> ... </a>
       
   100  * @endcode
       
   101  * and assume that the <b>attr</b> belongs to namespace pointed to with <i>ns_uri</i>.
       
   102  *    
       
   103  * <b>HINTS:</b>
       
   104  * - Use namespace declaration nodes as much as possible (but watch out prefix collisions).
       
   105  * - Add most referred to namespace declarations (AddNamespaceDeclarationL(uri,pref)) after
       
   106  *   any other namespace declarations in a element -- the will be found faster in
       
   107  *   namespace lookups.
       
   108  *
       
   109  * @lib XmlEngineDOM.lib
       
   110  * @since S60 v3.1
       
   111  */
       
   112 
       
   113 class TXmlEngElement : public TXmlEngNode
       
   114 {
       
   115   public:
       
   116     /**
       
   117      * Default constructor for automatic variables (not initialized)
       
   118 	 *
       
   119      * @since S60 v3.1
       
   120 	 */
       
   121     inline TXmlEngElement();
       
   122 
       
   123     /**
       
   124      * Constructor
       
   125      *
       
   126      * @since S60 v3.1
       
   127 	 * @param aInternal element pointer
       
   128 	 */
       
   129     inline TXmlEngElement(void* aInternal);
       
   130 	
       
   131     /** 
       
   132     *    @name XmlEngine's non-DOM extensions
       
   133     */
       
   134     /** @{ */
       
   135 
       
   136     /**
       
   137      *   Retrieves list of attribute nodes of the element
       
   138      *   
       
   139      *   @param aList - a node list object to initialize
       
   140      *
       
   141      *   Passed by reference list of nodes is initialized and after call to
       
   142      *   Attributes(..) is ready for use with HasNext() and Next() methods:
       
   143      *
       
   144      *   @code
       
   145      *       ...
       
   146      *       TXmlEngElement root = doc.DocumentElement();
       
   147      *       RXmlEngNodeList<TXmlEngAttr>    attlist;
       
   148      *       root.GetAttributes(attlist);
       
   149      *       while (attlist.HasNext())
       
   150      *           processAttribute(attlist.Next());
       
   151      *       ...
       
   152 	 *       attlist.Close();
       
   153      *   @endcode
       
   154 	 *
       
   155      * @since S60 v3.1
       
   156 	 */
       
   157     IMPORT_C void GetAttributes(RXmlEngNodeList<TXmlEngAttr>& aList) const;
       
   158 
       
   159     /**
       
   160      * Retrieves list of child elements of the element
       
   161      *
       
   162      * @since S60 v3.1
       
   163 	 * @param aList - a node list object to initialize
       
   164      *
       
   165      * Passed by reference list of nodes is initialized and after the call
       
   166      * it is ready for use with HasNext() and Next() methods:
       
   167      *   
       
   168      * @note Returned list is a "filtered view" of the underlying
       
   169      *       list of all element's children (with text nodes, comments
       
   170      *       processing instructions, etc.)
       
   171 	 */ 
       
   172     IMPORT_C void GetChildElements(RXmlEngNodeList<TXmlEngElement>& aList) const;
       
   173 
       
   174     /**
       
   175      * Creates new attribute node out of any namespace (i.e. it has no prefix),
       
   176      * sets attribute's value and links it as the last attribute of the current element
       
   177      *
       
   178      * @since S60 v3.1
       
   179 	 * @param  aName   A local name of attribute
       
   180      * @param  aValue  Value to set for new attribute or NULL (sets value to "")
       
   181      * @return         A handler to the newly created attribute node;
       
   182      *
       
   183      * For adding attribute as the first one, use TXmlEngNode::SetAsFirstSibling() on the attribute:
       
   184      * @code
       
   185      *     TXmlEngElement el = ... ; // get some element
       
   186      *     el.AddNewAttributeL("version","0.1").SetAsFirstSibling();
       
   187      * @endcode
       
   188      *   
       
   189      * @see   SetAsLastSibling(), MoveBeforeSibling(TXmlEngNode) and MoveAfterSibling(TXmlEngNode)
       
   190      *
       
   191      * @note   - No checks are made that attribute with such name exists
       
   192      *           Use this method only on newly created elements!
       
   193      *           Otherwise, use TXmlEngElement::SetAttributeL(..)
       
   194      *         - Attributes do not inherit default namespace of its element
       
   195      *           (http://w3.org/TR/REC-xml-names/#defaulting)
       
   196      *         - attribute's value is the second argument in all AddNewAttributeL(..) methods
       
   197      *         - Use of NULL as value is more preferrable then "" 
       
   198 	 */
       
   199     IMPORT_C TXmlEngAttr AddNewAttributeL(const TDesC8& aName, const TDesC8& aValue);
       
   200     
       
   201     /**
       
   202      * Creates new attribute node and add it to the element
       
   203      *
       
   204      * Provided handle to namespace declaration is used to set up
       
   205      * attribute's namespace.
       
   206      *
       
   207      * @since S60 v3.1
       
   208 	 * @param  aName   A local name of attribute
       
   209      * @param  aValue  Value to set for new attribute or NULL (sets value to "")
       
   210      * @param  aNsDef  Namespace to add to the attribute
       
   211      * @return         A handler to the newly created attribute node;
       
   212      *
       
   213      * @note If aNsDef is not defined in some of attributes ascendants
       
   214      *      (including this element), then
       
   215      *      ReconcileNamespacesL() method must be called on
       
   216      *      this element later.
       
   217 	 */
       
   218     IMPORT_C TXmlEngAttr AddNewAttributeL(const TDesC8& aName,
       
   219                                     const TDesC8& aValue, 
       
   220                                     const TXmlEngNamespace aNsDef);
       
   221 
       
   222     /**
       
   223      * Creates new attribute on the element. Namespace declaration for the attribute namespace is
       
   224      * created too.
       
   225      *
       
   226      * @since S60 v3.1
       
   227 	 * @param  aName   A local name of attribute
       
   228      * @param  aValue  Value to set for new attribute or NULL (sets value to "")
       
   229      * @param  aNsUri  Namespace uri
       
   230      * @param  aPrefix  Namespace prefix
       
   231      * @return         A handler to the newly created attribute node;
       
   232      *
       
   233      * @note
       
   234      *    - Namespace declarations are reused if possible (no redundant ones are created)
       
   235      */
       
   236     IMPORT_C TXmlEngAttr AddNewAttributeL(const TDesC8& aName, 
       
   237                                     const TDesC8& aValue,
       
   238                                     const TDesC8& aNsUri, 
       
   239                                     const TDesC8& aPrefix);
       
   240 
       
   241     /**
       
   242      * Creates new attribute node using namespace of its parent element (this element),
       
   243      * sets attribute's value and links it as the last attribute of the element
       
   244      *
       
   245      * @since S60 v3.1
       
   246 	 * @param aName Local name of attribute 
       
   247      * @param aValue Value to set for new attribute or NULL (sets value to "")
       
   248      * @return A handler to the newly created attribute node;
       
   249      *    
       
   250      * For more hints how to use it refer to AddNewAttributeL(const TDesC8&,const TDesC8&)
       
   251      *        
       
   252      * @note    
       
   253      *     - No checks are made that attribute with such name exists
       
   254      *     - if namespace of the parent element is default (i.e. bound prefix is NULL),
       
   255      *       then temporary prefix will be used and bound to the same namespace URI as elements
       
   256      *       (It is due to the fact that default namespaces do not spread on unprefixed attributes,
       
   257      *       see http://w3.org/TR/REC-xml-names/#defaulting)
       
   258      */
       
   259     inline   TXmlEngAttr AddNewAttributeSameNsL(const TDesC8& aName, const TDesC8& aValue);
       
   260 
       
   261     /**
       
   262      * Creates new attributes using namespace, which is bound to the specified prefix
       
   263      *
       
   264      * @since S60 v3.1
       
   265 	 * @param  aLocalName   A local name of attribute
       
   266      * @param  aValue  Value to set for new attribute or NULL (sets value to "")
       
   267      * @param  aPrefix  Namespace prefix for new attribute
       
   268      * @return A handler to the newly created attribute node;
       
   269      *
       
   270      * Use this mothod only for construction of new parts of DOM tree, where
       
   271      * you know for sure that prefix is bound in the given scope.
       
   272      * @code
       
   273      *     TXmlEngElement el = parent.AddNewAttributeUsePrefixL("property","ObjName","rdf");
       
   274      *     el.AddNewAttributeUsePrefixL("type", "xs:integer", "rdf");
       
   275      * @endcode
       
   276      *
       
   277      * Otherwise, you should check that prefix is bound like this example shows:
       
   278      * @code
       
   279      *     TXmlEngNamespace boundNS = TXmlEngNamespace::LookupByPrefix(thisElement, prefix);
       
   280      *     if (boundNS.NotNull()){
       
   281      *         thisElement.AddNewAttributeUsePrefixL("name", value, prefix);
       
   282      *     }
       
   283      * @endcode
       
   284      *
       
   285      * @note
       
   286      *     Use AddNewAttributeNsL(name,value,nsDefNode) as much as you can, because
       
   287      *     it is most efficient way to create namespaced DOM elements (no additional
       
   288      *     lookups for namespace declarations are required).
       
   289      *  
       
   290      * @code
       
   291      *     // If namespace with given URI is not in the scope, then it will be declared
       
   292      *     // and bound to "data" prefix.
       
   293      *     TXmlEngNamespace nsDef = elem.FindOrCreateNsDefL("http://../Data", "data");
       
   294      *     elem.AddNewAttributeL("location", "...", nsDef);
       
   295      *     elem.AddNewElementL("child", nsDef).AddNewAttributeL("attr","...value...");
       
   296      *     // the result is
       
   297      *         ...
       
   298      *      <elem xmlns:data="http://../Data" data:location="...">
       
   299      *         <data:child attr="...value..."/>
       
   300      *      </elem>
       
   301      *         ...
       
   302      *     //
       
   303      * @endcode    
       
   304      */
       
   305     IMPORT_C TXmlEngAttr AddNewAttributeUsePrefixL(const TDesC8& aLocalName, 
       
   306                                              const TDesC8& aValue, 
       
   307                                              const TDesC8& aPrefix);
       
   308 
       
   309     /**
       
   310      * Creates new attributes using namespace in the scope, which has specified URI
       
   311      *   
       
   312      * Almost the same as AddNewAttributeUsePrefixL(...) but does lookup by namespace URI
       
   313      *
       
   314      * @since S60 v3.1
       
   315 	 * @param  aLocalName   A local name of attribute
       
   316      * @param  aValue  Value to set for new attribute or NULL (sets value to "")
       
   317      * @param  aNsUri  Namespace uri for new attribute
       
   318      * @return - NULL attribute if namespace declaration is not found OR newly added to the end of
       
   319      *           attribute list attribute of this element.
       
   320      *
       
   321      * @see AddNewAttributeUsePrefixL(const TDesC8&,const TDesC8&,const TDesC8&)
       
   322      */
       
   323     IMPORT_C TXmlEngAttr AddNewAttributeWithNsL(const TDesC8& aLocalName, 
       
   324                                           const TDesC8& aValue, 
       
   325                                           const TDesC8& aNsUri);
       
   326                                           
       
   327     /**
       
   328      * Add attribute to element that will be used as Xml:Id.
       
   329      *
       
   330      * No check if such attribute exists are made.
       
   331      * 
       
   332      * @since S60 v3.2
       
   333 	 * @param aLocalName Name of attribute that should be add.
       
   334 	 * @param aValue Value of the attribute
       
   335 	 * @param aNs Namespace of the attribute
       
   336 	 * @return Attribute if created. Null attribute if Id exist
       
   337      *
       
   338      * @note Call RXmlEngDocument.RegisterXmlIdL(aName,aNsUri) first
       
   339      *       to register existed id's in the document.
       
   340      */
       
   341     IMPORT_C TXmlEngAttr AddXmlIdL(const TDesC8& aLocalName,
       
   342                                        const TDesC8& aValue,
       
   343                                        TXmlEngNamespace aNs = TXmlEngNamespace());
       
   344     
       
   345     /**
       
   346      * Adds child element with no namespace
       
   347      *
       
   348      * @since S60 v3.1
       
   349 	 * @param aName name of the element
       
   350      * @return A handler to the newly created element node;
       
   351      *
       
   352      * Results in adding element with aName and no prefix.
       
   353      *
       
   354      * This method is the best for creation of non-namespace based documents
       
   355      * or document fragments, where no default namespace declared.
       
   356      *
       
   357      * It may be used also as a method for adding element from default namespace,
       
   358      * BUT namespace will be assigned ONLY after serialization of the current
       
   359      * document and parsing it back into a DOM tree!! If you need that default namespace
       
   360      * was inherited by new element immediately use:
       
   361      * @code
       
   362      *    ...
       
   363      *    TXmlEngNamespace defns = element.DefaultNamespace();
       
   364      *    TXmlEngElement newEl = element.AddNewElementL("Name",defns);
       
   365      *    ...
       
   366      * @endcode
       
   367      *
       
   368      * If truly undefined namespace for the element is required, then <b>DO NOT USE</b>
       
   369      * this method if there is a default namespace in the scope!
       
   370      */
       
   371     IMPORT_C TXmlEngElement AddNewElementL(const TDesC8& aName);
       
   372 
       
   373     /**
       
   374      * Creates new child element with provided name and namespace declaration
       
   375      *
       
   376      * @since S60 v3.1
       
   377 	 * @param aLocalName Name of the element
       
   378      * @param aNsDecl Handle of the namespace declaration, that must be retrieved from
       
   379      *            one of the ascendant nodes of the new elements (and its prefix
       
   380      *            should not be remapped to another namespace URI for the scope
       
   381      *            of the new element)
       
   382      * @return    Created element node (and added as the last child of its parent)
       
   383      */
       
   384     IMPORT_C TXmlEngElement AddNewElementL(const TDesC8& aLocalName, TXmlEngNamespace aNsDecl);
       
   385 
       
   386     /**
       
   387      * Creates new child element with provided name, prefix and namespace URI
       
   388      *
       
   389      * New namespace declaration will be attached to the parent (this) element and used
       
   390      * as namespace for newly created child element. If such binding already exists
       
   391      * (same prefix is bound to same URI), it will be reused. If the prefix is already
       
   392      * bound to some another namespace URI, it will be rebound by the new namespace
       
   393      * declaration node.
       
   394      *
       
   395      * @since S60 v3.1
       
   396 	 * @param aLocalName Name of the element
       
   397      * @param aNsUri     URI of element's namespace
       
   398      * @param aPrefix    Prefix of the element
       
   399      * @return Created element node (and added as the last child of its parent)
       
   400      */
       
   401     IMPORT_C TXmlEngElement AddNewElementL(const TDesC8& aLocalName, 
       
   402                                      const TDesC8& aNsUri, 
       
   403                                      const TDesC8& aPrefix);
       
   404 
       
   405     /**
       
   406      * Adds child element with same namespace (and prefix if present) as parent element has
       
   407      *
       
   408      * @since S60 v3.1
       
   409 	 * @param aLocalName element's name
       
   410      * @return New element that was added to the end of children list of its parent (this element)
       
   411      */
       
   412     IMPORT_C TXmlEngElement AddNewElementSameNsL(const TDesC8& aLocalName);
       
   413 
       
   414     /**
       
   415      * Performs lookup for the namespace declaration for specified prefix and
       
   416      * adds new child element with found namespace.
       
   417      *
       
   418      * The assumption is that prefix is bound, otherwise run-time error
       
   419      * (Symbian's Leave or exception) occurs
       
   420      *
       
   421      * @note   Use this method only if there is a binding for the given prefix.
       
   422      *
       
   423      * @since S60 v3.1
       
   424 	 * @param aLocalName element's name
       
   425      * @param aPrefix    prefix to use
       
   426      * @return new TXmlEngElement that was added to the end of children list of its parent (this element)
       
   427      */
       
   428     IMPORT_C TXmlEngElement AddNewElementUsePrefixL(const TDesC8& aLocalName, const TDesC8& aPrefix);
       
   429 
       
   430     /**
       
   431      * Performs lookup for the namespace declaration for specified namespace URI and
       
   432      * adds new child element with found namespace.
       
   433      *
       
   434      * The assumption is that namespace with given URI was declared,
       
   435      * otherwise run-time error (Symbian' Leave or exception) occurs
       
   436      * 
       
   437      * @note Use this method only if namespace declaration for the provided URI exists.
       
   438      *
       
   439      * @since S60 v3.1
       
   440 	 * @param aLocalName    element's name
       
   441      * @param aNsUri        namespace of element
       
   442      * @return new TXmlEngElement that was added to the end of children list of its parent (this element)
       
   443      */
       
   444     IMPORT_C TXmlEngElement AddNewElementWithNsL(const TDesC8& aLocalName, const TDesC8& aNsUri);
       
   445 
       
   446     /**
       
   447      * Creates new child element; if there is no a prefix binding for new element's namespace,
       
   448      * a namespace decaration is created with generated prefix at specified element.
       
   449      *
       
   450      * @since S60 v3.1
       
   451 	 * @param aLocalName    Name of the element to create
       
   452      * @param aNsUri        Namespace URI of the new element
       
   453      * @param aNsDeclTarget An element where namespace declaraton should be placed
       
   454      *                     if there is a needed to create new namespace declaration;
       
   455      *                     NULL is used to specify the created element itself
       
   456      *
       
   457      * As aNsDeclTarget any ascendant of the new node may be provided:
       
   458      * @code
       
   459      *     el.AddNewElementAutoPrefixL(tagName,uri,NULL); // declare on the new element
       
   460      *     el.AddNewElementAutoPrefixL(tagName,uri,el);   // declare on the parent element
       
   461      *     el.AddNewElementAutoPrefixL(tagName,uri,doc.DocumentElement()); // declare on the root element
       
   462      *    ...
       
   463      * @endcode
       
   464      *
       
   465      * @note
       
   466      *  The farther namespace declaration up in the document tree,
       
   467      *  the longer time namespace declaration lookups take.
       
   468      */
       
   469     IMPORT_C TXmlEngElement AddNewElementAutoPrefixL(const TDesC8& aLocalName, 
       
   470                                                const TDesC8& aNsUri, 
       
   471                                                TXmlEngElement aNsDeclTarget);
       
   472 
       
   473     /**
       
   474      * Get element content.
       
   475      * This method may be used in most cases, when element has only simple text content
       
   476      * (without entity references embedded).
       
   477      * If element's contents is mixed (other types of nodes present), only contents of
       
   478      * first child node is returned if it is a TXmlEngTextNode node. For getting mixed contents of the
       
   479      * element of contents with entity references, WholeTextValueCopyL() should be used.
       
   480      *
       
   481      * @since S60 v3.1
       
   482 	 * @return Basic contents of the element
       
   483      * 
       
   484      * @see TXmlEngNode::WholeTextContentsCopyL()
       
   485      */
       
   486     IMPORT_C TPtrC8 Text() const;
       
   487 
       
   488     /**
       
   489      * Adds text as a child of the element.
       
   490      *
       
   491      * @since S60 v3.1
       
   492 	 * @param aString text to be added as element's content.
       
   493      * 
       
   494      * @note There may be several TXmlEngTextNode and TXmlEngEntityReference nodes added actually,
       
   495      *   depending on the aString value
       
   496      */
       
   497     IMPORT_C void  AddTextL(const TDesC8& aString);
       
   498 
       
   499     /**
       
   500      * Sets text contents for the element.
       
   501      * Any child nodes are removed.
       
   502      * Same as TXmlEngNode::SetValueL(TDesC8&)
       
   503      *
       
   504      * @since S60 v3.1
       
   505 	 * @param aString text to be set as element's content.
       
   506      *
       
   507      * @see TXmlEngNode::SetValueL(TDesC8&)
       
   508      */
       
   509     IMPORT_C void  SetTextL(const TDesC8& aString);
       
   510 
       
   511     /**
       
   512      * Sets text content of the element from escaped string.
       
   513      *
       
   514      * @since S60 v3.1
       
   515 	 * @param aEscapedString New value
       
   516      *
       
   517      * @see TXmlEngAttr::SetEscapedValueL(TDesC8&)
       
   518      */
       
   519     IMPORT_C void  SetEscapedTextL(const TDesC8& aEscapedString);
       
   520     
       
   521     /**
       
   522      * Sets new element value exactly as presented in the string.
       
   523 	 * Predefined entities are not converted into characters they represent.
       
   524 	 * Any child nodes are removed.     
       
   525      *
       
   526      * @since S60 v3.2
       
   527 	 * @param aNotEncText New element value
       
   528      *
       
   529      * @see TXmlEngAttr::SetValueNoEncL(const TDesC8& aNewValue); 
       
   530      */    
       
   531     IMPORT_C void SetTextNoEncL(const TDesC8& aNotEncString);
       
   532 
       
   533     /**
       
   534      * Appends new text node with the value exactly as presented in the string.
       
   535 	 * Predefined entities are not converted into characters they represent.
       
   536 	 * Existing child nodes are not removed.    
       
   537      *
       
   538      * @since S60 v3.2
       
   539 	 * @param aNotEncText Appended element value
       
   540      *
       
   541      * @see TXmlEngAttr::SetValueNoEncL(const TDesC8& aNewValue); 
       
   542      */  
       
   543 	IMPORT_C void AppendTextNoEncL(const TDesC8& aNotEncString);   
       
   544 
       
   545     /**
       
   546      * Adds namespace declaration to the current element, a binding of prefix to namespace URI.
       
   547      * 
       
   548      * If same namespace declaration exists (same prefix and URI), redundant namespace declaration
       
   549      * will not be created.
       
   550      * 
       
   551      * Both NULL or "" (empty string) may be used for "UNDEFINED URI" and "NO PREFIX" values of arguments. 
       
   552      *
       
   553      * @since S60 v3.1
       
   554 	 * @param aNsUri Namespace URI
       
   555      * @param aPrefix Namespace prefix
       
   556      * @return  A handle to the created (or found, if there is such) namespace declaration node.
       
   557      *          If namespace undeclaration is being created, NULL handle is returned -- it can be
       
   558      *           used in node-creation methods that take namespace handle as an argument.
       
   559      * 
       
   560      * @note   Undeclaring of default namespace (xmlns="") is supported by
       
   561      *         SetNoDefaultNamespace() method
       
   562      * 
       
   563      * @see SetNoDefaulNamespace()
       
   564      * 
       
   565      * @note   By adding namespace declaration that rebinds prefix mapping (or default namespace)
       
   566      *         used by nodes lower in the tree, document tree may become
       
   567      *         wrongly constructed, because references to namespace declaration are
       
   568      *         not updated. However, after serialization the document will have
       
   569      *         desired structure.
       
   570      *         Use this method with care!
       
   571      */ 
       
   572     IMPORT_C TXmlEngNamespace AddNamespaceDeclarationL(const TDesC8& aNsUri, const TDesC8& aPrefix);
       
   573 
       
   574     /**
       
   575      * Adds default namespace declaration.
       
   576      *
       
   577      * @since S60 v3.1
       
   578 	 * @param aNsUri   Namespace URI;  both NULL and "" (empty string) are allowed to represent UNDEFINED NAMSPACE
       
   579      * @return    Handle to the created namespace declaration (NULL for UNDEFINED NAMESPACE)
       
   580      *
       
   581      * Same result as with AddNamespaceDeclarationL(aNsUri, NULL), but additionally
       
   582      * element's namespace modified (if it has no prefix and there were no default
       
   583      * namespace declaration in the scope) to the new default one.
       
   584      */
       
   585     IMPORT_C TXmlEngNamespace SetDefaultNamespaceL(const TDesC8& aNsUri);
       
   586 
       
   587     /**
       
   588      * Undeclares any default namespace for current element and its descendants.
       
   589      * 
       
   590      * If there is already some default namespace,  <i>xmlns=""</i> namespace
       
   591      * declaration is added. Otherwise, nothing happens, since element with no
       
   592      * prefix in such scope is automaticaly considered as out of any namespace.
       
   593      * 
       
   594      * The side effect of this method is that namespace of the current element
       
   595      * may change from previous <b>default</b> namespace to NULL TXmlEngNamespace, which is
       
   596      * considered an absence of namespace.
       
   597      * 
       
   598      * If the element has prefix (i.e. not having default namespace), 
       
   599      * then the only effect for the element is undeclaration of existing default namespace. 
       
   600      * 
       
   601      * If element is in the scope of another <i>xmlns=""</i> undeclaration, no
       
   602      * actions are taken.
       
   603      * 
       
   604      * @note
       
   605      *     Use AddNamespaceDeclarationL(NULL,NULL) to force creation of
       
   606      *     xmlns=""  declaration within scope of another such declaration 
       
   607      *     (otherwise unneccessary/duplicate declarations are not created)
       
   608      * 
       
   609      * @note
       
   610      *     This method should be called on elements before adding children,
       
   611      *     because default namespace undeclaration is not spread into its subtree and 
       
   612      *     descedants' default namespaces are not reset to NULL. This should be taken into 
       
   613      *     account if later some processing on the subtree occurs.
       
   614      *     However, after serialization and deserialization, undeclared default namespace will
       
   615      *     affect whole element's subtree correctly.
       
   616      *
       
   617      * @since S60 v3.1
       
   618 	 */
       
   619     IMPORT_C void SetNoDefaultNamespaceL();
       
   620 
       
   621     /**
       
   622      * Finds namespace declaration that has specific prefix in the scope for given node
       
   623      *
       
   624      * Prefix "" or NULL are considered the same, meaning "<b>NO PREFIX</b>".
       
   625      * If namespace declaration for "no prefix" is searched, then default namespace is returned. 
       
   626      *
       
   627      * @since S60 v3.1
       
   628 	 * @param aPrefix Namespace prefix
       
   629      * @return Namespace handler, which may be NULL if prefix is not bound.
       
   630      * 
       
   631      * NULL result for "no prefix" means that default namespace is undefined.
       
   632      */
       
   633     IMPORT_C TXmlEngNamespace LookupNamespaceByPrefixL(const TDesC8& aPrefix) const;
       
   634 
       
   635     /**
       
   636      * Finds namespace declaration that has specific namespace URI
       
   637      * in the scope for the given node.
       
   638      *
       
   639      * @since S60 v3.1
       
   640 	 * @param aUri  Namespace URI, for which namespace declaration is searched
       
   641      * @return Handler to the namespace declaration that binds given namespace URI to some prefix 
       
   642      *          or sets it a default namespace.
       
   643      * 
       
   644      * NULL value of aUri is equivalent to "" and means "<b>UNDEFINED NAMESPACE</b>". 
       
   645      * For such URI  a NULL namespace handle is always returned even if there is
       
   646      * namespace undeclaration, which has "" URI (and NULL prefix).
       
   647      * 
       
   648      * <b>Hint:</b><p>
       
   649      * Use returned instance of TXmlEngNamespace as aNsDef argument to element's methods
       
   650      * that create new element's child elements and attributes. The same handler
       
   651      * may be used on more deep descentants of the reference element (and doing
       
   652      * this way will generally increase performance of DOM tree construction).<br />
       
   653      * <span class="color:red;">However</span>, if namespace bindings are not controlled
       
   654      * for element's children and prefix, which is bound to the search namespace, is
       
   655      * rebound to some other namespace URI, then reusing namespace may lead to
       
   656      * unwanted result.
       
   657      * 
       
   658      * Consider an example:
       
   659      * @code
       
   660      *     TXmlEngElement root = doc.DocumentElement();
       
   661      *     TXmlEngNamespace targetNs = root.AddNamespaceDeclarationL("http://example.com/","ex");
       
   662      *     TXmlEngElement el_1 = root.AddNewElementL("outer", targetNs);
       
   663      *     TXmlEngElement el_2 = el_1.AddNewElementL("inner"); // element without prefix
       
   664      * 
       
   665      *     // NOTE: prefix "ex" is not bound to "http://example.com/" anymore!
       
   666      *     el_2.AddNamespaceDeclarationL("http://whatever.com/","ex");
       
   667      *     TXmlEngElement el_3 = el_2.AddNewElementL("problem", targetNs);
       
   668      *     ...
       
   669      * @endcode
       
   670      * 
       
   671      * The sought result was (showing expanded names of elements):
       
   672      * @code
       
   673      *     --> "root"
       
   674      *         --> {"http://example.com/","outer"}
       
   675      *         --> "inner"
       
   676      *             -->{"http://example.com/","problem"}
       
   677      *                 ...
       
   678      *             <--
       
   679      *         <-- "inner"
       
   680      *         <-- {"http://example.com/","outer"}
       
   681      *         ...
       
   682      *     <-- </root>
       
   683      * @endcode
       
   684      * and it may look that it has been achieved. Indeed, if namespace of element "problem"
       
   685      * was queried, it would have URI "http://example.com/" and prefix "ex".
       
   686      * However, if namespace URI was looked up by "problem"'s prefix, it would be
       
   687      * "http://whatever.com/". We have created illegal DOM tree.
       
   688      * 
       
   689      * The actual DOM tree in serialized form will be:
       
   690      * @code
       
   691      *     <root>
       
   692      *         <ex:outer xmlns:ex="http://example.com/">
       
   693      *             <inner xmlns:ex="http://whatever.com/">
       
   694      *                 <ex:problem>
       
   695      *                 ...
       
   696      *                 </ex:problem>
       
   697      *             </inner>
       
   698      *         </ex:outer>
       
   699      *         ...
       
   700      *     </root>
       
   701      * @endcode
       
   702      * 
       
   703      * So, reuse of namespace handlers should be performed with special care.
       
   704      * 
       
   705      * @note
       
   706      * At the moment it is possible to retrieve namespace declaration nodes
       
   707      * whose prefixes were rebound. Be careful when use returned TXmlEngNamespace object
       
   708      * for creation of new elements. In later releases, this method will perform
       
   709      * safe lookup. And so far, it is better to make check that prefix of returned
       
   710      * namespace declaration has not rebound:
       
   711      * @code
       
   712      *     TXmlEngNamespace ns = element.LookupNamespaceByUri("a_uri");
       
   713      *     if (element.LookupNamespaceByPrefix(ns.Prefix()).IsSameNode(ns)){
       
   714      *         ... // now it is safe to create new elements by using "ns"
       
   715      *         element.AddNewElementL("product",ns);
       
   716      *         ...
       
   717      *     }
       
   718      * @endcode
       
   719      */
       
   720     IMPORT_C TXmlEngNamespace LookupNamespaceByUriL(const TDesC8& aUri) const;
       
   721 
       
   722     /**
       
   723      * Retrieves implicitly declared on every XML infoset binding
       
   724      * of 'xml' prefix to XML's namespace URI:
       
   725      * "http://www.w3.org/XML/1998/namespace"
       
   726      *
       
   727      * @since S60 v3.1
       
   728 	 * @return Handler to {xml,"http://www.w3.org/XML/1998/namespace"} prefix
       
   729      *            binding in the current document
       
   730      *
       
   731      * The result should be used for creating attributes beloging to the XML namespace
       
   732      * (xml:lang, xml:space, xml:id , etc.)
       
   733      *
       
   734      * DO NOT USE methods LookupNamespaceByUriL(const TDesC8&) and LookupNamespaceByPrefixL(const TDesC8&)
       
   735      * (with "http://www.w3.org/XML/1998/namespace" and "xml" arguments) for retrieving
       
   736      * namespace node, since in a case of [possible] memory allocation fault
       
   737      * NULL result is returned (and breaks your program silently)
       
   738      * 
       
   739      * @note   Normally 'xml' prefix is bound to XML namespace URI in the document
       
   740      *        node, BUT if current node is not a part of the document tree yet,
       
   741      *        the requested namespace declaration WILL BE ADDED to the current node.
       
   742      *        This is the reason why the method may fail in OOM conditions.
       
   743      */
       
   744     IMPORT_C TXmlEngNamespace TheXMLNamespaceL() const;
       
   745 
       
   746     /**
       
   747      * Get default namespace for element.
       
   748      *
       
   749      * @since S60 v3.1
       
   750 	 * @return Default namespace in the scope of the element
       
   751      *
       
   752      * NULL TXmlEngNamespace means that element with no prefix have no namespace associated
       
   753      * because no default namespace was declared or default namespace was undeclared with <b>xmlns=""</b>
       
   754      *
       
   755      * Equivalent to LookupNamespaceByPrefixL(const TDesC8&) with NULL (or "") prefix provided
       
   756      */
       
   757     inline   TXmlEngNamespace DefaultNamespaceL() const;
       
   758 
       
   759     /**
       
   760      * Performs search of namespace handler in the scope of the element. This method will
       
   761      * create new namespace declaration on the element if such namespace is not available.
       
   762      *
       
   763      * @since S60 v3.1
       
   764 	 * @param aNsUri   Searched namespace
       
   765      * @param aPrefix  Prefix to use for <b>new</b> namespace declaration (if it is to be created)
       
   766      * @return    TXmlEngNamespace handler that may be used to create new attributes and child elements of
       
   767      *            the element. The namespace may be one of those existed previously or was created
       
   768      *
       
   769      * @note
       
   770      *    Be sure not to use the result of this method for non-descendants of the element or in situations
       
   771      *    when prefix overlapping might occur (read also about general general considerations of attributes
       
   772      *    and elements creation using namespace handlers)
       
   773      */
       
   774     IMPORT_C TXmlEngNamespace FindOrCreateNsDeclL(const TDesC8& aNsUri, const TDesC8& aPrefix);
       
   775 
       
   776     /**
       
   777      * Performs search on the element and its ascendants for any namespace declaration
       
   778      * with given URI and create a new namespace declaration with some (unique) prefix
       
   779      * if the search was not successful.
       
   780      *
       
   781      * @since S60 v3.1
       
   782 	 * @param aNsUri   Searched namespace
       
   783      * @return    TXmlEngNamespace handler that may be used to create new attributes and child elements of
       
   784      *            the element. The namespace may be one of those existed previously or was created
       
   785      */
       
   786     IMPORT_C TXmlEngNamespace FindOrCreateNsDeclL(const TDesC8& aNsUri);
       
   787 
       
   788     /**
       
   789      * Checks whether a prefix has been bound in this element (not in one of its ascendants)
       
   790      * 
       
   791      * Use this method for preventig prefix-name collision in a element node
       
   792      *
       
   793      * @since S60 v3.1
       
   794 	 * @param aPrefix Namespace prefix
       
   795      * @return TRUE if there is already namespace declaration that uses aPrefix on this element
       
   796      */
       
   797     IMPORT_C TBool HasNsDeclarationForPrefixL(const TDesC8& aPrefix) const;
       
   798     
       
   799     /**
       
   800      * Copies the element with its attributes, but not child nodes
       
   801      * 
       
   802      * If context is preserved, then all namespace declarations that are in the element are
       
   803      * writen to element's start tag too.
       
   804      *
       
   805      * @since S60 v3.1
       
   806 	 * @param preserveNsContext TRUE if context should be preserved
       
   807      * @return handle to copy of element
       
   808      */
       
   809     IMPORT_C TXmlEngElement ElementCopyNoChildrenL(TBool preserveNsContext) const;
       
   810     
       
   811     /**
       
   812      * Specialized version of TXmlEngNode::CopyL()
       
   813      *
       
   814      * @since S60 v3.1
       
   815 	 * @return Deep copy of the element.
       
   816      */
       
   817     inline   TXmlEngElement CopyL() const;
       
   818 
       
   819     /**
       
   820      * Resets element's content: all child nodes are removed
       
   821      *
       
   822      * @since S60 v3.1
       
   823 	 */
       
   824     IMPORT_C void RemoveChildren();
       
   825 
       
   826     /**
       
   827      * Resets element's attributes
       
   828      *
       
   829      * @since S60 v3.1
       
   830 	 */
       
   831     IMPORT_C void RemoveAttributes();
       
   832 
       
   833     /**
       
   834      * Resets all namespace declarations made in the element
       
   835      * 
       
   836      * @note There can be references to these namespace declaration from elsewhere!
       
   837      *      Use ReconcileNamespacesL() to fix that.
       
   838      *
       
   839      * @since S60 v3.1
       
   840 	 */
       
   841     IMPORT_C void RemoveNamespaceDeclarations();
       
   842 
       
   843     /**
       
   844      * Removes all element contents: child nodes, attributes and namespace declarations
       
   845      *
       
   846      * @see RemoveChildren(), RemoveAttributes(), RemoveNamespaceDeclarations();
       
   847      *
       
   848      * @since S60 v3.1
       
   849 	 */
       
   850     inline   void ClearElement();
       
   851 
       
   852     /**
       
   853      * Copies attributes from another element
       
   854      *
       
   855      * It may be a very convenient method for initializing element with a set of predefined attributes.
       
   856      *
       
   857      * @since S60 v3.1
       
   858 	 * @param aSrc source element
       
   859      * 
       
   860      * @note
       
   861      *  Namespaces of the this element may need to be reconciled if copied attributes
       
   862      *  belong to any namespace that is not declared on some ascendant of this node.
       
   863      * @see ReconcileNamespacesL()
       
   864      */  
       
   865     IMPORT_C void CopyAttributesL(TXmlEngElement aSrc);
       
   866 
       
   867     /**
       
   868      * Copies a list of elements.
       
   869      *
       
   870      * Elements are appended to the element's children list.
       
   871      *
       
   872      * @since S60 v3.1
       
   873 	 * @param aSrc source element
       
   874      *
       
   875      * @note Namespaces of the this element may need to be reconciled after copy operation
       
   876      * @see  ReconcileNamespacesL()
       
   877      */
       
   878     IMPORT_C void CopyChildrenL(TXmlEngElement aSrc);
       
   879 
       
   880     /**
       
   881      * Removes attribute with given name and namespace URI(if such exists).
       
   882      * Memory allocated for the attribute is freed.
       
   883      *
       
   884      * @since S60 v3.1
       
   885 	 * @param aLocalName Element name
       
   886      * @param aNamespaceUri Element namespace
       
   887      */
       
   888     IMPORT_C void RemoveChildElementsL(const TDesC8& aLocalName,const TDesC8& aNamespaceUri);
       
   889 
       
   890     /** @} */
       
   891 
       
   892     /** 
       
   893     *    @name DOM Level 3 Core methods
       
   894     *
       
   895     *    @note
       
   896     *        Most methods of DOM spec operate with fully-qualified names (QNames)
       
   897     *        of elements and attributes. It is different in this API - all methods
       
   898     *        instead accept prefix and localName parts of QName.
       
   899     */
       
   900     /** @{ */
       
   901     
       
   902     /**
       
   903      * Returns value of attribute with given name and namespace URI
       
   904      *
       
   905      * @since S60 v3.1
       
   906 	 * @param aLocalName Local name of attribute node
       
   907      * @param aNamespaceUri Namespace URI of attribute
       
   908      * @return Attribute value
       
   909      */
       
   910     IMPORT_C TPtrC8 AttributeValueL(const TDesC8& aLocalName, 
       
   911                                     const TDesC8& aNamespaceUri = KNullDesC8) const;
       
   912 
       
   913     /**
       
   914      * Initializes list of child elements with matching name and namespace URI.
       
   915      *
       
   916      * @since S60 v3.1
       
   917 	 * @param aList Node list to be initialized
       
   918      * @param aLocalName Element name
       
   919      * @param aNamespaceUri Namespace URI, default is NULL
       
   920      *
       
   921      * @note This method does not lists all descedants of the element, only child elements
       
   922      */
       
   923     IMPORT_C void  GetElementsByTagNameL(RXmlEngNodeList<TXmlEngElement>& aList, 
       
   924                                          const TDesC8& aLocalName, 
       
   925                                          const TDesC8& aNamespaceUri = KNullDesC8) const;
       
   926     
       
   927     /**
       
   928      * Sets value of attribute; attribute is created if there is no such attribute yet
       
   929      *
       
   930      * @since S60 v3.1
       
   931 	 * @param aLocalName Attribute name
       
   932      * @param aValue Attribute value
       
   933      * @param aNamespaceUri Namespace URI - default is NULL
       
   934      * @param aPrefix Namespace prefix - default is NULL
       
   935      *
       
   936      * @note
       
   937      *  If prefix is not NULL (or ""), then namespace URI may not be empty
       
   938      *  see http://www.w3.org/TR/REC-xml-names/#ns-decl (Definition #3)
       
   939      */
       
   940     IMPORT_C void  SetAttributeL(const TDesC8& aLocalName, 
       
   941                                  const TDesC8& aValue, 
       
   942                                  const TDesC8& aNamespaceUri = KNullDesC8, 
       
   943                                  const TDesC8& aPrefix = KNullDesC8);
       
   944 
       
   945     /**
       
   946      * Removes attribute with given name and namespace URI(if such exists).
       
   947      * Memory allocated for the attribute is freed.
       
   948      *
       
   949      * @since S60 v3.1
       
   950 	 * @param aLocalName Name of the attribute
       
   951      * @param aNamespaceUri Attribute namespace URI, default is NULL
       
   952      */
       
   953     IMPORT_C void  RemoveAttributeL(const TDesC8& aLocalName, 
       
   954                                     const TDesC8& aNamespaceUri = KNullDesC8);
       
   955 
       
   956     /**
       
   957      * Retrieves attribute node from specific namespace by its name.
       
   958      *
       
   959      * @since S60 v3.1
       
   960 	 * @param aLocalName Name of the attribute
       
   961      * @param aNamespaceUri Attribute namespace URI, default is NULL
       
   962      * @return Attribute node with matching namespace URI and name
       
   963      */
       
   964     IMPORT_C TXmlEngAttr AttributeNodeL(const TDesC8& aLocalName, 
       
   965                                   const TDesC8& aNamespaceUri = KNullDesC8) const;
       
   966 
       
   967     /**
       
   968      * Check if element has attribute with given parameters.
       
   969      *
       
   970      * @since S60 v3.1
       
   971 	 * @param aLocalName Name of attribute
       
   972      * @param aNamespaceUri Namespace uri, default is NULL.
       
   973      * @return TRUE if the element holds an attribute with such namespace URI and name.
       
   974      *
       
   975      * Same result gives AttributeNodeL(uri,name).NotNull()
       
   976      */
       
   977     inline     TBool HasAttributeL(const TDesC8& aLocalName, 
       
   978                                    const TDesC8& aNamespaceUri  = KNullDesC8) const;
       
   979 
       
   980     /**
       
   981      * Links attribute into tree
       
   982      *
       
   983      * @since S60 v3.1
       
   984 	 * @param aNewAttr new attribute
       
   985      * 
       
   986      * The replaced attribute node is not returned and just deleted
       
   987      */
       
   988     IMPORT_C void  SetAttributeNodeL(TXmlEngAttr aNewAttr);
       
   989 };
       
   990 
       
   991 
       
   992 
       
   993 #include "xmlengelement.inl"
       
   994 
       
   995 #endif /* XMLENGINE_ELEMENT_H_INCLUDED */