epoc32/include/xml/dom/xmlengnode.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/xmlengnode.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies). 
williamr@2
     3
* All rights reserved.
williamr@2
     4
* This component and the accompanying materials are made available
williamr@2
     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
williamr@2
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     8
*
williamr@2
     9
* Initial Contributors:
williamr@2
    10
* Nokia Corporation - initial contribution.
williamr@2
    11
*
williamr@2
    12
* Contributors:
williamr@2
    13
*
williamr@2
    14
* Description:       Node class declaration
williamr@2
    15
*
williamr@2
    16
*/
williamr@2
    17
williamr@2
    18
williamr@2
    19
williamr@2
    20
williamr@2
    21
williamr@2
    22
williamr@2
    23
williamr@2
    24
#ifndef XMLENGINE_NODE_H_INCLUDED
williamr@2
    25
#define XMLENGINE_NODE_H_INCLUDED
williamr@2
    26
williamr@2
    27
#include <e32base.h>
williamr@2
    28
williamr@2
    29
// forward declaration
williamr@2
    30
class TXmlEngNode;
williamr@2
    31
williamr@2
    32
// Forward declarations
williamr@2
    33
template<class T> class RXmlEngNodeList;
williamr@2
    34
williamr@2
    35
class RXmlEngDocument;
williamr@2
    36
class TXmlEngElement;
williamr@2
    37
class TXmlEngAttr;
williamr@2
    38
class TXmlEngTextNode;
williamr@2
    39
class TXmlEngNamespace;
williamr@2
    40
class TXmlEngComment;
williamr@2
    41
class TXmlEngCDATASection;
williamr@2
    42
class TXmlEngDocumentFragment;
williamr@2
    43
class TXmlEngEntityReference;
williamr@2
    44
class TXmlEngProcessingInstruction;
williamr@2
    45
class MXmlEngUserData;
williamr@2
    46
class TXmlEngBinaryContainer;
williamr@2
    47
class TXmlEngChunkContainer;
williamr@2
    48
class TXmlEngDataContainer;
williamr@2
    49
class TXmlEngFileContainer;
williamr@2
    50
//
williamr@2
    51
williamr@2
    52
/**
williamr@2
    53
 * Instance of TXmlEngNode class represents an XML node in the DOM tree.
williamr@2
    54
 *
williamr@2
    55
 * Class implements methods that are similar for all XML node types
williamr@2
    56
 * i.e. element, attribute.
williamr@2
    57
 * 
williamr@2
    58
 * Sample code for node tree modifications:
williamr@2
    59
 * @code  
williamr@2
    60
 *      RXmlEngDOMImplementation domImpl;
williamr@2
    61
 *      domImpl.OpenL();        ///< opening DOM implementation object 
williamr@2
    62
 *      RXmlEngDocument iDoc; ///< iDoc with created nodes tree
williamr@2
    63
 *      TXmlEngNode tmp = iDoc.DocumentElement();
williamr@2
    64
 *	///< copying first child of iDoc to tmp2 node and appending it
williamr@2
    65
 * 	TXmlEngNode tmp2 = tmp.FirstChild().CopyL();
williamr@2
    66
 *	tmp.AppendChildL(tmp2);
williamr@2
    67
 *	///< copying next node to the first child of iDoc to the last child place
williamr@2
    68
 *	tmp.FirstChild().NextSibling().CopyToL(tmp.LastChild());
williamr@2
    69
 *	///< replasing before last child with second child 
williamr@2
    70
 *	tmp.LastChild().PreviousSibling().ReplaceWith(tmp.FirstChild().NextSibling());
williamr@2
    71
 *	///< moving first child of iDoc to second child childrens
williamr@2
    72
 *	tmp.FirstChild().MoveTo(tmp.FirstChild().NextSibling());	
williamr@2
    73
 *      iDoc.Close();               ///< closing all opened objects
williamr@2
    74
 *      domImpl.Close();
williamr@2
    75
 * @endcode 
williamr@2
    76
 *
williamr@2
    77
 * @lib XmlEngineDOM.lib
williamr@2
    78
 * @since S60 v3.1
williamr@2
    79
 */
williamr@2
    80
class TXmlEngNode
williamr@2
    81
{
williamr@2
    82
public:
williamr@2
    83
   /**
williamr@2
    84
    * The different element types carried by an XML tree.
williamr@2
    85
    *
williamr@2
    86
    * @note This is synchronized with DOM Level 3 values
williamr@2
    87
    *       See http://www.w3.org/TR/DOM-Level-3-Core/
williamr@2
    88
    *
williamr@2
    89
    */
williamr@2
    90
    enum TXmlEngDOMNodeType {
williamr@2
    91
        EElement                =        1,
williamr@2
    92
        EAttribute              =        2,
williamr@2
    93
        EText                   =        3,
williamr@2
    94
        ECDATASection           =        4,
williamr@2
    95
        EEntityReference        =        5,
williamr@2
    96
        EEntity                 =        6,  //> Not supported currently
williamr@2
    97
        EProcessingInstruction  =        7,
williamr@2
    98
        EComment                =        8,
williamr@2
    99
        EDocument               =        9,
williamr@2
   100
        EDocumentType           =        10, //> Not supported currently
williamr@2
   101
        EDocumentFragment       =        11,
williamr@2
   102
        ENotation               =        12, //> Not supported currently
williamr@2
   103
        ENamespaceDeclaration   =        18, //> Not in DOM spec
williamr@2
   104
		EBinaryContainer 		= 		 30, //> Not in DOM spec
williamr@2
   105
		EChunkContainer 		= 		 31, //> Not in DOM spec
williamr@2
   106
		EFileContainer 			= 		 32  //> Not in DOM spec
williamr@2
   107
    };
williamr@2
   108
williamr@2
   109
public:
williamr@2
   110
    /**
williamr@2
   111
     * Default constructor
williamr@2
   112
     *
williamr@2
   113
     * @since S60 v3.1
williamr@2
   114
     */
williamr@2
   115
    inline TXmlEngNode();
williamr@2
   116
williamr@2
   117
    /**
williamr@2
   118
     * Constructor
williamr@2
   119
     *
williamr@2
   120
     * @since S60 v3.1
williamr@2
   121
     * @param aInternal node pointer
williamr@2
   122
     */
williamr@2
   123
    inline TXmlEngNode(void* aInternal);
williamr@2
   124
williamr@2
   125
    /**
williamr@2
   126
     * Check if node is NULL
williamr@2
   127
     *
williamr@2
   128
     * @since S60 v3.1
williamr@2
   129
     * @return TRUE if node is NULL in other case FALSE
williamr@2
   130
     */
williamr@2
   131
    inline TBool IsNull() const;
williamr@2
   132
williamr@2
   133
    /**
williamr@2
   134
     * Check if node is NULL
williamr@2
   135
     *
williamr@2
   136
     * @since S60 v3.1
williamr@2
   137
     * @return TRUE if node is not NULL in other case FALSE
williamr@2
   138
     */
williamr@2
   139
    inline TBool NotNull()const;
williamr@2
   140
williamr@2
   141
    /**
williamr@2
   142
     * Cast node to attribute node.
williamr@2
   143
     *
williamr@2
   144
     * @since S60 v3.1
williamr@2
   145
     * @return Attribute node
williamr@2
   146
     *
williamr@2
   147
     * @note
williamr@2
   148
     *      - Never cast nodes to a wrong node type!
williamr@2
   149
     *      - Casting removes const'ness of the node
williamr@2
   150
     */
williamr@2
   151
    inline    TXmlEngAttr&                    AsAttr() const;
williamr@2
   152
williamr@2
   153
    /**
williamr@2
   154
     * Cast node to text node.
williamr@2
   155
     *
williamr@2
   156
     * @since S60 v3.1
williamr@2
   157
     * @return Text node
williamr@2
   158
     *
williamr@2
   159
     * @note
williamr@2
   160
     *     - Never cast nodes to a wrong node type!
williamr@2
   161
     *     - Casting removes const'ness of the node
williamr@2
   162
     */
williamr@2
   163
    inline    TXmlEngTextNode&                AsText() const;
williamr@2
   164
williamr@2
   165
    /**
williamr@2
   166
     * Cast node to binary data container
williamr@2
   167
     *
williamr@2
   168
     * @since S60 v3.2
williamr@2
   169
     * @return Binary container
williamr@2
   170
     *
williamr@2
   171
     * @note
williamr@2
   172
     *     - Never cast nodes to a wrong node type!
williamr@2
   173
     *     - Casting removes const'ness of the node
williamr@2
   174
     */
williamr@2
   175
    inline    TXmlEngBinaryContainer&		 AsBinaryContainer() const;
williamr@2
   176
williamr@2
   177
    /**
williamr@2
   178
     * Cast node to memory chunk container
williamr@2
   179
     *
williamr@2
   180
     * @since S60 v3.2
williamr@2
   181
     * @return Chunk container
williamr@2
   182
     *
williamr@2
   183
     * @note
williamr@2
   184
     *     - Never cast nodes to a wrong node type!
williamr@2
   185
     *     - Casting removes const'ness of the node
williamr@2
   186
     */
williamr@2
   187
    inline    TXmlEngChunkContainer&		 AsChunkContainer() const;
williamr@2
   188
williamr@2
   189
    /**
williamr@2
   190
     * Cast node to file container
williamr@2
   191
     *
williamr@2
   192
     * @since S60 v3.2
williamr@2
   193
     * @return File container
williamr@2
   194
     *
williamr@2
   195
     * @note
williamr@2
   196
     *     - Never cast nodes to a wrong node type!
williamr@2
   197
     *     - Casting removes const'ness of the node
williamr@2
   198
     */
williamr@2
   199
    inline    TXmlEngFileContainer&		 AsFileContainer() const;
williamr@2
   200
williamr@2
   201
    /**
williamr@2
   202
     * Cast node to memory chunk container
williamr@2
   203
     *
williamr@2
   204
     * @since S60 v3.1
williamr@2
   205
     * @return Chunk container
williamr@2
   206
     *
williamr@2
   207
     * @note
williamr@2
   208
     *     - Never cast nodes to a wrong node type!
williamr@2
   209
     *     - Casting removes const'ness of the node
williamr@2
   210
     */
williamr@2
   211
    inline    TXmlEngDataContainer&		 AsDataContainer() const;
williamr@2
   212
williamr@2
   213
    /**
williamr@2
   214
     * Cast node to element node.
williamr@2
   215
     *
williamr@2
   216
     * @since S60 v3.1
williamr@2
   217
     * @return Element node
williamr@2
   218
     *
williamr@2
   219
     * @note
williamr@2
   220
     *     - Never cast nodes to a wrong node type!
williamr@2
   221
     *     - Casting removes const'ness of the node
williamr@2
   222
     */
williamr@2
   223
    inline TXmlEngElement& AsElement() const;
williamr@2
   224
williamr@2
   225
    /**
williamr@2
   226
     * Cast node to comment node.
williamr@2
   227
     *
williamr@2
   228
     * @since S60 v3.1
williamr@2
   229
     * @return Comment node
williamr@2
   230
     *
williamr@2
   231
     * @note
williamr@2
   232
     *     - Never cast nodes to a wrong node type!
williamr@2
   233
     *     - Casting removes const'ness of the node
williamr@2
   234
     */
williamr@2
   235
    inline TXmlEngComment& AsComment() const;
williamr@2
   236
williamr@2
   237
    /**
williamr@2
   238
     * Cast node to namespace node.
williamr@2
   239
     *
williamr@2
   240
     * @since S60 v3.1
williamr@2
   241
     * @return Namespace node
williamr@2
   242
     *
williamr@2
   243
     * @note
williamr@2
   244
     *     - Never cast nodes to a wrong node type!
williamr@2
   245
     *     - Casting removes const'ness of the node
williamr@2
   246
     */
williamr@2
   247
    inline TXmlEngNamespace& AsNamespace() const;
williamr@2
   248
williamr@2
   249
    /**
williamr@2
   250
     * Cast node to CDATA section node.
williamr@2
   251
     *
williamr@2
   252
     * @since S60 v3.1
williamr@2
   253
     * @return CDATA section node
williamr@2
   254
     *
williamr@2
   255
     * @note
williamr@2
   256
     *     - Never cast nodes to a wrong node type!
williamr@2
   257
     *     - Casting removes const'ness of the node
williamr@2
   258
     */
williamr@2
   259
    inline TXmlEngCDATASection& AsCDATASection() const;
williamr@2
   260
williamr@2
   261
    /**
williamr@2
   262
     * Cast node to entity reference node.
williamr@2
   263
     *
williamr@2
   264
     * @since S60 v3.1
williamr@2
   265
     * @return Entity reference node
williamr@2
   266
     *
williamr@2
   267
     * @note
williamr@2
   268
     *     - Never cast nodes to a wrong node type!
williamr@2
   269
     *     - Casting removes const'ness of the node
williamr@2
   270
     */
williamr@2
   271
    inline TXmlEngEntityReference& AsEntityReference() const;
williamr@2
   272
williamr@2
   273
    /**
williamr@2
   274
     * Cast node to processing instruction node.
williamr@2
   275
     *
williamr@2
   276
     * @since S60 v3.1
williamr@2
   277
     * @return Processing instruction node
williamr@2
   278
     *
williamr@2
   279
     * @note
williamr@2
   280
     *     - Never cast nodes to a wrong node type!
williamr@2
   281
     *     - Casting removes const'ness of the node
williamr@2
   282
     */
williamr@2
   283
    inline TXmlEngProcessingInstruction& AsProcessingInstruction() const;
williamr@2
   284
williamr@2
   285
    /**
williamr@2
   286
     * Get innerXML string. This method returns all content of the node.
williamr@2
   287
     * Output text does not include node markup.
williamr@2
   288
     *
williamr@2
   289
     * @since S60 v3.1
williamr@2
   290
     * @param aBuffer RBuf8 in which output should be save
williamr@2
   291
     * @return Size of output buffer
williamr@2
   292
     * @note Returned RBuf8 should be freed
williamr@2
   293
     */
williamr@2
   294
    IMPORT_C TInt InnerXmlL(RBuf8& aBuffer);
williamr@2
   295
    
williamr@2
   296
    /**
williamr@2
   297
     * Get outerXML string. This method returns all content of the node.
williamr@2
   298
     * Output text includes node markup.
williamr@2
   299
     *
williamr@2
   300
     * @since S60 v3.1
williamr@2
   301
     * @param aBuffer RBuf8 in which output should be save
williamr@2
   302
     * @return Size of output buffer
williamr@2
   303
     * @note Returned RBuf8 should be freed
williamr@2
   304
     */
williamr@2
   305
    IMPORT_C TInt OuterXmlL(RBuf8& aBuffer);
williamr@2
   306
williamr@2
   307
    /**
williamr@2
   308
     * Moves the node to become the first in the list of its siblings
williamr@2
   309
     * Node is expected to have a parent.
williamr@2
   310
     *
williamr@2
   311
     * @since S60 v3.1
williamr@2
   312
     */
williamr@2
   313
    IMPORT_C void SetAsFirstSibling();
williamr@2
   314
williamr@2
   315
    /**
williamr@2
   316
     * Moves the node to become the last in the list of its siblings
williamr@2
   317
     * Node is expected to have a parent.
williamr@2
   318
     *
williamr@2
   319
     * @since S60 v3.1
williamr@2
   320
     */
williamr@2
   321
    IMPORT_C void SetAsLastSibling();
williamr@2
   322
williamr@2
   323
    /**
williamr@2
   324
     * Moves the node in the list of sibling nodes before another node
williamr@2
   325
     * Node is expected to have a parent.
williamr@2
   326
     * Do nothing if aSiblingNode is not one of node's siblings
williamr@2
   327
     *
williamr@2
   328
     * @since S60 v3.1
williamr@2
   329
	 * @param aSiblingNode Node that should be after current node 
williamr@2
   330
     */
williamr@2
   331
    IMPORT_C void MoveBeforeSibling(TXmlEngNode aSiblingNode);
williamr@2
   332
williamr@2
   333
    /**
williamr@2
   334
     * Moves the node in the list of sibling nodes after another node
williamr@2
   335
     * Node is expected to have a parent.
williamr@2
   336
     * Do nothing if aSiblingNode is not one of the node's siblings
williamr@2
   337
     *
williamr@2
   338
     * @since S60 v3.1
williamr@2
   339
	 * @param aSiblingNode Node that should be after current node 
williamr@2
   340
     */    
williamr@2
   341
    IMPORT_C void MoveAfterSibling(TXmlEngNode aSiblingNode);
williamr@2
   342
williamr@2
   343
    /**
williamr@2
   344
     * Moves the node to another part of the tree or another document
williamr@2
   345
     * The node is unliked from current postion (if any) and appended
williamr@2
   346
     * to the its new parent.
williamr@2
   347
     *
williamr@2
   348
     * @since S60 v3.1
williamr@2
   349
     * @param aParent Parent node
williamr@2
   350
     * @return Node handle
williamr@2
   351
     *
williamr@2
   352
     * @note 
williamr@2
   353
     * In many cases this method call should be followed by ReconcileNamespacesL() on the moved node
williamr@2
   354
     */
williamr@2
   355
    inline  TXmlEngNode MoveTo(TXmlEngNode aParent);
williamr@2
   356
williamr@2
   357
    /**
williamr@2
   358
     * Detaches a node from document tree
williamr@2
   359
     *
williamr@2
   360
     * @since S60 v3.1
williamr@2
   361
     * @return This node, which is already not a part of any document
williamr@2
   362
     * @note    Remember to use ReconcileNamespacesL() later, if extracted node (subtree)
williamr@2
   363
     *          contains references to namespace declarations outside of the subtree.
williamr@2
   364
     * @see     ReconcileNamespacesL()
williamr@2
   365
     * @note    The document, from which the is being unlinked, becomes an owner of the node
williamr@2
   366
     *          until it is linked elsewhere.
williamr@2
   367
     */
williamr@2
   368
    IMPORT_C TXmlEngNode Unlink();
williamr@2
   369
williamr@2
   370
    /**
williamr@2
   371
     * Ensures that namespaces referred to in the node and its descendants are
williamr@2
   372
     * in the scope the node.
williamr@2
   373
     *
williamr@2
   374
     * This method checks that all the namespaces declared within the given
williamr@2
   375
     * tree are properly declared. This is needed for example after Copy or Unlink
williamr@2
   376
     * and then Append operations. The subtree may still hold pointers to
williamr@2
   377
     * namespace declarations outside the subtree or they may be invalid/masked. As much
williamr@2
   378
     * as possible the function try to reuse the existing namespaces found in
williamr@2
   379
     * the new environment. If not possible, the new namespaces are redeclared
williamr@2
   380
     * on the top of the subtree.
williamr@2
   381
     *
williamr@2
   382
     * This method should be used after unlinking nodes and inserting to another
williamr@2
   383
     * document tree or to a another part of the original tree, if some nodes of the subtree
williamr@2
   384
     * are remove from the scope of a namespace declaration they refer to.
williamr@2
   385
     *
williamr@2
   386
     * When node is unlinked, it may still refer to namespace declarations from the previous location.
williamr@2
   387
     * It is important to reconcile subtree's namespaces if previous parent tree is to be destroyed.
williamr@2
   388
     * On the other hand, if the parent tree is not changed before pasting its unlinked part into another
williamr@2
   389
     * tree, then reconciliation is needed only after paste operation.
williamr@2
   390
     *
williamr@2
   391
     * @since S60 v3.1
williamr@2
   392
     */
williamr@2
   393
    IMPORT_C void ReconcileNamespacesL();
williamr@2
   394
williamr@2
   395
    /**
williamr@2
   396
     * Unlinks the node and destroys it; all child nodes are destroyed as well and all memory is freed
williamr@2
   397
     *
williamr@2
   398
     * @note  Document nodes cannot be "removed" with this method, uses RXmlEngDocument-specific methods.
williamr@2
   399
     *
williamr@2
   400
     * @since S60 v3.1
williamr@2
   401
     */
williamr@2
   402
    IMPORT_C void Remove();
williamr@2
   403
williamr@2
   404
    /**
williamr@2
   405
     * Current node is replaced with another node (subtree).
williamr@2
   406
     *
williamr@2
   407
     * The replacement node is linked into document tree instead of this node.
williamr@2
   408
     * The replaced node is destroyed.
williamr@2
   409
     *
williamr@2
   410
     * @since S60 v3.1
williamr@2
   411
     * @param aNode Node that repleace current node
williamr@2
   412
     *
williamr@2
   413
     * @see SubstituteFor(TXmlEngNode)
williamr@2
   414
     *
williamr@2
   415
     * In both cases the argument node is unlinked from its previous location
williamr@2
   416
     * (which can be NONE, i.e. not linked; SAME or ANOTHER document tree).
williamr@2
   417
     *
williamr@2
   418
     * @note Replacement of a node with NULL TXmlEngNode is legal and equivalent to removing the node.
williamr@2
   419
     * @note Not applicable to document nodes
williamr@2
   420
     */
williamr@2
   421
    IMPORT_C void ReplaceWith(TXmlEngNode aNode);
williamr@2
   422
williamr@2
   423
    /**
williamr@2
   424
     * Another node is put instead of the current node.
williamr@2
   425
     *
williamr@2
   426
     * Does the same as ReplaceWith(TXmlEngNode) but does not free node and just returns it.
williamr@2
   427
     *
williamr@2
   428
     * @since S60 v3.1
williamr@2
   429
     * @param aNode Node that repleace current node
williamr@2
   430
     * @return Current node after unlinking it from document tree
williamr@2
   431
     * @see ReplaceWith(TXmlEngNode)
williamr@2
   432
     *
williamr@2
   433
     * In both cases the argument node is unlinked from its previous location
williamr@2
   434
     * (which can be NONE, i.e. not linked; SAME or ANOTHER document tree)
williamr@2
   435
     *
williamr@2
   436
     * It is possible to use NULL TXmlEngNode object as an argument. In such case
williamr@2
   437
     * no new node will be put instead of unlinked one.
williamr@2
   438
     *
williamr@2
   439
     * @note Not applicable to document nodes
williamr@2
   440
     */
williamr@2
   441
    IMPORT_C TXmlEngNode SubstituteForL(TXmlEngNode aNode);
williamr@2
   442
williamr@2
   443
    /**
williamr@2
   444
     * Retrieves a "handle" for namespace declaration that applies to the node's namespace
williamr@2
   445
     * Note: DOM specs do not consider namespace declarations as a kind of nodes
williamr@2
   446
     * This API adds TXmlEngNamespace type of nodes, which is derived from TXmlEngNode.
williamr@2
   447
     *
williamr@2
   448
     * @since S60 v3.1
williamr@2
   449
     * @return    Object that represents namespace declaration and prefix binding that
williamr@2
   450
     *             act on the node; returns NULL object (check using TXmlEngNamespace.IsNull()
williamr@2
   451
     *             or TXmlEngNamespace.NotNull()) if no namespace associated
williamr@2
   452
     */
williamr@2
   453
    IMPORT_C TXmlEngNamespace NamespaceDeclaration() const;
williamr@2
   454
williamr@2
   455
    /**
williamr@2
   456
     * Attaches a user data object to this node. The ownership of the object is transferred.
williamr@2
   457
     * When the (underlying) node is deleted the Destroy method of the MXmlEngUserData class will be
williamr@2
   458
     * called. If there already is a user data object associated with this node, it will be
williamr@2
   459
     * deleted before attaching the new object.
williamr@2
   460
     *
williamr@2
   461
     * @since S60 v3.1
williamr@2
   462
     * @param aData Pointer to the data object.
williamr@2
   463
     * @return true if successful, false if for example underlying node type doesn't support
williamr@2
   464
     * attaching user data.
williamr@2
   465
     * @note Only TXmlEngElement and Attribute nodes currently support this feature.
williamr@2
   466
     *             User data is not copied, when node is copied.
williamr@2
   467
     */
williamr@2
   468
    IMPORT_C TBool AddUserData(MXmlEngUserData* aData);
williamr@2
   469
williamr@2
   470
    /**
williamr@2
   471
     * Returns the user data object attached to this node. Ownership is not transferred.
williamr@2
   472
     *
williamr@2
   473
     * @since S60 v3.1
williamr@2
   474
     * @return Pointer to data object or NULL if it doesn't exist.
williamr@2
   475
     */
williamr@2
   476
    IMPORT_C MXmlEngUserData* UserData() const;
williamr@2
   477
williamr@2
   478
    /**
williamr@2
   479
     * Removes the user data onject attached to this node. Ownership is transferred
williamr@2
   480
     * (the object is not deleted).
williamr@2
   481
     *
williamr@2
   482
     * @since S60 v3.1
williamr@2
   483
     * @return Pointer to data object or NULL if it doesn't exist.
williamr@2
   484
     */
williamr@2
   485
    IMPORT_C MXmlEngUserData* RemoveUserData();
williamr@2
   486
williamr@2
   487
    /**
williamr@2
   488
     * Clones the node completely: all attributes and namespace declarations (for TXmlEngElement nodes),
williamr@2
   489
     * values and children nodes are copied as well.
williamr@2
   490
     *
williamr@2
   491
     * Document nodes cannot be copied with this method: RXmlEngDocument::CloneDocumentL() must be used.
williamr@2
   492
     *
williamr@2
   493
     * @since S60 v3.1
williamr@2
   494
     * @return Complete copy of a node or leaves.
williamr@2
   495
     * @note    The node should not be NULL!
williamr@2
   496
     */
williamr@2
   497
    IMPORT_C TXmlEngNode CopyL() const;
williamr@2
   498
williamr@2
   499
    /**
williamr@2
   500
     * Creates a deep copy of the node and appends the subtree as a new child
williamr@2
   501
     * to the provided parent node.
williamr@2
   502
     *
williamr@2
   503
     * @since S60 v3.1
williamr@2
   504
     * @return Created copy of the node after linking it into the target document tree.
williamr@2
   505
     * @note Document nodes cannot be copied with this method; use RXmlEngDocument::CloneDocumentL()
williamr@2
   506
     */
williamr@2
   507
    IMPORT_C TXmlEngNode CopyToL(TXmlEngNode aParent) const;
williamr@2
   508
williamr@2
   509
    /**
williamr@2
   510
     * Append a child node.
williamr@2
   511
     *
williamr@2
   512
     * This is universal operation for any types of nodes.
williamr@2
   513
     * Note, that some types of nodes cannot have children and
williamr@2
   514
     * some types of nodes are not allowed to be children of some other types.
williamr@2
   515
     *
williamr@2
   516
     * @since S60 v3.1
williamr@2
   517
     * @param aNewChild Child node that should be added
williamr@2
   518
     * @return Appended node, which could changed as a result of adding it to
williamr@2
   519
     * list of child nodes (e.g. text nodes can coalesce together)
williamr@2
   520
     */
williamr@2
   521
    IMPORT_C TXmlEngNode AppendChildL(TXmlEngNode aNewChild);
williamr@2
   522
williamr@2
   523
    /**
williamr@2
   524
     * Initializes a node list with all children of the node
williamr@2
   525
     *
williamr@2
   526
     * @since S60 v3.1
williamr@2
   527
     * @param aList node list that should be initialized
williamr@2
   528
     */
williamr@2
   529
    IMPORT_C void GetChildNodes(RXmlEngNodeList<TXmlEngNode>& aList) const;
williamr@2
   530
williamr@2
   531
    /**
williamr@2
   532
     * Get parent node of current node.
williamr@2
   533
     *
williamr@2
   534
     * @since S60 v3.1
williamr@2
   535
     * @return Parent node of the node or NULL if no parent
williamr@2
   536
     */
williamr@2
   537
    IMPORT_C TXmlEngNode ParentNode() const;
williamr@2
   538
williamr@2
   539
    /**
williamr@2
   540
     * Get first child of current node
williamr@2
   541
     *
williamr@2
   542
     * @since S60 v3.1
williamr@2
   543
     * @return The first child node or NULL if no children
williamr@2
   544
     */
williamr@2
   545
    IMPORT_C TXmlEngNode FirstChild() const;
williamr@2
   546
williamr@2
   547
    /**
williamr@2
   548
     * Get last child of current node
williamr@2
   549
     *
williamr@2
   550
     * @since S60 v3.1
williamr@2
   551
     * @return The last child node or NULL if no children
williamr@2
   552
     */
williamr@2
   553
    IMPORT_C TXmlEngNode LastChild() const;
williamr@2
   554
williamr@2
   555
    /**
williamr@2
   556
     * Get previous node of current node
williamr@2
   557
     *
williamr@2
   558
     * @since S60 v3.1
williamr@2
   559
     * @return Previous node in a child list or NULL if no sibling before
williamr@2
   560
     */
williamr@2
   561
    IMPORT_C TXmlEngNode PreviousSibling() const;
williamr@2
   562
williamr@2
   563
    /**
williamr@2
   564
     * Get fallowing node of current node
williamr@2
   565
     *
williamr@2
   566
     * @since S60 v3.1
williamr@2
   567
     * @return Following node in a child list or NULL if no sibling after
williamr@2
   568
     */
williamr@2
   569
    IMPORT_C TXmlEngNode NextSibling() const;
williamr@2
   570
williamr@2
   571
    /**
williamr@2
   572
     * Get document handle
williamr@2
   573
     *
williamr@2
   574
     * @since S60 v3.1
williamr@2
   575
     * @return A document node of the DOM tree this node belongs to
williamr@2
   576
     *
williamr@2
   577
     * @note An instance of RXmlEngDocument class returns itself
williamr@2
   578
     */
williamr@2
   579
    IMPORT_C RXmlEngDocument OwnerDocument() const;
williamr@2
   580
williamr@2
   581
    /**
williamr@2
   582
     * Fetches value of this node, depending on its type.
williamr@2
   583
     *
williamr@2
   584
     * @note It is better to always cast nodes to specific type and then use specific
williamr@2
   585
     *       method for getting "node value"
williamr@2
   586
     *
williamr@2
   587
     * @since S60 v3.1
williamr@2
   588
     * @return Node value
williamr@2
   589
     */
williamr@2
   590
    IMPORT_C TPtrC8 Value() const;
williamr@2
   591
williamr@2
   592
    /**
williamr@2
   593
     * Get copy of node's text content
williamr@2
   594
     * What is returned depends on the node type.
williamr@2
   595
     * Method caller is responsible for freeing returned string.
williamr@2
   596
     *
williamr@2
   597
     * @since S60 v3.1
williamr@2
   598
     * @return   the content of the node
williamr@2
   599
     */
williamr@2
   600
    IMPORT_C void WholeTextContentsCopyL(RBuf8& aOutput) const;
williamr@2
   601
williamr@2
   602
    /**
williamr@2
   603
     * Sets value of this node.
williamr@2
   604
     *
williamr@2
   605
     * @since S60 v3.1
williamr@2
   606
     * @param aValue New value
williamr@2
   607
     */
williamr@2
   608
    IMPORT_C void SetValueL(const TDesC8& aValue);
williamr@2
   609
williamr@2
   610
    /**
williamr@2
   611
     * Check if node content is "simple text".
williamr@2
   612
     *
williamr@2
   613
     * @since S60 v3.1
williamr@2
   614
     * @return Whether the value of the node is presented by only one TXmlEngTextNode node
williamr@2
   615
     *
williamr@2
   616
     * If the value is <i>"simple text"</i> then it is possible to access it as TDOMString
williamr@2
   617
     * without making copy, which combines values of all text nodes and entity reference nodes.
williamr@2
   618
     *
williamr@2
   619
     * @see TXmlEngNode::Value(), TXmlEngAttr::Value(), TXmlEngElement::Text()
williamr@2
   620
     *
williamr@2
   621
     * This method is applicable to TXmlEngElement and TXmlEngAttr nodes. On other nodes FALSE is returned.
williamr@2
   622
     *
williamr@2
   623
     * @note
williamr@2
   624
     *  Values (contents) of TXmlEngComment, TXmlEngCDATASection, TXmlEngTextNode, ProcessingInstuction data are
williamr@2
   625
     *  always "simple".
williamr@2
   626
     *
williamr@2
   627
     * When the returned result is FALSE, getting value of the node would not returned
williamr@2
   628
     * whole contents because of either entity references present in the contents or
williamr@2
   629
     * the contents is mixed (for TXmlEngElement node). In this case WholeTextContentsCopyL()
williamr@2
   630
     * should be used.
williamr@2
   631
     *
williamr@2
   632
     * @see TXmlEngNode::WholeTextContentsCopyL()
williamr@2
   633
     */
williamr@2
   634
    IMPORT_C TBool IsSimpleTextContents() const;
williamr@2
   635
williamr@2
   636
    /**
williamr@2
   637
     * Use NodeType() to find out the type of the node prior to casting object
williamr@2
   638
     * of TXmlEngNode class to one of its derived subclasses (TXmlEngElement, TXmlEngAttr, TXmlEngTextNode, etc.)
williamr@2
   639
     *
williamr@2
   640
     * @since S60 v3.1
williamr@2
   641
     * @return Type of the node
williamr@2
   642
     *
williamr@2
   643
     * @see TXmlEngDOMNodeType
williamr@2
   644
     */
williamr@2
   645
    IMPORT_C TXmlEngDOMNodeType NodeType() const;
williamr@2
   646
williamr@2
   647
    /**
williamr@2
   648
     * Get node name
williamr@2
   649
     *
williamr@2
   650
     * @since S60 v3.1
williamr@2
   651
     * @return Name of the node
williamr@2
   652
     *
williamr@2
   653
     * This method generally follows DOM spec :
williamr@2
   654
     * -------------------------------------------------------------------------------
williamr@2
   655
     * The values of nodeName, nodeValue, and attributes vary according to the node
williamr@2
   656
     * type as follows:
williamr@2
   657
     *
williamr@2
   658
     * interface              nodeName                nodeValue            attributes
williamr@2
   659
     * -------------------------------------------------------------------------------
williamr@2
   660
     * Attr                   = Attr.name              = Attr.value             = null
williamr@2
   661
     * CDATASection           = "#cdata-section"       = CharacterData.data     = null
williamr@2
   662
     * Comment                = "#comment"             = CharacterData.data     = null
williamr@2
   663
     * Document               = "#document"            = null                   = null
williamr@2
   664
     * DocumentFragment       = "#document-fragment"   = null                   = null
williamr@2
   665
     * DocumentType           = DocumentType.name      = null                   = null
williamr@2
   666
     * Element                = Element.tagName        = null           = NamedNodeMap
williamr@2
   667
     * Entity                 = entity name            = null                   = null
williamr@2
   668
     * EntityReference        = name of entity referenced  = null               = null
williamr@2
   669
     * Notation               = notation name          = null                   = null
williamr@2
   670
     * ProcessingInstruction  = target                 = data                   = null
williamr@2
   671
     * Text                   = "#text"                = CharacterData.data     = null
williamr@2
   672
     * -------------------------------------------------------------------------------
williamr@2
   673
     */
williamr@2
   674
    IMPORT_C TPtrC8 Name() const;
williamr@2
   675
williamr@2
   676
williamr@2
   677
    /**
williamr@2
   678
     * Check if node has child nodes.
williamr@2
   679
     *
williamr@2
   680
     * @since S60 v3.1
williamr@2
   681
     * @return True if the node is TXmlEngElement and has at least one child node
williamr@2
   682
     */
williamr@2
   683
    IMPORT_C TBool HasChildNodes() const;
williamr@2
   684
williamr@2
   685
    /**
williamr@2
   686
     * Check if node has attributes.
williamr@2
   687
     *
williamr@2
   688
     * @since S60 v3.1
williamr@2
   689
     * @return True if the node is TXmlEngElement and has at least one attribute
williamr@2
   690
     *
williamr@2
   691
     * @note Namespace-to-prefix bindings are not attributes.
williamr@2
   692
     */
williamr@2
   693
    IMPORT_C TBool HasAttributes() const;
williamr@2
   694
williamr@2
   695
    /**
williamr@2
   696
     * Evaluates active base URI for the node by processing xml:base attributes of parents
williamr@2
   697
     *
williamr@2
   698
     * @since S60 v3.1
williamr@2
   699
     * @return A copy of effective base URI for the node
williamr@2
   700
     * @note It's up to the caller to free the string
williamr@2
   701
     */
williamr@2
   702
    IMPORT_C void BaseUriL(RBuf8& aBaseUri) const;
williamr@2
   703
williamr@2
   704
    /**
williamr@2
   705
     * Compares nodes.
williamr@2
   706
     *
williamr@2
   707
     * The nodes are the same if they are referring to the same in-memory
williamr@2
   708
     * data structure.
williamr@2
   709
     *
williamr@2
   710
     * @since S60 v3.1
williamr@2
   711
     * @param aOther Node to compare
williamr@2
   712
     * @return TRUE if the same
williamr@2
   713
     */
williamr@2
   714
    inline TBool IsSameNode(TXmlEngNode aOther) const;
williamr@2
   715
williamr@2
   716
    /**
williamr@2
   717
     * Get namespace uri.
williamr@2
   718
     *
williamr@2
   719
     * @since S60 v3.1
williamr@2
   720
     * @return  Namespace URI of a node
williamr@2
   721
     *           - NULL is returned for elements and attributes that do not
williamr@2
   722
     *             belong to any namespace.
williamr@2
   723
     *           - bound namespace URI is returned for namespace declaration nodes (instances of TXmlEngNamespace).
williamr@2
   724
     *           - NULL is returned to all other types of node.
williamr@2
   725
     *
williamr@2
   726
     * @note use IsNull() and NotNull() for testing returned result on the subject
williamr@2
   727
     *      of having some URI
williamr@2
   728
     */
williamr@2
   729
    IMPORT_C TPtrC8 NamespaceUri() const;
williamr@2
   730
williamr@2
   731
    /**
williamr@2
   732
     * Get namespace prefix.
williamr@2
   733
     *
williamr@2
   734
     * @since S60 v3.1
williamr@2
   735
     * @return  Prefix of a node
williamr@2
   736
     * Returns NULL for elements and attributes that do not have prefix
williamr@2
   737
     * (node belongs to the default namespace or does not belong to any namespace)
williamr@2
   738
     * NULL is also returned for all types of node other than TXmlEngElement or TXmlEngAttr
williamr@2
   739
     */
williamr@2
   740
    IMPORT_C TPtrC8 Prefix() const;
williamr@2
   741
williamr@2
   742
    /**
williamr@2
   743
     * Check if nemespace is default for this node
williamr@2
   744
     *
williamr@2
   745
     * @since S60 v3.1
williamr@2
   746
     * @param aNamespaceUri Namespace URI
williamr@2
   747
     * @return True if given namespace URI is a default one for the node (applicable to elements only)
williamr@2
   748
     *
williamr@2
   749
     * @note "" or NULL can be used to denote undefined namespace
williamr@2
   750
     */
williamr@2
   751
    IMPORT_C TBool IsDefaultNamespaceL(const TDesC8& aNamespaceUri) const;
williamr@2
   752
williamr@2
   753
    /**
williamr@2
   754
     * Searches the prefix that is bound to the given aNamespaceUri and
williamr@2
   755
     * applicable in the scope of this TXmlEngNode.
williamr@2
   756
     *
williamr@2
   757
     * @since S60 v3.1
williamr@2
   758
     * @param aNamespaceUri Namespace Uri that should be found
williamr@2
   759
     * @return A sought prefix or NULL if not found or aNamespaceUri is the default namespace
williamr@2
   760
     *
williamr@2
   761
     * @see TXmlEngElement::LookupNamespaceByUriL(const TDesC8&)
williamr@2
   762
     */
williamr@2
   763
    IMPORT_C TPtrC8 LookupPrefixL(const TDesC8& aNamespaceUri) const;
williamr@2
   764
williamr@2
   765
    /**
williamr@2
   766
     * Searches the namespace URI that is bound to the given prefix.
williamr@2
   767
     * 
williamr@2
   768
     * @since S60 v3.1
williamr@2
   769
     * @param aPrefix Namespace prefix that should be found
williamr@2
   770
     * @return A sought URI or NULL if the prefix is not bound
williamr@2
   771
     *
williamr@2
   772
     * @see TXmlEngElement::LookupNamespaceByPrefixL(const TDesC8&)
williamr@2
   773
     */
williamr@2
   774
    IMPORT_C TPtrC8 LookupNamespaceUriL(const TDesC8& aPrefix) const;
williamr@2
   775
williamr@2
   776
protected:
williamr@2
   777
    /**
williamr@2
   778
     * Unlinks the internal libxml2's node from double-linked list.
williamr@2
   779
     * Relinks neighbour nodes.The node stays virtually linked to its old neighbours! Use with care!!
williamr@2
   780
     *
williamr@2
   781
     * No checks are made; nor parent's, nor node's properties updated
williamr@2
   782
     *
williamr@2
   783
     * @since S60 v3.1
williamr@2
   784
     */
williamr@2
   785
    void DoUnlinkNode();
williamr@2
   786
williamr@2
   787
    /**
williamr@2
   788
     * Inserts the node in a double-linked list of nodes before specified node.
williamr@2
   789
     *
williamr@2
   790
     * No checks are made; nor parent's, nor node's properties updated (except prev/next)
williamr@2
   791
     *
williamr@2
   792
     * @since S60 v3.1
williamr@2
   793
     * @param aNode Target node
williamr@2
   794
     */
williamr@2
   795
    void LinkBefore(TXmlEngNode aNode);
williamr@2
   796
williamr@2
   797
protected:
williamr@2
   798
	/** Node pointer */
williamr@2
   799
    void* iInternal;
williamr@2
   800
williamr@2
   801
};
williamr@2
   802
williamr@2
   803
#include "xmlengnode.inl"
williamr@2
   804
williamr@2
   805
#endif /* XMLENGINE_NODE_H_INCLUDED */