2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: The abstract interface of an XML element
25 #ifndef M_SEN_ELEMENT_H
26 #define M_SEN_ELEMENT_H
31 #include <xml/Attribute.h>
33 // FORWARD DECLARATIONS
35 class CSenBaseAttribute;
43 * The abstract interface of an XML element
49 public: // New functions
52 * Getter for Element's local name.
53 * @return KNullDesC if not set
55 virtual const TDesC8& LocalName() const = 0;
58 * Getter for Element's namespace URI.
59 * @return Namespace URI or KNullDesC if not set.
61 virtual const TDesC8& NamespaceURI() const = 0;
64 * Setter for Element's namespace URI.
65 * @param aNsUri: Namespace URI
67 virtual void SetNamespaceL(const TDesC8& aNsUri) = 0;
70 * Setter for Element's namespace URI.
71 * @param aNsPrefix: Namespace prefix
72 * @param aNsUri: Namespace URI
74 virtual void SetNamespaceL( const TDesC8& aNsPrefix,
75 const TDesC8& aNsUri) = 0;
78 * Method for adding a namespace for the Element.
79 * @param aNsPrefix: Namespace prefix
80 * @param aNsUri: Namespace URI
81 * @return the added Namespace, or the equivalent pre-existing one.
83 virtual const CSenNamespace* AddNamespaceL( const TDesC8& aPrefix,
84 const TDesC8& aUri) = 0;
87 * Adds a namespace declaration.
88 * If this element (or its parent if parameter aCheckInParent is ETrue)
89 * already has a Namespace with the same prefix and URI the given
90 * Namespace is not added.
91 * @param aNewNamespace
92 * @param aCheckInParent
93 * @return the added Namespace, or the equivalent pre-existing one.
95 virtual const CSenNamespace* AddNamespaceL( CSenNamespace& aNewNamespace,
96 TBool aCheckInParent) = 0;
98 * Getter for Element's namespace.
99 * @return const pointer to the CSenNamespace object of this Element.
102 virtual const CSenNamespace* Namespace() = 0;
105 * Get namespace that is declared for the given prefix
106 * @param aNsPrefix: The prefix to be used in searching.
107 * @return the found Namespace that is declared for the given prefix
108 * within the scope of this Element or NULL if not found.
110 virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix) = 0;
113 * Get namespace that is declared for the given prefix and namespace
114 * URI within the scope of this Element.
116 * @param aNsPrefix: The prefix used to search
117 * @param aUri: The namespace URI used to search.
118 * @return the found Namespace that is declared for the given prefix and namespace
119 * URI within the scope of this Element or NULL if not found.
121 virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix,
122 const TDesC8& aUri) = 0;
125 * Get namespace that is declared for the given prefix and namespace
126 * URI within the scope of this Element.
128 * @param aNsPrefix: The prefix used to search
129 * @param aCheckInParent: The flag indicating whether to check parent's
130 * namespaces too if not found in the current
132 * ETrue to check, EFalse for not to check.
133 * @return the found Namespace that is declared for the given prefix and namespace
134 * URI within the scope of this Element or NULL if not found
136 virtual const CSenNamespace* Namespace( const TDesC8& aNsPrefix,
137 const TBool aCheckInParent) = 0;
140 * Getter for namespace prefix of this element.
141 * @return namespace prefix or KNullDesC8 if not set.
143 virtual const TDesC8& NsPrefix() const = 0;
146 * Setter for namespace prefix of this element.
147 * @param aPrefix: new namespace prefix for the element.
149 virtual void SetPrefixL(const TDesC8& aPrefix) = 0;
152 * Method for checking if the element has any content within.
153 * @return ETrue if has content, EFalse if not.
155 virtual TBool HasContent() const = 0;
158 * Getter for the content of the element.
159 * @return the content or KNullDesC8 if empty.
161 virtual TPtrC8 Content() const = 0;
164 * Getter for the content of the element, unicode version.
165 * @return content as unicode. Ownership IS TRANSFERRED to the caller.
167 virtual HBufC* ContentUnicodeL() const = 0;
170 * Sets the content to the element. Old content is overwritten.
171 * @param aContent: The content to be set. Can be KNullDesC8.
172 * @return The content of the element or KNullDesC8 if no content was set.
174 virtual TPtrC8 SetContentL(const TDesC8& aContent) = 0;
177 * Gets the write stream for the content for easy appending.
178 * Writing 8-bit (UTF-8) string to the returned stream will be appended
180 * @return reference to the RWriteStream.
182 virtual RWriteStream& ContentWriteStreamL() = 0;
185 * Checks if element matches to another element by its content and
186 * child elements. Element can contain more data than the given
188 * @since Series60 3.0
189 * @param aCandidate The pattern to be matched. Must contain same or
190 * less data for match to come true.
191 * @return ETrue if content and possible children match exactly
192 * to given pattern. EFalse otherwise.
194 virtual TBool ConsistsOfL(MSenElement& aCandidate) = 0;
197 * Getting the child elements of this element.
198 * @return an array of child elements. This is an empty array if there
199 * are no children. Any modifications made on the returned array
200 * modify the element object.
202 virtual RPointerArray<CSenElement>& ElementsL() = 0;
205 * Gets a child element from a specified index.
206 * @param aIndex: the index what to get
207 * @return child element from a current index. NULL if no child in given
210 virtual CSenElement* Child(TInt aIndex) = 0;
213 * Gets the value of the given attribute.
214 * @param aName: Name of the attribute in question.
215 * @return the value of the attribute, or NULL if not found. Ownership is
218 virtual const TDesC8* AttrValue(const TDesC8& aName) = 0;
221 * Adds an attribute. If attribute is already existing,
222 * the value of the attribute will be replaced.
223 * @param aName Name of the attribute to be added.
224 * @param aValue Value of the attribute to be added.
226 virtual void AddAttrL(const TDesC8& aName, const TDesC8& aValue) = 0;
229 * Gets all the attributes of this element in an array.
230 * @return array of attributes. Array will be empty if element has
233 virtual RPointerArray<CSenBaseAttribute>& AttributesL() = 0;
236 * Gets all the namespaces of this element in an array.
237 * @return array of namespaces. Array will be empty if element has
240 virtual RPointerArray<CSenNamespace>& NamespacesL() = 0;
243 * Gets the parent element of this element.
244 * @return the parent element or NULL if no parent set.
245 * Ownership is NOT transferred to the caller.
247 virtual CSenElement* Parent() = 0;
250 * Sets the parent element to this element. Notice that the element is not
251 * automatically added as a child of the parent. Parent's
252 * AddElementL() should be called instead.
253 * @param apParent: The wanted parent. Can be NULL.
254 * @return the parent element
256 virtual CSenElement* SetParent(CSenElement* apParent) = 0;
259 * Detach the element from its parent.
260 * If the element, or one of its children, is dependent
261 * on a namespace declared in the scope of the parent
262 * copy those namespace declarations to this element.
263 * @return this Element. Ownership is NOT transferred to the caller.
264 * Returns NULL if no parent was set, and nothing was detached.
266 virtual CSenElement* DetachL() = 0;
269 * Gets the root element. If no parent element, returns this element.
270 * @return the root of the tree. Ownership is not transferred.
272 virtual MSenElement& Root() = 0;
275 * Gets the child element with the specified local name.
276 * Assumes that namespace is the same as this parent element.
277 * @return the child element or NULL if the child with the specified
278 * local name is not found. Ownership is NOT transferred.
280 virtual CSenElement* Element(const TDesC8& aLocalName) = 0;
283 * Gets the child element with the specified local name and namespace URI.
284 * @return the child element or NULL if the child with the specified
285 * criterias is not found. Ownership is NOT transferred.
287 virtual CSenElement* Element(const TDesC8& aNsUri,
288 const TDesC8& aLocalName) = 0;
291 * Create a new element ready for adding or insertion.
292 * If the given namespace prefix is not declared yet
293 * the element will not be created and NULL will be returned.
294 * @param aNsPrefix: The namespace prefix
295 * @param aLocalName: The new elements localname
296 * @return the new Element just created, or NULL if given prefix was not
297 * declared yet. Ownership is transferred to the caller.
299 * KErrSenInvalidCharacters if aLocalName or aQName contain illegal
301 * KErrSenZeroLengthDescriptor if aLocalName is zero length.
303 virtual CSenElement* CreateElementL(const TDesC8& aNsPrefix,
304 const TDesC8& aLocalName) = 0;
307 * Insert an Element into the list of children elements
308 * so that the inserted Element is placed right before the aBeforeElement.
309 * If aBeforeElement is not found, element will be appended to the last
311 * Function leaves if error occurs in inserting.
312 * @param aInsertedElement: the element to be inserted.
313 * Ownership is transferred.
314 * @param aBeforeElement: the element which will be right next to the
315 * element just inserted.
316 * @return the inserted Element
318 virtual CSenElement& InsertElementL(CSenElement& aInsertedElement,
319 const CSenElement& aBeforeElement) = 0;
322 * Adds an Element to the children elements.
323 * Sets this element to be the new parent of the given element.
324 * @param aElement: the element to be added. Ownership is transferred.
325 * @return the added Element
327 virtual CSenElement& AddElementL(CSenElement& aElement) = 0;
330 * Constructs and adds a new element to the children elements.
331 * Sets this element to be the new parent of the given element.
332 * @param aNsUri: namespace URI of the new element
333 * @param aLocalName: local name of the new element
334 * @return the added Element
336 * KErrSenInvalidCharacters if aLocalName contains illegal characters.
337 * KErrSenZeroLengthDescriptor if aLocalName is zero length.
339 virtual CSenElement& AddElementL(const TDesC8& aNsUri,
340 const TDesC8& aLocalName) = 0;
343 * Constructs and adds a new element to the children elements.
344 * Sets this element to be the new parent of the given element.
345 * @param aNsUri: namespace URI of the new element
346 * @param aLocalName: local name of the new element
347 * @param aQName: qualified name of the new element
348 * @return the added Element
350 * KErrSenInvalidCharacters if aLocalName or aQName contain illegal
352 * KErrSenZeroLengthDescriptor if aLocalName or aQName is zero length.
354 virtual CSenElement& AddElementL(const TDesC8& aNsUri,
355 const TDesC8& aLocalName,
356 const TDesC8& aQName) = 0;
359 * Constructs and adds a new element to the children elements.
360 * Sets this element to be the new parent of the given element.
361 * Note: Element is created with no specific namespace, default namespace
362 * of some of the upper level elements are in effect if there is such a
364 * @param aLocalName: local name of the new element
365 * @return the added Element
367 * KErrSenInvalidCharacters if aLocalName contains illegal characters.
368 * KErrSenZeroLengthDescriptor if aLocalName is zero length.
370 virtual CSenElement& AddElementL(const TDesC8& aLocalName) = 0;
373 * Remove an element from the childs.
374 * @param aElement: the element to be removed.
375 * @return The removed element. May be NULL if nothing was removed
376 * (if element was not found from the childs).
377 * The caller TAKES OWNERSHIP of the removed element.
379 virtual CSenElement* RemoveElement(CSenElement& aElement) = 0;
382 * Remove an element from the childs.
383 * @param aNsUri: the namespace URI of the element to be removed.
384 * @param aLocalName: the local name of the element to be removed.
385 * @return The removed element. May be NULL if nothing was removed
386 * (if element was not found from the childs).
387 * The caller TAKES OWNERSHIP of the removed element.
389 virtual CSenElement* RemoveElement( const TDesC8& aNsUri,
390 const TDesC8& aLocalName) = 0;
393 * Remove an element from the childs.
394 * @param aLocalName: the local name of the element to be removed.
395 * @return The removed element. May be NULL if nothing was removed
396 * (if element was not found from the childs).
397 * The caller TAKES OWNERSHIP of the removed element.
399 virtual CSenElement* RemoveElement(const TDesC8& aLocalName) = 0;
402 * Replaces an element from the childs with another element.
403 * Element's local name and namespace URI will be used to match the
404 * element to be replaced. If matching element is not found, will
405 * normally add the given element to the childs.
407 * @param aElement: the element to be added. Ownership is transferred.
408 * @return The old element. May be NULL if nothing was replaced
409 * (if element was not found from the childs).
410 * The caller TAKES OWNERSHIP of the old element.
412 virtual CSenElement* ReplaceElementL(CSenElement& aElement) = 0;
415 * Gets element as an UTF-8 form XML.
416 * @return element as XML (in UTF-8 format). Caller takes ownership.
418 virtual HBufC8* AsXmlL() = 0;
421 * Gets the element as XML fragment in Unicode UCS2 format.
422 * @since Series60 3.0
423 * @return the service description as XML, which ownership is
424 * transferred to the caller.
426 virtual HBufC* AsXmlUnicodeL() = 0;
429 * Writes this element as XML, in UTF-8 form to a stream
430 * @since Series60 3.0
431 * @param aWriteStream to write into.
433 virtual void WriteAsXMLToL(RWriteStream& aWriteStream) = 0;
436 * Element writes its namespaces to a write stream using UTF-8 charset
439 * @param aWriteStream: The stream to write to.
441 virtual void WriteNamespacesToL(RWriteStream& aWriteStream) = 0;
444 * Gets the current element as XML element. Mostly used to get the
445 * classes which implement this interface as an instance of this
447 * @return the current object as element. Ownership is NOT transferred.
449 virtual MSenElement* AsElement() = 0;
452 * Copies content from given element to this element appending to the
453 * existing content if there is any.
454 * @param aSource: The source element.
456 virtual void CopyFromL(CSenElement& aSource) = 0;
459 * (Re-) Set the name and namespace of this Element. The element will be
460 * given the localName in the the given namespace. A prefix will be
461 * computed from the qualified name.
463 * This method should be used with care and is mainly intended for
464 * protected use in implementations.
466 * @param aNamespaceURI: The new namespace URI.
467 * @param aLocalName: The new local name.
468 * @param aQName: The new qualified name.
470 virtual void Set(const TDesC8& aNamespaceURI,
471 const TDesC8& aLocalName,
472 const TDesC8& aQName) = 0;
475 * Adds new attributes to the element.
476 * @param aAttrs: the array of attributes.
478 virtual void AddAttributesL(const RAttributeArray& aAttrs) = 0;
482 #endif // M_SEN_ELEMENT_H