epoc32/include/xml/dom/xmlengdocument.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Document node functions
    15 //
    16 
    17 
    18 
    19 /**
    20  @file
    21  @publishedAll
    22  @released
    23 */
    24 #ifndef XMLENGDOCUMENT_H
    25 #define XMLENGDOCUMENT_H
    26 
    27 #include <f32file.h> 
    28 
    29 #include <xml/dom/xmlengnode.h>
    30 #include <xml/dom/xmlengserializationoptions.h>
    31 
    32 class RXmlEngDOMImplementation;
    33 
    34 /**
    35 This class represents an XML document in the DOM tree.  It stores all nodes 
    36 and associated information about the XML document.  
    37 
    38 This class implements the interface.  Another class, RXmlEngDOMImplementation,
    39 provides the implementation.  An instance of RXmlEngDOMImplementation must be
    40 constructed and opened first and passed to RXmlEngDocument::OpenL().
    41 */
    42 class RXmlEngDocument : public TXmlEngNode
    43 {
    44 public:    
    45     /** 
    46 	Default constructor.  An instance of RXmlEngDocument must be "opened" with
    47 	one of OpenL() overloads before methods are invoked on the object.
    48 	*/
    49     IMPORT_C RXmlEngDocument();
    50     
    51     /** 
    52     Opens the document.
    53 	@param aDOMImpl An opened DOM implementation object
    54 	@leave - One of the system-wide error codes
    55     */
    56     IMPORT_C void OpenL(RXmlEngDOMImplementation& aDOMImpl);
    57 	
    58 	/** 
    59 	Opens the document, initializing it with the internal state pointer from
    60 	another RXmlEngDocument.  This document becomes an alias for the document
    61 	whose state is represented by aInternal and a change in either document
    62 	will be reflected in the other.  Close() need only be called once, however,
    63 	it is not an error to call Close() on each RXmlEngDocument.
    64 
    65 	@param aDOMImpl An opened DOM implementation object
    66  	@param aInternal The internal document state to initialize this object with
    67 	@leave - One of the system-wide error codes
    68     */
    69     IMPORT_C void OpenL(RXmlEngDOMImplementation& aDOMImpl, void* aInternal);
    70     
    71 	/** 
    72 	Opens the document and adds aRoot as the root of the DOM tree.  If aRoot is
    73 	currently part of another document, it will be unlinked.  Ownership is
    74 	transferred to this document.
    75 
    76 	@param aDOMImpl An opened DOM implementation object
    77  	@param aRoot The element that will be the root of the DOM tree
    78 	@leave - One of the system-wide error codes
    79     */
    80     IMPORT_C void OpenL(RXmlEngDOMImplementation& aDOMImpl, TXmlEngElement aRoot);
    81     
    82     /** 
    83 	Closes document:  All owned nodes, child nodes, and namespaces are freed.  All
    84 	data containers on the data container list are freed.
    85 	*/
    86     IMPORT_C  void Close();
    87 
    88 	/**
    89 	Serializes document tree into a file.  For nodes containing binary data in
    90 	the form of BinaryDataContainer, FileContainer or ChunkContainer, the
    91 	client can implement custom serialization by implementing the
    92 	MXmlEngDataSerializer interface and saving a pointer to the customer
    93 	serializer in the iDataSerializer member of the aSaveOptions parameter. If
    94 	no custom serialization is specified, the binary data container nodes are
    95 	serialized like text nodes.
    96 
    97 	If no aRoot is provided, the entire DOM tree is serialized.  aRoot does not
    98 	need to be owned by this document.
    99     
   100 	@param aFileName A file name (with path)
   101  	@param aRoot Root node to be serialized	
   102 	@param aSaveOptions Options that control how serialization is performed 
   103     @return Number of bytes written
   104 	@leave KXmlEngErrWrongEncoding Encoding not understood
   105 	@leave KXmlEngErrWrongUseOfAPI Document is NULL
   106     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
   107 	@leave - One of the system-wide error codes
   108 	*/
   109     IMPORT_C TInt SaveL( const TDesC& aFileName,
   110     					 TXmlEngNode aRoot = TXmlEngNode(),
   111     					 const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions() ) const;
   112    
   113     /**
   114 	Serializes document tree into a file.  For nodes containing binary data in
   115 	the form of BinaryDataContainer, FileContainer or ChunkContainer, the
   116 	client can implement custom serialization by implementing the
   117 	MXmlEngDataSerializer interface and saving a pointer to the customer
   118 	serializer in the iDataSerializer member of the aSaveOptions parameter. If
   119 	no custom serialization is specified, the binary data container nodes are
   120 	serialized like text nodes.
   121     
   122 	If no aRoot is provided, the entire DOM tree is serialized.  aRoot does not
   123 	need to be owned by this document.
   124     
   125 	@param aRFs An open file Server session
   126 	@param aFileName A file name (with path)
   127  	@param aRoot Root node to be serialized	
   128 	@param aSaveOptions Options that control how serialization is performed 
   129     @return Number of bytes written
   130 	@leave KXmlEngErrWrongEncoding Encoding not understood
   131 	@leave KXmlEngErrWrongUseOfAPI Document is NULL
   132     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
   133 	@leave - One of the system-wide error codes
   134     */                        
   135     IMPORT_C TInt SaveL( RFs& aRFs,
   136                          const TDesC& aFileName,
   137                          TXmlEngNode aRoot = TXmlEngNode(),
   138                          const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions() ) const;
   139     
   140 	/**
   141 	Serializes document tree into provided output stream, which supports
   142 	progressive writing of data.  For nodes containing binary data in the form
   143 	of BinaryDataContainer, FileContainer or ChunkContainer, the client can
   144 	implement custom serialization by implementing the MXmlEngDataSerializer
   145 	interface and saving a pointer to the customer serializer in the
   146 	iDataSerializer member of the aSaveOptions parameter. If no custom
   147 	serialization is specified, the binary data container nodes are serialized
   148 	like text nodes.
   149 
   150 	If no aRoot is provided, the entire DOM tree is serialized.  aRoot does not
   151 	need to be owned by this document.
   152     
   153 	@param aStream  An output stream to write the serialized DOM tree
   154  	@param aRoot Root node to be serialized	
   155 	@param aSaveOptions Options that control how serialization is performed 
   156     @return Number of bytes written
   157 	@leave KXmlEngErrWrongEncoding Encoding not understood
   158 	@leave KXmlEngErrWrongUseOfAPI Document is NULL
   159     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
   160 	@leave - One of the system-wide error codes
   161     */
   162     IMPORT_C TInt SaveL( MXmlEngOutputStream& aStream,
   163 						 TXmlEngNode aRoot = TXmlEngNode(),
   164 						 const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions() ) const;
   165 
   166     /**
   167     Saves document tree into memory buffer.
   168 
   169 	Any existing contents in aBuffer will be deleted.  The memory required for
   170 	aBuffer will be allocated by this method.  The method caller must Close()
   171 	aBuffer.
   172 
   173 	If no aRoot is provided, the entire DOM tree is serialized.  aRoot does not
   174 	need to be owned by this document.
   175     
   176 	@param aBuffer Resulting buffer
   177     @param aRoot The root of the subtree to serialize
   178     @param aSaveOptions Options that control how serialization is performed
   179     @return Size of buffer 
   180 	@leave KXmlEngErrWrongEncoding Encoding not understood
   181 	@leave KXmlEngErrWrongUseOfAPI Document is NULL
   182     @leave KXmlEngErrNegativeOutputSize The data to be serialized has a negative size
   183 	@leave - One of the system-wide error codes
   184     */
   185     IMPORT_C TInt SaveL(RBuf8& aBuffer, 
   186     					TXmlEngNode aRoot = TXmlEngNode(), 
   187                         const TXmlEngSerializationOptions& aSaveOptions = TXmlEngSerializationOptions()) const;
   188    
   189 	/**
   190 	Creates a complete copy of the document and transfers ownership to the
   191 	caller.  The caller is required to call Close() on the new document.  The
   192 	new document is independant from this document and this document may be
   193 	changed or closed without affecting the new document.
   194 
   195 	@return Complete copy of the document 
   196 	@leave - One of the system-wide error codes
   197     */
   198 	IMPORT_C RXmlEngDocument CloneDocumentL() const;
   199 
   200 	/**
   201 	Creates a new element from a specific namespace to be the root of the
   202 	document tree.  Any existing document element of the document is destroyed.
   203     
   204 	@param aName Element name
   205     @param aNamespaceUri Element namespace URI
   206     @param aPrefix Element namemespace prefix
   207     @return The new root element
   208 	@leave KXmlEngErrWrongUseOfAPI No name has been specified
   209 	@leave - One of the system-wide error codes
   210     */
   211     IMPORT_C TXmlEngElement CreateDocumentElementL(const TDesC8& aName, 
   212                                              const TDesC8& aNamespaceUri = KNullDesC8, 
   213                                              const TDesC8& aPrefix = KNullDesC8);
   214 
   215 	/**
   216 	Replaces (and destroys) the document element.  
   217 
   218 	Note:  Use TXmlEngElement::ReconcileNamespacesL() on the new document
   219 	element if it or its descendants can contain references to namespace
   220 	declarations outside of the element.
   221     
   222 	@param aNewDocElement New document element
   223     @see TXmlEngElement::ReconcileNamespacesL()
   224     */
   225     IMPORT_C void SetDocumentElement(TXmlEngElement aNewDocElement);
   226 
   227     /**
   228     Get document encoding.
   229 	@return Encoding of the source XML data or TPtrC8("") if none.
   230     */
   231     IMPORT_C TPtrC8 XmlEncoding() const;
   232 
   233     /**
   234     Get xml version
   235 	@return Version number reported by the XML declaration or TPtrC8("") if none.
   236     */
   237     IMPORT_C TPtrC8 XmlVersion() const;
   238   
   239     /**
   240     Retrieves base URI (if defined) of the document
   241 	@return Document URI or TPtrC8("") if none.
   242     */
   243     IMPORT_C TPtrC8 DocumentUri() const;
   244 
   245     /**
   246     Check if document is standalone
   247 	@return ETrue if standalone="true" was specified in the XML declaration in
   248 	the source XML file.
   249     */
   250 	IMPORT_C TBool IsStandalone() const;
   251 
   252     /**
   253     Sets XML version number to be shown in XML declaration when document is serialized.
   254 	@param aVersion Version string
   255 	@leave - One of the system-wide error codes
   256     */
   257     IMPORT_C void  SetXmlVersionL(const TDesC8& aVersion);
   258 
   259 	/**
   260 	Sets the location of the document.  The document's URI is used as the
   261 	top-level base URI definition.
   262 	@param aUri Document URI
   263 	@leave - One of the system-wide error codes
   264     */
   265     IMPORT_C void  SetDocumentUriL(const TDesC8& aUri);
   266 
   267     /** 
   268 	Sets "standalone" attribute of XML declaration for the document
   269 	@param aStandalone Is the document standalone
   270     */
   271     IMPORT_C void  SetStandalone(TBool aStandalone);
   272 
   273     /** 
   274 	Get the DOM implementation.  Ownership is not transferred.  Any operation
   275 	on the returned object will affect this document directly, in particular, 
   276 	a call to RXmlEngDOMImplementation::Close() will cause further operations
   277 	on this document to fail.
   278 
   279 	@return Object that represents current DOM implementation
   280     */
   281     IMPORT_C RXmlEngDOMImplementation Implementation() const;
   282     
   283     /**
   284     Get the document element
   285 	@return The document element -- the top-most element in the document tree
   286     */
   287     IMPORT_C TXmlEngElement DocumentElement() const;
   288 
   289 	/**
   290 	Sets the "document" property on the node and all its descendants to be this
   291 	RXmlEngDocument node 
   292 	@param aSource Node that should be added.
   293     @return Adopted node
   294 	@leave KXmlEngErrWrongUseOfAPI The node has a parent node, the node is
   295 	already owned by this document, or the node is a document.
   296 	@leave - One of the system-wide error codes
   297     */
   298     IMPORT_C TXmlEngNode AdoptNodeL(TXmlEngNode aSource);
   299 
   300     /**
   301     Creates a new attribute.
   302 
   303 	aValue should represent the correct value of an attribute if it is put
   304 	as-is into an XML file (with all characters correctly escaped with entity
   305 	references when XML spec requires)
   306     
   307 	The TXmlEngElement class provides a rich set of attribute creation methods,
   308 	which not only create attributes but also link them into elements.
   309     
   310 	@see TXmlEngElement
   311     
   312     There is no way to create attributes with namespaces (despite the DOM spec); 
   313     you have to use one of the TXmlEngElement::AddNewAttributeL(..) methods instead
   314 
   315 	The returned attribute is the only reference to the allocated memory until
   316 	you have attached the attribute to some element node.
   317 
   318 	@param aName Name of the atribute; no prefix allowed
   319     @param aValue Value of the attribute (optional)
   320     @return The newly created attribute 
   321 	@leave KXmlEngErrWrongUseOfAPI No name specified
   322 	@leave - One of the system-wide error codes
   323     */
   324     IMPORT_C TXmlEngAttr CreateAttributeL(const TDesC8& aName,
   325                                     const TDesC8& aValue = KNullDesC8);
   326 
   327     /**
   328     Creates a new text node and copies the content string into it.
   329 	@param aCharacters Text node content
   330     @return The created node
   331 	@leave - One of the system-wide error codes
   332     */
   333     IMPORT_C TXmlEngTextNode CreateTextNodeL(const TDesC8& aCharacters = KNullDesC8);
   334 
   335 	/**
   336 	Creates a new binary container and copies the specified cid and data into
   337 	it.  A pointer to the container is stored in the document's data container
   338 	list that can be fetched using GetDataContainerList().
   339 
   340     @see GetDataContainerList( RArray<TXmlEngDataContainer>& aList )
   341 	@param aCid Content identifier     
   342 	@param aData Binary octets
   343     @return The new binary container
   344 	@leave - One of the system-wide error codes
   345     */
   346     IMPORT_C TXmlEngBinaryContainer CreateBinaryContainerL( const TDesC8& aCid,
   347     												  const TDesC8& aData );
   348 
   349 	/**
   350 	Creates a new chunk container and copies the specified cid into it.  A
   351 	reference to a memory chunk is stored in the container.  The memory chunk
   352 	must stay in scope for the lifetime of the container.  A pointer to the
   353 	container is stored in the document's data container list that can be
   354 	fetched using GetDataContainerList().
   355 
   356     @see GetDataContainerList( RArray<TXmlEngDataContainer>& aList )     
   357 	@param aCid Content identifier 
   358 	@param aChunk RChunk reference
   359 	@param aChunkOffset Offset to the binary data in aChunk
   360 	@param aDataSize Size of binary data in aChunk
   361     @return The new chunk container
   362 	@leave - One of the system-wide error codes
   363     */
   364     IMPORT_C TXmlEngChunkContainer CreateChunkContainerL( const TDesC8& aCid, 
   365     												const RChunk& aChunk,
   366 					                                const TInt aChunkOffset,
   367 					                                const TInt aDataSize );
   368 
   369 	/**
   370 	Creates a new file container and copies the specified cid into it.  A
   371 	reference to a file is stored in the container.  aFile must stay in scope
   372 	of the lifetime of the container.  A pointer to the container is stored in
   373 	the document's data container list that can be fetched using
   374 	GetDataContainerList().
   375 
   376     @see GetDataContainerList( RArray<TXmlEngDataContainer>& aList )     
   377 	@param aCid Content identifier
   378 	@param aFile The file to reference
   379     @return The new file container
   380 	@leave - One of the system-wide error codes
   381     */
   382     IMPORT_C TXmlEngFileContainer CreateFileContainerL( const TDesC8& aCid, 
   383     											  const RFile& aFile );
   384 
   385 	/**
   386 	Creates a new element node that belongs to the specific namespace.  A
   387 	namespace declaration node is created on the element.
   388 
   389 	If the provided namespace uri is NULL, the element will be created without
   390 	namespace.
   391 
   392 	@param aNamespaceUri Namespace of new element
   393     @param aPrefix Prefix to use for the namespace binding and the QName of the element
   394     @param aLocalName Local name of the element 
   395     @return The created element
   396 	@leave KXmlEngErrWrongUseOfAPI No name specified
   397 	@leave - One of the system-wide error codes
   398     */  
   399     IMPORT_C TXmlEngElement CreateElementL(const TDesC8& aLocalName, 
   400                                      const TDesC8& aNamespaceUri = KNullDesC8, 
   401                                      const TDesC8& aPrefix = KNullDesC8);
   402 
   403     /**
   404 	Creates a new comment node and copies the specified string into it.
   405 	@param aText New comment
   406     @return The created node
   407 	@leave - One of the system-wide error codes
   408     */
   409     IMPORT_C TXmlEngComment CreateCommentL(const TDesC8& aText = KNullDesC8);
   410 
   411     /**
   412 	Creates a new CDATA section node and copies the specified string into it.
   413 	@param aContents CDATASection content
   414     @return The created node
   415 	@leave - One of the system-wide error codes
   416     */
   417     IMPORT_C TXmlEngCDATASection CreateCDATASectionL(const TDesC8& aContents = KNullDesC8);
   418 
   419     /**
   420 	Creates a new entity reference node and copies the specified string into
   421 	it.
   422 
   423 	Note:  &lt; , &gt; , &apos; , &quot; and other predefined entity references
   424 	should not be created with this method. These entity references are rather
   425 	"character references" and are encoded/decoded automatically.
   426 
   427 	@param aEntityRef is a string in one of these forms:
   428         -  name
   429         -  &name
   430         -  &name;
   431     where name is the name of the entity
   432     @return The new entity reference
   433 	@leave KXmlEngErrWrongUseOfAPI No entity specified
   434 	@leave - One of the system-wide error codes
   435     */
   436     IMPORT_C TXmlEngEntityReference CreateEntityReferenceL(const TDesC8& aEntityRef);
   437 
   438     /**
   439     Creates a new empty Document Fragment node.  The document fragment is owned by
   440 	this document.
   441 	@return The created document fragment
   442 	@leave - One of the system-wide error codes
   443     */
   444     IMPORT_C TXmlEngDocumentFragment CreateDocumentFragmentL();
   445 
   446 	/**
   447 	Creates a new processing instruction node and copies "target" and "data"
   448 	into it.
   449 	
   450 	@param aTarget Target
   451     @param aData Data
   452     @return The created processing instruction
   453 	@leave KXmlEngErrWrongUseOfAPI No target specified
   454 	@leave - One of the system-wide error codes
   455     */
   456     IMPORT_C TXmlEngProcessingInstruction CreateProcessingInstructionL(const TDesC8& aTarget, 
   457                                                                  const TDesC8& aData = KNullDesC8);
   458                                                                  
   459 	/**
   460 	Sets the specified attribute as a xml:id attribute, starting at
   461 	aStartElement and recursing through the subtree.  To set the specified
   462 	attribute as a xml:id attribute for the entire DOM tree, see
   463 	RegisterXmlId(const TDesC8&,const TDesC8&).
   464 
   465     @param aStartElement Root of the subtree to recurse
   466     @param aLocalName Name of the attribute
   467 	@param aNamespaceUri Namespace of the new element (default empty)
   468 	@leave KXmlEngErrWrongUseOfAPI The starting element is NULL, the attribute
   469 	name is not specified, the starting element is the document, or the
   470 	starting element does not belong to a document.
   471 	@leave KErrAlreadyExists The attribute is already set to be xml:id
   472 	@leave - One of the system-wide error codes
   473     */
   474     IMPORT_C void RegisterXmlIdL(TXmlEngElement aStartElement,
   475                                  const TDesC8& aLocalName, 
   476                                  const TDesC8& aNamespaceUri = KNullDesC8);
   477 
   478 	/**
   479 	Sets the specified attribute as a xml:id attribute, recursing through the
   480 	entire DOM tree.  In order to specify a subtree only, see
   481 	RegisterXmlId(TXmlEngElement,const TDesC8,const TDesC8).
   482 
   483     @param aLocalName Name of attribute
   484 	@param aNamespaceUri Namespace of new element (default empty)
   485 	@leave KXmlEngErrWrongUseOfAPI The document is NULL
   486 	@leave KErrAlreadyExists The attribute is already set to be xml:id
   487 	@leave - One of the system-wide error codes
   488     */
   489     IMPORT_C void RegisterXmlIdL(const TDesC8& aLocalName, 
   490                                  const TDesC8& aNamespaceUri = KNullDesC8);
   491        
   492     /**
   493     Looks for an element with the specified xml:id attribute
   494 	@param aValue Name of attribute
   495     @return The found element or a NULL element if not found
   496 	@leave - One of the system-wide error codes
   497     */
   498     IMPORT_C TXmlEngElement FindElementByXmlIdL(const TDesC8& aValue ) const;  
   499 
   500     /**
   501     Retrieves an array of data containers owned by this document.
   502 
   503 	Note: The document ceases to be the owner of a data container when the data
   504 	container (or one of its predecessors) is removed from the document or
   505 	becomes part of another document.  Unlinking a data container (or one of its
   506 	predecessors) doesn't remove ownership of the data container from this
   507 	document so the list might contain containers that are not linked to this
   508 	document anymore.    
   509 
   510 	@param aList Array of data containers
   511 	@return KErrNone if successful or one of the system wide error codes otherwise
   512     */
   513     IMPORT_C TInt GetDataContainerList( RArray<TXmlEngDataContainer>& aList );
   514                                                                  
   515 protected:
   516     friend class RXmlEngDOMParser;
   517     friend class TXmlEngNode;
   518     friend class TXmlEngAttr;
   519     friend class TXmlEngElement;
   520     friend class RXmlEngDOMImplementation;
   521 
   522 protected:
   523     /**
   524     Constructor
   525 	@param aInternal Document pointer
   526 	*/
   527     inline RXmlEngDocument(void* aInternal);
   528 
   529     /**
   530     DISABLED for document; CloneDocumentL() must be used
   531 	*/
   532     inline TXmlEngNode CopyL() const; 
   533 
   534     /**
   535     DISABLED for document; Close() must be used
   536 	*/    
   537     inline void Remove();
   538 
   539     /**
   540     DISABLED for document; Close() must be used
   541 	*/ 
   542     inline void ReplaceWith(TXmlEngNode aNode);
   543     inline void ReplaceWithL(TXmlEngNode aNode);
   544     
   545     /**
   546     DISABLED for document; Close() must be used
   547 	 */ 
   548     inline TXmlEngNode SubstituteForL(TXmlEngNode aNode);
   549 
   550 private:
   551 	TInt SaveNodeL( TXmlEngNode aNode,
   552 					RBuf8& aBuffer,
   553                	    MXmlEngOutputStream* aOutputStream = NULL,
   554                	    TXmlEngSerializationOptions aOpt = TXmlEngSerializationOptions()) const;	
   555 
   556     void InitOwnedNodeListL();
   557     void TakeOwnership(TXmlEngNode aNode);
   558     void RemoveOwnership(TXmlEngNode aNode);
   559 
   560 protected:
   561     /**  Pointer to DOM implementation object */
   562     RXmlEngDOMImplementation* iImpl;
   563 
   564 };// class RXmlEngDocument
   565 
   566 
   567 
   568 #include <xml/dom/xmlengdocument.inl>
   569 
   570 #endif /* XMLENGDOCUMENT_H */