williamr@2: /* williamr@2: * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * 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: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: This is an optimized variant of XML element, which consumes williamr@2: * significantly less heap when compared to CSenBaseElement williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: #ifndef SEN_XML_ELEMENT_H williamr@2: #define SEN_XML_ELEMENT_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * Implementation of an XML element functionality williamr@2: * Content is stored in UTF-8 form XML. Note, that williamr@2: * setting any 8-bit content into XML without encoding williamr@2: * it into form of legal is illegal. Instead, one williamr@2: * should use encoding methods, like ones introduced williamr@2: * in SenXmlUtils class to encode basic entities, or williamr@2: * use use some other encoding like MD5 for binary williamr@2: * data content. williamr@2: * @lib SenXML.dll williamr@2: * @since Series60 3.1 williamr@2: */ williamr@2: class CSenXmlElement : public CSenElement williamr@2: { williamr@2: public: // Constructors and destructor williamr@2: williamr@2: /** williamr@2: * Standard constructor. williamr@2: * @param aLocalName the local name for this element. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: williamr@2: IMPORT_C static CSenXmlElement* NewL(const TDesC8& aLocalName); williamr@2: /** williamr@2: * Standard constructor. williamr@2: * @param aNsUri the namespace URI for this element. williamr@2: * @param aLocalName the local name for this element. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Standard constructor. williamr@2: * @param aNsUri the namespace URI for this element. williamr@2: * @param aLocalName the local name for this element. williamr@2: * @param aQName the qualified name for this element. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contains williamr@2: * illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName); williamr@2: williamr@2: /** williamr@2: * Standard constructor. williamr@2: * @param aNsUri the namespace URI for this element. williamr@2: * @param aLocalName the local name for this element. williamr@2: * @param aQName the qualified name for this element. williamr@2: * @param apAttrs the attributes for this element. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contains williamr@2: * illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName, williamr@2: const RAttributeArray& apAttrs); williamr@2: williamr@2: /** williamr@2: * Standard constructor. williamr@2: * @param aNsUri the namespace URI for this element. williamr@2: * @param aLocalName the local name for this element. williamr@2: * @param aQName the qualified name for this element. williamr@2: * @param apAttrs the attributes for this element. williamr@2: * @param aParent: the parent element for the new element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contains williamr@2: * illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: IMPORT_C static CSenXmlElement* NewL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName, williamr@2: const RAttributeArray& apAttrs, williamr@2: CSenElement& aParent); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: */ williamr@2: IMPORT_C virtual ~CSenXmlElement(); williamr@2: williamr@2: public: // New functions williamr@2: williamr@2: /** williamr@2: * Adds attributes to the element. Calls internally AddAttributesL() williamr@2: * Can be overridden to replace old attributes. williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: IMPORT_C virtual void SetAttributesL(const RAttributeArray& apAttrs); williamr@2: williamr@2: // Functions from base classes williamr@2: williamr@2: // From CSenElement williamr@2: williamr@2: /** williamr@2: * Getter for Element's local name. williamr@2: * @return Localname or KNullDesC if not set. williamr@2: */ williamr@2: IMPORT_C virtual const TDesC8& LocalName() const; williamr@2: williamr@2: /** williamr@2: * Getter for Element's namespace URI. williamr@2: * @return Namespace URI or KNullDesC if not set. williamr@2: */ williamr@2: IMPORT_C virtual const TDesC8& NamespaceURI() const; williamr@2: williamr@2: /** williamr@2: * Getter for namespace prefix of this element. williamr@2: * @return namespace prefix or KNullDesC if not set. williamr@2: */ williamr@2: IMPORT_C virtual const TDesC8& NsPrefix() const; williamr@2: williamr@2: /** williamr@2: * Setter for namespace prefix of this element. williamr@2: * @param aPrefix: new namespace prefix for the element. williamr@2: */ williamr@2: IMPORT_C virtual void SetPrefixL(const TDesC8& aPrefix); williamr@2: williamr@2: /** williamr@2: * Method for checking if the element has any content within. williamr@2: * @return ETrue if has content, EFalse if not. williamr@2: */ williamr@2: IMPORT_C virtual TBool HasContent() const; williamr@2: williamr@2: /** williamr@2: * Getter for the content of the element. williamr@2: * @return the content or KNullDesC if empty. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 Content() const; williamr@2: williamr@2: /** williamr@2: * Getter for the content of the element, unicode version. williamr@2: * @return content as unicode. Ownership IS TRANSFERRED to the caller. williamr@2: */ williamr@2: IMPORT_C virtual HBufC* ContentUnicodeL() const; williamr@2: williamr@2: /** williamr@2: * Sets the content to the element. Old content is overwritten. williamr@2: * @param aContent: The content to be set. Can be KNullDesC8. williamr@2: * @return The content of the element or KNullDesC8 if no content was set. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 SetContentL(const TDesC8& aContent); williamr@2: williamr@2: /** williamr@2: * Gets the write stream for the content for easy appending. williamr@2: * Writing 8-bit (UTF-8) string to the returned stream will be appended williamr@2: * to the content. williamr@2: * @return reference to the RWriteStream. williamr@2: */ williamr@2: IMPORT_C virtual RWriteStream& ContentWriteStreamL(); williamr@2: williamr@2: /** williamr@2: * Checks if element matches to another element williamr@2: * by its content and child elements. Element williamr@2: * can contain more data than the given pattern. williamr@2: * @since Series60 3.0 williamr@2: * @param aCandidate The pattern to be matched. Must contain same or williamr@2: * less data for match to come true. williamr@2: * @return ETrue if content and possible children match exactly williamr@2: * to given pattern. EFalse otherwise. williamr@2: */ williamr@2: IMPORT_C virtual TBool ConsistsOfL(MSenElement& aCandidate); williamr@2: williamr@2: /** williamr@2: * Setter for Element's namespace URI. williamr@2: * @param aNsUri: Namespace URI williamr@2: */ williamr@2: IMPORT_C virtual void SetNamespaceL(const TDesC8& aNsUri); williamr@2: williamr@2: /** williamr@2: * Setter for Element's namespace URI. williamr@2: * @param aNsPrefix: Namespace prefix williamr@2: * @param aNsUri: Namespace URI williamr@2: */ williamr@2: IMPORT_C virtual void SetNamespaceL(const TDesC8& aNsPrefix, williamr@2: const TDesC8& aNsUri); williamr@2: williamr@2: /** williamr@2: * Adds a namespace declaration. williamr@2: * If this element (or its parent if parameter aCheckInParent is ETrue) williamr@2: * already has a Namespace with the same prefix and URI the given williamr@2: * Namespace is not added. williamr@2: * @param aNewNamespace williamr@2: * @param aCheckInParent williamr@2: * @return the added Namespace, or the equivalent pre-existing one. williamr@2: */ williamr@2: IMPORT_C virtual const CSenNamespace* AddNamespaceL(CSenNamespace& aNewNamespace, williamr@2: TBool aCheckInParent); williamr@2: /** williamr@2: * Method for adding a namespace for the Element. williamr@2: * @param aPrefix: Namespace prefix williamr@2: * @param aUri: Namespace URI williamr@2: * @return the added Namespace, or the equivalent pre-existing one. williamr@2: */ williamr@2: IMPORT_C virtual const CSenNamespace* AddNamespaceL(const TDesC8& aPrefix, williamr@2: const TDesC8& aUri); williamr@2: /** williamr@2: * Getter for Element's namespace. williamr@2: * @return const pointer to the CSenNamespace object of this Element. williamr@2: * NULL if not set. williamr@2: */ williamr@2: IMPORT_C virtual const CSenNamespace* Namespace(); williamr@2: williamr@2: /** williamr@2: * Getter for new namespace, using a namespace prefix as a search criteria. williamr@2: * @param aNsPrefix is the new namespace prefix for this element williamr@2: * @return the found Namespace that is declared for the given prefix williamr@2: * within the scope of this Element. If no such prefix is williamr@2: * declared return null. williamr@2: */ williamr@2: IMPORT_C virtual const CSenNamespace* Namespace(const TDesC8& aNsPrefix); williamr@2: williamr@2: /** williamr@2: * Getter for new namespace, using a namespace prefix as a search criteria, williamr@2: * supporting both normal and recursive search mode (checking the parent). williamr@2: * @param aNsPrefix: The prefix used to search williamr@2: * @param aCheckInParent: The flag indicating whether to check parent's williamr@2: * namespaces too if not found in the current williamr@2: * element. williamr@2: * ETrue to check, EFalse for not to check. williamr@2: * @return the found Namespace that is declared for the given prefix williamr@2: * and namespace URI within the scope of this Element williamr@2: * or NULL if not found williamr@2: */ williamr@2: IMPORT_C virtual const CSenNamespace* Namespace(const TDesC8& aNsPrefix, williamr@2: const TBool aCheckInParent); williamr@2: williamr@2: /** williamr@2: * Getter for new namespace, using both namespace prefix and namespace URI as search criteria. williamr@2: * @param aNsPrefix: The prefix used to search williamr@2: * @param aUri: The namespace URI used to search. williamr@2: * @return the found Namespace that is declared for the given prefix williamr@2: * and namespace URI within the scope of this Element williamr@2: * or NULL if not found. williamr@2: */ williamr@2: IMPORT_C virtual const CSenNamespace* Namespace(const TDesC8& aNsPrefix, williamr@2: const TDesC8& aUri); williamr@2: williamr@2: /** williamr@2: * Getting the child elements of this element matching the given criteria. williamr@2: * @param aElementArray: Array to be filled with the matching elements, williamr@2: * or empty array if no matching found. williamr@2: * Any modifications made on the returned items williamr@2: * modify the real childs too. williamr@2: * @param aNsUri: namespace URI to be matched williamr@2: * @param aLocalName: local name to be matched williamr@2: * @return KErrNone ok williamr@2: * KErrNotFound No child elements exist. williamr@2: */ williamr@2: IMPORT_C virtual TInt ElementsL(RPointerArray& aElementArray, williamr@2: const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Getting the child elements of this element matching the given criteria. williamr@2: * @param aElementArray: Array to be filled with the matching elements, williamr@2: * or empty array if no matching found. williamr@2: * Any modifications made on the returned items williamr@2: * modify the real childs too. williamr@2: * @param aNsUri: namespace URI to be matched williamr@2: * @param aLocalName: local name to be matched williamr@2: * @return KErrNone ok williamr@2: * KErrNotFound No child elements exist. williamr@2: */ williamr@2: IMPORT_C virtual TInt ElementsL(RPointerArray& aElementArray, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Getting the child elements of this element. williamr@2: * @return an array of child elements. This is an empty array if there williamr@2: * are no children. Any modifications made on the returned array williamr@2: * modify the element object. williamr@2: */ williamr@2: IMPORT_C virtual RPointerArray& ElementsL(); williamr@2: williamr@2: /** williamr@2: * Gets all the attributes of this element in an array. williamr@2: * @return array of attributes. Array will be empty if element has williamr@2: * no attributes. williamr@2: */ williamr@2: IMPORT_C virtual RPointerArray& AttributesL(); williamr@2: williamr@2: /** williamr@2: * Gets all the namespaces of this element in an array. williamr@2: * @return array of namespaces. Array will be empty if element has williamr@2: * no namespaces. williamr@2: */ williamr@2: IMPORT_C virtual RPointerArray& NamespacesL(); williamr@2: williamr@2: /** williamr@2: * Gets the value of the given attribute. williamr@2: * @param aName: Name of the attribute in question. williamr@2: * @return the value of the attribute, or NULL if not found. Ownership is williamr@2: * NOT TRANSFERRED. williamr@2: */ williamr@2: IMPORT_C virtual const TDesC8* AttrValue(const TDesC8& aName); williamr@2: williamr@2: /** williamr@2: * Adds an attribute. If attribute is already existing, williamr@2: * the value of the attribute will be replaced. williamr@2: */ williamr@2: IMPORT_C virtual void AddAttrL(const TDesC8& aName, const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Gets the parent element of this element. williamr@2: * @return the parent element or NULL if no parent set. williamr@2: * Ownership is NOT transferred to the caller. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* Parent(); williamr@2: williamr@2: /** williamr@2: * Sets the parent element to this element. Notice that the element is not williamr@2: * automatically added as a child of the parent. Parent's williamr@2: * AddElementL() should be called instead. williamr@2: * @param apParent: The wanted parent. Can be NULL. williamr@2: * @return the parent element williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* SetParent(CSenElement* apParent); williamr@2: williamr@2: /** williamr@2: * Gets the root element. If no parent element, returns this element. williamr@2: * @return the root of the tree. Ownership is NOT transferred. williamr@2: */ williamr@2: IMPORT_C virtual MSenElement& Root(); williamr@2: williamr@2: /** williamr@2: * Gets the child element with the specified local name. williamr@2: * Assumes that namespace is the same as this parent element. williamr@2: * @return the child element or NULL if the child with the specified williamr@2: * local name is not found. Ownership is NOT transferred. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* Element(const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Gets the child element with the specified local name and namespace URI. williamr@2: * @return the child element or NULL if the child with the specified williamr@2: * criterias is not found. Ownership is NOT transferred. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* Element(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Create a new element ready for adding or insertion. williamr@2: * If the given namespace prefix is not declared yet williamr@2: * the element will not be created and NULL will be returned. williamr@2: * @param aNsPrefix: The namespace prefix williamr@2: * @param aLocalName: The new elements localname williamr@2: * @return the new Element just created, or NULL if given prefix was not williamr@2: * declared yet. Ownership is transferred to the caller. williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* CreateElementL(const TDesC8& aNsPrefix, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Insert an Element into the list of children elements williamr@2: * so that the inserted Element is placed right before the aBeforeElement. williamr@2: * If aBeforeElement is not found, element will be appended to the last williamr@2: * position. williamr@2: * Function leaves if error occurs in inserting. williamr@2: * @param aInsertedElement: the element to be inserted. williamr@2: * Ownership is transferred. williamr@2: * @param aBeforeElement: the element which will be right next to the williamr@2: * element just inserted. williamr@2: * @return the inserted Element williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& InsertElementL(CSenElement& aElement, williamr@2: const CSenElement& aBeforeElement); williamr@2: williamr@2: /** williamr@2: * Adds an Element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * @param aElement: the element to be added. Ownership is transferred. williamr@2: * @return the added Element williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& AddElementL(CSenElement& aElement); williamr@2: williamr@2: /** williamr@2: * Constructs and adds a new element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * @param aNsUri: namespace URI of the new element williamr@2: * @param aLocalName: local name of the new element williamr@2: * @return the added Element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& AddElementL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Constructs and adds a new element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * @param aNsUri: namespace URI of the new element williamr@2: * @param aLocalName: local name of the new element williamr@2: * @param aQName: qualified name of the new element williamr@2: * @return the added Element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contain illegal williamr@2: * characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& AddElementL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName); williamr@2: williamr@2: /** williamr@2: * Constructs and adds a new element to the children elements. williamr@2: * Sets this element to be the new parent of the given element. williamr@2: * Note: Element is created with no specific namespace, default namespace williamr@2: * of some of the upper level elements are in effect if there is such a williamr@2: * namespace. williamr@2: * @param aLocalName: local name of the new element williamr@2: * @return the added Element williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName is zero length. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement& AddElementL(const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Remove an element from the childs. williamr@2: * @param aElement: the element to be removed. williamr@2: * @return The removed element. May be NULL if nothing was removed williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the removed element. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* RemoveElement(CSenElement& aElement); williamr@2: williamr@2: /** williamr@2: * Remove an element from the childs. williamr@2: * @param aNsUri: the namespace URI of the element to be removed. williamr@2: * @param aLocalName: the local name of the element to be removed. williamr@2: * @return The removed element. May be NULL if nothing was removed williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the removed element. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* RemoveElement(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Remove an element from the childs. williamr@2: * @param aLocalName: the local name of the element to be removed. williamr@2: * @return The removed element. May be NULL if nothing was removed williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the removed element. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* RemoveElement(const TDesC8& aLocalName); williamr@2: williamr@2: /** williamr@2: * Replaces an element from the childs with another element. williamr@2: * Element's local name and namespace URI will be used to match the williamr@2: * element to be replaced. If matching element is not found, will williamr@2: * normally add the given element to the childs. williamr@2: * @param aElement: the element to be added. Ownership is transferred. williamr@2: * @return The old element. May be NULL if nothing was replaced williamr@2: * (if element was not found from the childs). williamr@2: * The caller TAKES OWNERSHIP of the old element. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* ReplaceElementL(CSenElement& aElement); williamr@2: williamr@2: /** williamr@2: * Gets the element as an XML buffer. Buffer will contain all the childs williamr@2: * @return element as XML. Caller takes ownership. williamr@2: */ williamr@2: IMPORT_C virtual HBufC8* AsXmlL(); williamr@2: williamr@2: /** williamr@2: * Gets the element as an unicode XML buffer. williamr@2: * Buffer will contain all the childs etc. williamr@2: * @return element as XML. Caller takes ownership. williamr@2: */ williamr@2: IMPORT_C virtual HBufC* AsXmlUnicodeL(); williamr@2: williamr@2: /** williamr@2: * Element writes itself to a write stream using UTF-8 charset encoding. williamr@2: * @param aWriteStream: The stream to write to. williamr@2: */ williamr@2: IMPORT_C virtual void WriteAsXMLToL(RWriteStream& aWriteStream); williamr@2: williamr@2: /** williamr@2: * Element writes its namespaces to a write stream using UTF-8 charset williamr@2: * encoding. williamr@2: * @param aWriteStream: The stream to write to. williamr@2: */ williamr@2: IMPORT_C virtual void WriteNamespacesToL(RWriteStream& aWriteStream); williamr@2: williamr@2: /** williamr@2: * Gets the current element as XML element. Mostly used to get the williamr@2: * classes which implement this interface as an instance of this williamr@2: * interface. williamr@2: * @return the current object as element. Ownership is NOT transferred. williamr@2: */ williamr@2: IMPORT_C virtual MSenElement* AsElement(); williamr@2: williamr@2: /** williamr@2: * Copies content from given element to this element appending to the williamr@2: * existing content if there is any. williamr@2: * @param aSource: The source element. williamr@2: */ williamr@2: IMPORT_C void CopyFromL(CSenElement& aSource); williamr@2: williamr@2: /** williamr@2: * Detach the element from its parent. williamr@2: * If the element, or one of its children, is dependent williamr@2: * on a namespace declared in the scope of the parent williamr@2: * copy those namespace declarations to this element. williamr@2: * @return this Element. Ownership IS TRANSFERRED to the caller. williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* DetachL(); williamr@2: williamr@2: /** williamr@2: * Gets a child element from a specified index. williamr@2: * @param aIndex: the index what to get williamr@2: * @return child element from a current index. NULL if no child in given williamr@2: * index is found williamr@2: */ williamr@2: IMPORT_C virtual CSenElement* Child(TInt aIndex); williamr@2: williamr@2: /** williamr@2: * (Re-) Set the name and namespace of this Element. The element will be williamr@2: * given the localName in the the given namespace. A prefix will be williamr@2: * computed from the qualified name. williamr@2: * This method should be used with care and is mainly intended for williamr@2: * protected use in implementations. williamr@2: * @param aNamespaceURI: The new namespace URI. williamr@2: * @param aLocalName: The new local name. williamr@2: * @param aQName: The new qualified name. williamr@2: */ williamr@2: IMPORT_C virtual void Set(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName); williamr@2: williamr@2: /** williamr@2: * Adds new attributes to the element. williamr@2: * @param aAttrs: the array of attributes. williamr@2: */ williamr@2: IMPORT_C virtual void AddAttributesL(const RAttributeArray& apAttrs); williamr@2: williamr@2: void Compress(); williamr@2: williamr@2: protected: // New functions williamr@2: williamr@2: /** williamr@2: * C++ default constructor. williamr@2: */ williamr@2: IMPORT_C CSenXmlElement(); williamr@2: williamr@2: /** williamr@2: * Following BaseConstructL methods should be called from the deriving williamr@2: * classes ConstructL() methods. Parameter info is found in the williamr@2: * corresponding NewL-methods. williamr@2: */ williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aLocalName); williamr@2: williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName); williamr@2: williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName); williamr@2: williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName, williamr@2: const RAttributeArray& apAttrs); williamr@2: williamr@2: IMPORT_C void BaseConstructL(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aQName, williamr@2: const RAttributeArray& apAttrs, williamr@2: CSenElement& aParent); williamr@2: williamr@2: /** williamr@2: * Method for finding an attribute with given name. williamr@2: * @param aName a name of the attribute to be searched for williamr@2: * @return the 1st attribute with the name, or NULL. williamr@2: * Ownership is not transferred. williamr@2: */ williamr@2: IMPORT_C virtual CSenBaseAttribute* FindAttr(const TDesC8& aName); williamr@2: williamr@2: /** williamr@2: * Method for finding index for a wanted element. williamr@2: * @param aNsUri a namespace URI which needs to match williamr@2: * @param aLocalName a local name which needs to match williamr@2: * @return Index of the element with given characteristics. williamr@2: * or KErrNotFound if none matching williamr@2: */ williamr@2: IMPORT_C virtual TInt IndexOfElement(const TDesC8& aNsUri, williamr@2: const TDesC8& aLocalName) const; williamr@2: williamr@2: /** williamr@2: * Writes element's attributes into a writestream. williamr@2: * @param aWriteStream writestream to write into williamr@2: */ williamr@2: IMPORT_C virtual void WriteAttrsToL(RWriteStream& aWriteStream); williamr@2: williamr@2: /** williamr@2: * Helper function to write an attribute into a writestream. williamr@2: * @param aWriteStream writestream to write into williamr@2: * @param aName attribute name williamr@2: * @param aValue attribute value williamr@2: */ williamr@2: IMPORT_C virtual void WriteAttrToL(RWriteStream& aWriteStream, williamr@2: const TDesC8& aName, williamr@2: const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Writes all internal elements into a writestream. williamr@2: * @param aWriteStream writestream to write into williamr@2: */ williamr@2: IMPORT_C virtual void WriteElementsToL(RWriteStream& aWriteStream); williamr@2: williamr@2: /** williamr@2: * Writes all element's content into a writestream. williamr@2: * @param aWriteStream writestream to write into williamr@2: */ williamr@2: IMPORT_C virtual void WriteContentToL(RWriteStream& aWriteStream); williamr@2: williamr@2: /** williamr@2: * Adds an attribute into this element. Used also adding new namespaces williamr@2: * into the element. williamr@2: * @param aQName Attribute's qualified name williamr@2: * @param aLocalName Attribute's local name williamr@2: * @param aValue Attribute's value williamr@2: * @return value of the attribute as string (TDesC&) williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName or aQName contain illegal williamr@2: * characters. williamr@2: * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length. williamr@2: */ williamr@2: IMPORT_C virtual const TDesC8& AddAttributeL(const TDesC8& aQName, williamr@2: const TDesC8& aLocalName, williamr@2: const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Adds an attribute into this element. Used also adding new namespaces williamr@2: * into the element. williamr@2: * @param aLocalName Attribute's local name williamr@2: * @param aValue Attribute's value williamr@2: * @return value of the attribute as string (TDesC&) williamr@2: * Leave codes: williamr@2: * KErrSenInvalidCharacters if aLocalName contains illegal characters. williamr@2: * KErrSenZeroLengthDescriptor if aAttrName is zero length, or williamr@2: * if the local name part of it is zero length. williamr@2: */ williamr@2: IMPORT_C virtual const TDesC8& AddAttributeL(const TDesC8& aAttrName, williamr@2: const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Adds an attribute into this element. williamr@2: * @param apAttribute Attribute to be added. Ownership is transferred williamr@2: * to this element. williamr@2: * @return attribute value as a string (TDesC8&) williamr@2: */ williamr@2: IMPORT_C const TDesC8& AddAttributeL(CSenBaseAttribute* apAttribute); williamr@2: williamr@2: /** williamr@2: * Allocates a new buffer for saving content, if none allocated yet. williamr@2: */ williamr@2: IMPORT_C virtual void AllocContentBufL(); williamr@2: williamr@2: /** williamr@2: * Writes element into a dynamic buffer. williamr@2: * @param aBuf a dynamic buffer where to append everything. williamr@2: * @return the modified buffer as TPtrC8. williamr@2: */ williamr@2: IMPORT_C virtual TPtrC8 WriteToBufL(CBufBase& aBuf); williamr@2: williamr@2: private: williamr@2: void AddNamespaceMissingFromL(RPointerArray& aNamespaces); williamr@2: williamr@2: private: // Data williamr@2: williamr@2: HBufC8* ipLocalName; // Owned williamr@2: williamr@2: CBufFlat* ipContentBuf; // Owned williamr@2: williamr@2: RBufWriteStream* ipContentWriteStream; // Owned williamr@2: williamr@2: RPointerArray* ipAttrs; // Elements owned williamr@2: williamr@2: RPointerArray* ipElements; // Elements owned williamr@2: williamr@2: RPointerArray* ipNamespaces; // Elements owned williamr@2: williamr@2: CSenElement* ipParent; // Not owned williamr@2: williamr@2: CSenNamespace* ipNamespace; // Not Owned (deleted in upper level array) williamr@2: williamr@2: }; williamr@2: williamr@2: #endif // SEN_XML_ELEMENT_H williamr@2: williamr@2: // End of File williamr@2: