Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * Copyright (c) 2004-2006 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: Element node functions
24 #ifndef XMLENGINE_ELEMENT_H_INCLUDED
25 #define XMLENGINE_ELEMENT_H_INCLUDED
27 #include "XmlEngAttr.h"
28 #include "XmlEngNamespace.h"
30 template<class T> class RXmlEngNodeList;
34 * Instance of TXmlEngElement class represents an XML element in the DOM tree.
36 * <b>Namespace handling:</b>
38 * Namespace of XML element is an URI that in pair with <i>local part</i> of
39 * element's name consistute <b>expanded-name</b> of element. It is said that "the element
40 * is of <i>NNN</i> namespace".
42 * XML elements are shown as belonging to a specific namespace by using <i>prefixes</i>
43 * that previously were bound to some namespace URIs. The scope of a prefix is the
44 * element, where it was declared and all its child (sub-)elements.
46 * Namespace declaration is created by using special <b>xmlns:<i>{prefix-name}</i></b>
47 * attribute (which is not really considered as attribute in DOM):
49 * <a xmlns:pr="http://some.uri.com/"> ... </a>
51 * <pr:a xmlns:pr="http://some.uri.com/"> ... </a>
52 * <a xmlns="http://some.uri.com/"> ... </a>
55 * The latter two examples are equivalent and show the use of <i>default namespace</i>.
57 * Implementation notes:
58 * - Element having no namespace is either presented with a NULL TXmlEngNamespace node
59 * or a TXmlEngNamespace node that has NULL prefix and namespace URI set to "".
60 * The former is used by default on all nodes, whereas the latter is for cases
61 * when some node contains undeclaration of the default namespace:
63 * <a xmlns=""> .. </a>
66 * - The prefix of the default attribute is NULL, not "" (zero-length string)
69 * <a xmlns:="http://some.uri.com/"> ... </a>
71 * (it does not contradict XML spec, but you are strongly advised against using this)
73 * - Prefix <b>"xml"</b> is reserved by XML Namespace spec for special purposes; it is implicitly bound
74 * to XML's namespace <i>"http://www.w3.org/XML/1998/namespace"</i> and no one is allowed
75 * to use this prefix except as with spec-defined elements and attributes or to rebind this
76 * prefix to other namespaces
78 * - Namespace URI may be "" only for default namespace. In other words,
79 * "" namespace URI may not be bound to non-NULL prefix.
81 * Declaration of "" namespace with NULL prefix results in:
83 * <a xmlns=""> ... </a>
85 * which <i>undeclares</i> any existing (in some parent element) default namespace
86 * for the scope of element 'a': element, its attributes and all child nodes of DOM tree.
87 * Note, that such "undeclaration" will be added only if neccessary.
89 * - Unneccessary namespace declaration are ignored. Attemps to add namespace binding
90 * using same namespace URI and prefix if such binding already exists in the scope
91 * will have no effect.
93 * - <b>IMPORTANT!</b> Attributes DO NOT HAVE default namespaces. If an attribute has no
94 * prefix, its namespace is <b>undeclared</b> even if there is some default namespaces for
95 * the scope of the element, which contains the attribute.
97 * So, it is wrong to write something like this:
99 * <a xmlns="ns_uri" attr="value"> ... </a>
101 * and assume that the <b>attr</b> belongs to namespace pointed to with <i>ns_uri</i>.
104 * - Use namespace declaration nodes as much as possible (but watch out prefix collisions).
105 * - Add most referred to namespace declarations (AddNamespaceDeclarationL(uri,pref)) after
106 * any other namespace declarations in a element -- the will be found faster in
109 * @lib XmlEngineDOM.lib
113 class TXmlEngElement : public TXmlEngNode
117 * Default constructor for automatic variables (not initialized)
121 inline TXmlEngElement();
127 * @param aInternal element pointer
129 inline TXmlEngElement(void* aInternal);
132 * @name XmlEngine's non-DOM extensions
137 * Retrieves list of attribute nodes of the element
139 * @param aList - a node list object to initialize
141 * Passed by reference list of nodes is initialized and after call to
142 * Attributes(..) is ready for use with HasNext() and Next() methods:
146 * TXmlEngElement root = doc.DocumentElement();
147 * RXmlEngNodeList<TXmlEngAttr> attlist;
148 * root.GetAttributes(attlist);
149 * while (attlist.HasNext())
150 * processAttribute(attlist.Next());
157 IMPORT_C void GetAttributes(RXmlEngNodeList<TXmlEngAttr>& aList) const;
160 * Retrieves list of child elements of the element
163 * @param aList - a node list object to initialize
165 * Passed by reference list of nodes is initialized and after the call
166 * it is ready for use with HasNext() and Next() methods:
168 * @note Returned list is a "filtered view" of the underlying
169 * list of all element's children (with text nodes, comments
170 * processing instructions, etc.)
172 IMPORT_C void GetChildElements(RXmlEngNodeList<TXmlEngElement>& aList) const;
175 * Creates new attribute node out of any namespace (i.e. it has no prefix),
176 * sets attribute's value and links it as the last attribute of the current element
179 * @param aName A local name of attribute
180 * @param aValue Value to set for new attribute or NULL (sets value to "")
181 * @return A handler to the newly created attribute node;
183 * For adding attribute as the first one, use TXmlEngNode::SetAsFirstSibling() on the attribute:
185 * TXmlEngElement el = ... ; // get some element
186 * el.AddNewAttributeL("version","0.1").SetAsFirstSibling();
189 * @see SetAsLastSibling(), MoveBeforeSibling(TXmlEngNode) and MoveAfterSibling(TXmlEngNode)
191 * @note - No checks are made that attribute with such name exists
192 * Use this method only on newly created elements!
193 * Otherwise, use TXmlEngElement::SetAttributeL(..)
194 * - Attributes do not inherit default namespace of its element
195 * (http://w3.org/TR/REC-xml-names/#defaulting)
196 * - attribute's value is the second argument in all AddNewAttributeL(..) methods
197 * - Use of NULL as value is more preferrable then ""
199 IMPORT_C TXmlEngAttr AddNewAttributeL(const TDesC8& aName, const TDesC8& aValue);
202 * Creates new attribute node and add it to the element
204 * Provided handle to namespace declaration is used to set up
205 * attribute's namespace.
208 * @param aName A local name of attribute
209 * @param aValue Value to set for new attribute or NULL (sets value to "")
210 * @param aNsDef Namespace to add to the attribute
211 * @return A handler to the newly created attribute node;
213 * @note If aNsDef is not defined in some of attributes ascendants
214 * (including this element), then
215 * ReconcileNamespacesL() method must be called on
216 * this element later.
218 IMPORT_C TXmlEngAttr AddNewAttributeL(const TDesC8& aName,
219 const TDesC8& aValue,
220 const TXmlEngNamespace aNsDef);
223 * Creates new attribute on the element. Namespace declaration for the attribute namespace is
227 * @param aName A local name of attribute
228 * @param aValue Value to set for new attribute or NULL (sets value to "")
229 * @param aNsUri Namespace uri
230 * @param aPrefix Namespace prefix
231 * @return A handler to the newly created attribute node;
234 * - Namespace declarations are reused if possible (no redundant ones are created)
236 IMPORT_C TXmlEngAttr AddNewAttributeL(const TDesC8& aName,
237 const TDesC8& aValue,
238 const TDesC8& aNsUri,
239 const TDesC8& aPrefix);
242 * Creates new attribute node using namespace of its parent element (this element),
243 * sets attribute's value and links it as the last attribute of the element
246 * @param aName Local name of attribute
247 * @param aValue Value to set for new attribute or NULL (sets value to "")
248 * @return A handler to the newly created attribute node;
250 * For more hints how to use it refer to AddNewAttributeL(const TDesC8&,const TDesC8&)
253 * - No checks are made that attribute with such name exists
254 * - if namespace of the parent element is default (i.e. bound prefix is NULL),
255 * then temporary prefix will be used and bound to the same namespace URI as elements
256 * (It is due to the fact that default namespaces do not spread on unprefixed attributes,
257 * see http://w3.org/TR/REC-xml-names/#defaulting)
259 inline TXmlEngAttr AddNewAttributeSameNsL(const TDesC8& aName, const TDesC8& aValue);
262 * Creates new attributes using namespace, which is bound to the specified prefix
265 * @param aLocalName A local name of attribute
266 * @param aValue Value to set for new attribute or NULL (sets value to "")
267 * @param aPrefix Namespace prefix for new attribute
268 * @return A handler to the newly created attribute node;
270 * Use this mothod only for construction of new parts of DOM tree, where
271 * you know for sure that prefix is bound in the given scope.
273 * TXmlEngElement el = parent.AddNewAttributeUsePrefixL("property","ObjName","rdf");
274 * el.AddNewAttributeUsePrefixL("type", "xs:integer", "rdf");
277 * Otherwise, you should check that prefix is bound like this example shows:
279 * TXmlEngNamespace boundNS = TXmlEngNamespace::LookupByPrefix(thisElement, prefix);
280 * if (boundNS.NotNull()){
281 * thisElement.AddNewAttributeUsePrefixL("name", value, prefix);
286 * Use AddNewAttributeNsL(name,value,nsDefNode) as much as you can, because
287 * it is most efficient way to create namespaced DOM elements (no additional
288 * lookups for namespace declarations are required).
291 * // If namespace with given URI is not in the scope, then it will be declared
292 * // and bound to "data" prefix.
293 * TXmlEngNamespace nsDef = elem.FindOrCreateNsDefL("http://../Data", "data");
294 * elem.AddNewAttributeL("location", "...", nsDef);
295 * elem.AddNewElementL("child", nsDef).AddNewAttributeL("attr","...value...");
298 * <elem xmlns:data="http://../Data" data:location="...">
299 * <data:child attr="...value..."/>
305 IMPORT_C TXmlEngAttr AddNewAttributeUsePrefixL(const TDesC8& aLocalName,
306 const TDesC8& aValue,
307 const TDesC8& aPrefix);
310 * Creates new attributes using namespace in the scope, which has specified URI
312 * Almost the same as AddNewAttributeUsePrefixL(...) but does lookup by namespace URI
315 * @param aLocalName A local name of attribute
316 * @param aValue Value to set for new attribute or NULL (sets value to "")
317 * @param aNsUri Namespace uri for new attribute
318 * @return - NULL attribute if namespace declaration is not found OR newly added to the end of
319 * attribute list attribute of this element.
321 * @see AddNewAttributeUsePrefixL(const TDesC8&,const TDesC8&,const TDesC8&)
323 IMPORT_C TXmlEngAttr AddNewAttributeWithNsL(const TDesC8& aLocalName,
324 const TDesC8& aValue,
325 const TDesC8& aNsUri);
328 * Add attribute to element that will be used as Xml:Id.
330 * No check if such attribute exists are made.
333 * @param aLocalName Name of attribute that should be add.
334 * @param aValue Value of the attribute
335 * @param aNs Namespace of the attribute
336 * @return Attribute if created. Null attribute if Id exist
338 * @note Call RXmlEngDocument.RegisterXmlIdL(aName,aNsUri) first
339 * to register existed id's in the document.
341 IMPORT_C TXmlEngAttr AddXmlIdL(const TDesC8& aLocalName,
342 const TDesC8& aValue,
343 TXmlEngNamespace aNs = TXmlEngNamespace());
346 * Adds child element with no namespace
349 * @param aName name of the element
350 * @return A handler to the newly created element node;
352 * Results in adding element with aName and no prefix.
354 * This method is the best for creation of non-namespace based documents
355 * or document fragments, where no default namespace declared.
357 * It may be used also as a method for adding element from default namespace,
358 * BUT namespace will be assigned ONLY after serialization of the current
359 * document and parsing it back into a DOM tree!! If you need that default namespace
360 * was inherited by new element immediately use:
363 * TXmlEngNamespace defns = element.DefaultNamespace();
364 * TXmlEngElement newEl = element.AddNewElementL("Name",defns);
368 * If truly undefined namespace for the element is required, then <b>DO NOT USE</b>
369 * this method if there is a default namespace in the scope!
371 IMPORT_C TXmlEngElement AddNewElementL(const TDesC8& aName);
374 * Creates new child element with provided name and namespace declaration
377 * @param aLocalName Name of the element
378 * @param aNsDecl Handle of the namespace declaration, that must be retrieved from
379 * one of the ascendant nodes of the new elements (and its prefix
380 * should not be remapped to another namespace URI for the scope
381 * of the new element)
382 * @return Created element node (and added as the last child of its parent)
384 IMPORT_C TXmlEngElement AddNewElementL(const TDesC8& aLocalName, TXmlEngNamespace aNsDecl);
387 * Creates new child element with provided name, prefix and namespace URI
389 * New namespace declaration will be attached to the parent (this) element and used
390 * as namespace for newly created child element. If such binding already exists
391 * (same prefix is bound to same URI), it will be reused. If the prefix is already
392 * bound to some another namespace URI, it will be rebound by the new namespace
396 * @param aLocalName Name of the element
397 * @param aNsUri URI of element's namespace
398 * @param aPrefix Prefix of the element
399 * @return Created element node (and added as the last child of its parent)
401 IMPORT_C TXmlEngElement AddNewElementL(const TDesC8& aLocalName,
402 const TDesC8& aNsUri,
403 const TDesC8& aPrefix);
406 * Adds child element with same namespace (and prefix if present) as parent element has
409 * @param aLocalName element's name
410 * @return New element that was added to the end of children list of its parent (this element)
412 IMPORT_C TXmlEngElement AddNewElementSameNsL(const TDesC8& aLocalName);
415 * Performs lookup for the namespace declaration for specified prefix and
416 * adds new child element with found namespace.
418 * The assumption is that prefix is bound, otherwise run-time error
419 * (Symbian's Leave or exception) occurs
421 * @note Use this method only if there is a binding for the given prefix.
424 * @param aLocalName element's name
425 * @param aPrefix prefix to use
426 * @return new TXmlEngElement that was added to the end of children list of its parent (this element)
428 IMPORT_C TXmlEngElement AddNewElementUsePrefixL(const TDesC8& aLocalName, const TDesC8& aPrefix);
431 * Performs lookup for the namespace declaration for specified namespace URI and
432 * adds new child element with found namespace.
434 * The assumption is that namespace with given URI was declared,
435 * otherwise run-time error (Symbian' Leave or exception) occurs
437 * @note Use this method only if namespace declaration for the provided URI exists.
440 * @param aLocalName element's name
441 * @param aNsUri namespace of element
442 * @return new TXmlEngElement that was added to the end of children list of its parent (this element)
444 IMPORT_C TXmlEngElement AddNewElementWithNsL(const TDesC8& aLocalName, const TDesC8& aNsUri);
447 * Creates new child element; if there is no a prefix binding for new element's namespace,
448 * a namespace decaration is created with generated prefix at specified element.
451 * @param aLocalName Name of the element to create
452 * @param aNsUri Namespace URI of the new element
453 * @param aNsDeclTarget An element where namespace declaraton should be placed
454 * if there is a needed to create new namespace declaration;
455 * NULL is used to specify the created element itself
457 * As aNsDeclTarget any ascendant of the new node may be provided:
459 * el.AddNewElementAutoPrefixL(tagName,uri,NULL); // declare on the new element
460 * el.AddNewElementAutoPrefixL(tagName,uri,el); // declare on the parent element
461 * el.AddNewElementAutoPrefixL(tagName,uri,doc.DocumentElement()); // declare on the root element
466 * The farther namespace declaration up in the document tree,
467 * the longer time namespace declaration lookups take.
469 IMPORT_C TXmlEngElement AddNewElementAutoPrefixL(const TDesC8& aLocalName,
470 const TDesC8& aNsUri,
471 TXmlEngElement aNsDeclTarget);
474 * Get element content.
475 * This method may be used in most cases, when element has only simple text content
476 * (without entity references embedded).
477 * If element's contents is mixed (other types of nodes present), only contents of
478 * first child node is returned if it is a TXmlEngTextNode node. For getting mixed contents of the
479 * element of contents with entity references, WholeTextValueCopyL() should be used.
482 * @return Basic contents of the element
484 * @see TXmlEngNode::WholeTextContentsCopyL()
486 IMPORT_C TPtrC8 Text() const;
489 * Adds text as a child of the element.
492 * @param aString text to be added as element's content.
494 * @note There may be several TXmlEngTextNode and TXmlEngEntityReference nodes added actually,
495 * depending on the aString value
497 IMPORT_C void AddTextL(const TDesC8& aString);
500 * Sets text contents for the element.
501 * Any child nodes are removed.
502 * Same as TXmlEngNode::SetValueL(TDesC8&)
505 * @param aString text to be set as element's content.
507 * @see TXmlEngNode::SetValueL(TDesC8&)
509 IMPORT_C void SetTextL(const TDesC8& aString);
512 * Sets text content of the element from escaped string.
515 * @param aEscapedString New value
517 * @see TXmlEngAttr::SetEscapedValueL(TDesC8&)
519 IMPORT_C void SetEscapedTextL(const TDesC8& aEscapedString);
522 * Sets new element value exactly as presented in the string.
523 * Predefined entities are not converted into characters they represent.
524 * Any child nodes are removed.
527 * @param aNotEncText New element value
529 * @see TXmlEngAttr::SetValueNoEncL(const TDesC8& aNewValue);
531 IMPORT_C void SetTextNoEncL(const TDesC8& aNotEncString);
534 * Appends new text node with the value exactly as presented in the string.
535 * Predefined entities are not converted into characters they represent.
536 * Existing child nodes are not removed.
539 * @param aNotEncText Appended element value
541 * @see TXmlEngAttr::SetValueNoEncL(const TDesC8& aNewValue);
543 IMPORT_C void AppendTextNoEncL(const TDesC8& aNotEncString);
546 * Adds namespace declaration to the current element, a binding of prefix to namespace URI.
548 * If same namespace declaration exists (same prefix and URI), redundant namespace declaration
549 * will not be created.
551 * Both NULL or "" (empty string) may be used for "UNDEFINED URI" and "NO PREFIX" values of arguments.
554 * @param aNsUri Namespace URI
555 * @param aPrefix Namespace prefix
556 * @return A handle to the created (or found, if there is such) namespace declaration node.
557 * If namespace undeclaration is being created, NULL handle is returned -- it can be
558 * used in node-creation methods that take namespace handle as an argument.
560 * @note Undeclaring of default namespace (xmlns="") is supported by
561 * SetNoDefaultNamespace() method
563 * @see SetNoDefaulNamespace()
565 * @note By adding namespace declaration that rebinds prefix mapping (or default namespace)
566 * used by nodes lower in the tree, document tree may become
567 * wrongly constructed, because references to namespace declaration are
568 * not updated. However, after serialization the document will have
570 * Use this method with care!
572 IMPORT_C TXmlEngNamespace AddNamespaceDeclarationL(const TDesC8& aNsUri, const TDesC8& aPrefix);
575 * Adds default namespace declaration.
578 * @param aNsUri Namespace URI; both NULL and "" (empty string) are allowed to represent UNDEFINED NAMSPACE
579 * @return Handle to the created namespace declaration (NULL for UNDEFINED NAMESPACE)
581 * Same result as with AddNamespaceDeclarationL(aNsUri, NULL), but additionally
582 * element's namespace modified (if it has no prefix and there were no default
583 * namespace declaration in the scope) to the new default one.
585 IMPORT_C TXmlEngNamespace SetDefaultNamespaceL(const TDesC8& aNsUri);
588 * Undeclares any default namespace for current element and its descendants.
590 * If there is already some default namespace, <i>xmlns=""</i> namespace
591 * declaration is added. Otherwise, nothing happens, since element with no
592 * prefix in such scope is automaticaly considered as out of any namespace.
594 * The side effect of this method is that namespace of the current element
595 * may change from previous <b>default</b> namespace to NULL TXmlEngNamespace, which is
596 * considered an absence of namespace.
598 * If the element has prefix (i.e. not having default namespace),
599 * then the only effect for the element is undeclaration of existing default namespace.
601 * If element is in the scope of another <i>xmlns=""</i> undeclaration, no
605 * Use AddNamespaceDeclarationL(NULL,NULL) to force creation of
606 * xmlns="" declaration within scope of another such declaration
607 * (otherwise unneccessary/duplicate declarations are not created)
610 * This method should be called on elements before adding children,
611 * because default namespace undeclaration is not spread into its subtree and
612 * descedants' default namespaces are not reset to NULL. This should be taken into
613 * account if later some processing on the subtree occurs.
614 * However, after serialization and deserialization, undeclared default namespace will
615 * affect whole element's subtree correctly.
619 IMPORT_C void SetNoDefaultNamespaceL();
622 * Finds namespace declaration that has specific prefix in the scope for given node
624 * Prefix "" or NULL are considered the same, meaning "<b>NO PREFIX</b>".
625 * If namespace declaration for "no prefix" is searched, then default namespace is returned.
628 * @param aPrefix Namespace prefix
629 * @return Namespace handler, which may be NULL if prefix is not bound.
631 * NULL result for "no prefix" means that default namespace is undefined.
633 IMPORT_C TXmlEngNamespace LookupNamespaceByPrefixL(const TDesC8& aPrefix) const;
636 * Finds namespace declaration that has specific namespace URI
637 * in the scope for the given node.
640 * @param aUri Namespace URI, for which namespace declaration is searched
641 * @return Handler to the namespace declaration that binds given namespace URI to some prefix
642 * or sets it a default namespace.
644 * NULL value of aUri is equivalent to "" and means "<b>UNDEFINED NAMESPACE</b>".
645 * For such URI a NULL namespace handle is always returned even if there is
646 * namespace undeclaration, which has "" URI (and NULL prefix).
649 * Use returned instance of TXmlEngNamespace as aNsDef argument to element's methods
650 * that create new element's child elements and attributes. The same handler
651 * may be used on more deep descentants of the reference element (and doing
652 * this way will generally increase performance of DOM tree construction).<br />
653 * <span class="color:red;">However</span>, if namespace bindings are not controlled
654 * for element's children and prefix, which is bound to the search namespace, is
655 * rebound to some other namespace URI, then reusing namespace may lead to
658 * Consider an example:
660 * TXmlEngElement root = doc.DocumentElement();
661 * TXmlEngNamespace targetNs = root.AddNamespaceDeclarationL("http://example.com/","ex");
662 * TXmlEngElement el_1 = root.AddNewElementL("outer", targetNs);
663 * TXmlEngElement el_2 = el_1.AddNewElementL("inner"); // element without prefix
665 * // NOTE: prefix "ex" is not bound to "http://example.com/" anymore!
666 * el_2.AddNamespaceDeclarationL("http://whatever.com/","ex");
667 * TXmlEngElement el_3 = el_2.AddNewElementL("problem", targetNs);
671 * The sought result was (showing expanded names of elements):
674 * --> {"http://example.com/","outer"}
676 * -->{"http://example.com/","problem"}
680 * <-- {"http://example.com/","outer"}
684 * and it may look that it has been achieved. Indeed, if namespace of element "problem"
685 * was queried, it would have URI "http://example.com/" and prefix "ex".
686 * However, if namespace URI was looked up by "problem"'s prefix, it would be
687 * "http://whatever.com/". We have created illegal DOM tree.
689 * The actual DOM tree in serialized form will be:
692 * <ex:outer xmlns:ex="http://example.com/">
693 * <inner xmlns:ex="http://whatever.com/">
703 * So, reuse of namespace handlers should be performed with special care.
706 * At the moment it is possible to retrieve namespace declaration nodes
707 * whose prefixes were rebound. Be careful when use returned TXmlEngNamespace object
708 * for creation of new elements. In later releases, this method will perform
709 * safe lookup. And so far, it is better to make check that prefix of returned
710 * namespace declaration has not rebound:
712 * TXmlEngNamespace ns = element.LookupNamespaceByUri("a_uri");
713 * if (element.LookupNamespaceByPrefix(ns.Prefix()).IsSameNode(ns)){
714 * ... // now it is safe to create new elements by using "ns"
715 * element.AddNewElementL("product",ns);
720 IMPORT_C TXmlEngNamespace LookupNamespaceByUriL(const TDesC8& aUri) const;
723 * Retrieves implicitly declared on every XML infoset binding
724 * of 'xml' prefix to XML's namespace URI:
725 * "http://www.w3.org/XML/1998/namespace"
728 * @return Handler to {xml,"http://www.w3.org/XML/1998/namespace"} prefix
729 * binding in the current document
731 * The result should be used for creating attributes beloging to the XML namespace
732 * (xml:lang, xml:space, xml:id , etc.)
734 * DO NOT USE methods LookupNamespaceByUriL(const TDesC8&) and LookupNamespaceByPrefixL(const TDesC8&)
735 * (with "http://www.w3.org/XML/1998/namespace" and "xml" arguments) for retrieving
736 * namespace node, since in a case of [possible] memory allocation fault
737 * NULL result is returned (and breaks your program silently)
739 * @note Normally 'xml' prefix is bound to XML namespace URI in the document
740 * node, BUT if current node is not a part of the document tree yet,
741 * the requested namespace declaration WILL BE ADDED to the current node.
742 * This is the reason why the method may fail in OOM conditions.
744 IMPORT_C TXmlEngNamespace TheXMLNamespaceL() const;
747 * Get default namespace for element.
750 * @return Default namespace in the scope of the element
752 * NULL TXmlEngNamespace means that element with no prefix have no namespace associated
753 * because no default namespace was declared or default namespace was undeclared with <b>xmlns=""</b>
755 * Equivalent to LookupNamespaceByPrefixL(const TDesC8&) with NULL (or "") prefix provided
757 inline TXmlEngNamespace DefaultNamespaceL() const;
760 * Performs search of namespace handler in the scope of the element. This method will
761 * create new namespace declaration on the element if such namespace is not available.
764 * @param aNsUri Searched namespace
765 * @param aPrefix Prefix to use for <b>new</b> namespace declaration (if it is to be created)
766 * @return TXmlEngNamespace handler that may be used to create new attributes and child elements of
767 * the element. The namespace may be one of those existed previously or was created
770 * Be sure not to use the result of this method for non-descendants of the element or in situations
771 * when prefix overlapping might occur (read also about general general considerations of attributes
772 * and elements creation using namespace handlers)
774 IMPORT_C TXmlEngNamespace FindOrCreateNsDeclL(const TDesC8& aNsUri, const TDesC8& aPrefix);
777 * Performs search on the element and its ascendants for any namespace declaration
778 * with given URI and create a new namespace declaration with some (unique) prefix
779 * if the search was not successful.
782 * @param aNsUri Searched namespace
783 * @return TXmlEngNamespace handler that may be used to create new attributes and child elements of
784 * the element. The namespace may be one of those existed previously or was created
786 IMPORT_C TXmlEngNamespace FindOrCreateNsDeclL(const TDesC8& aNsUri);
789 * Checks whether a prefix has been bound in this element (not in one of its ascendants)
791 * Use this method for preventig prefix-name collision in a element node
794 * @param aPrefix Namespace prefix
795 * @return TRUE if there is already namespace declaration that uses aPrefix on this element
797 IMPORT_C TBool HasNsDeclarationForPrefixL(const TDesC8& aPrefix) const;
800 * Copies the element with its attributes, but not child nodes
802 * If context is preserved, then all namespace declarations that are in the element are
803 * writen to element's start tag too.
806 * @param preserveNsContext TRUE if context should be preserved
807 * @return handle to copy of element
809 IMPORT_C TXmlEngElement ElementCopyNoChildrenL(TBool preserveNsContext) const;
812 * Specialized version of TXmlEngNode::CopyL()
815 * @return Deep copy of the element.
817 inline TXmlEngElement CopyL() const;
820 * Resets element's content: all child nodes are removed
824 IMPORT_C void RemoveChildren();
827 * Resets element's attributes
831 IMPORT_C void RemoveAttributes();
834 * Resets all namespace declarations made in the element
836 * @note There can be references to these namespace declaration from elsewhere!
837 * Use ReconcileNamespacesL() to fix that.
841 IMPORT_C void RemoveNamespaceDeclarations();
844 * Removes all element contents: child nodes, attributes and namespace declarations
846 * @see RemoveChildren(), RemoveAttributes(), RemoveNamespaceDeclarations();
850 inline void ClearElement();
853 * Copies attributes from another element
855 * It may be a very convenient method for initializing element with a set of predefined attributes.
858 * @param aSrc source element
861 * Namespaces of the this element may need to be reconciled if copied attributes
862 * belong to any namespace that is not declared on some ascendant of this node.
863 * @see ReconcileNamespacesL()
865 IMPORT_C void CopyAttributesL(TXmlEngElement aSrc);
868 * Copies a list of elements.
870 * Elements are appended to the element's children list.
873 * @param aSrc source element
875 * @note Namespaces of the this element may need to be reconciled after copy operation
876 * @see ReconcileNamespacesL()
878 IMPORT_C void CopyChildrenL(TXmlEngElement aSrc);
881 * Removes attribute with given name and namespace URI(if such exists).
882 * Memory allocated for the attribute is freed.
885 * @param aLocalName Element name
886 * @param aNamespaceUri Element namespace
888 IMPORT_C void RemoveChildElementsL(const TDesC8& aLocalName,const TDesC8& aNamespaceUri);
893 * @name DOM Level 3 Core methods
896 * Most methods of DOM spec operate with fully-qualified names (QNames)
897 * of elements and attributes. It is different in this API - all methods
898 * instead accept prefix and localName parts of QName.
903 * Returns value of attribute with given name and namespace URI
906 * @param aLocalName Local name of attribute node
907 * @param aNamespaceUri Namespace URI of attribute
908 * @return Attribute value
910 IMPORT_C TPtrC8 AttributeValueL(const TDesC8& aLocalName,
911 const TDesC8& aNamespaceUri = KNullDesC8) const;
914 * Initializes list of child elements with matching name and namespace URI.
917 * @param aList Node list to be initialized
918 * @param aLocalName Element name
919 * @param aNamespaceUri Namespace URI, default is NULL
921 * @note This method does not lists all descedants of the element, only child elements
923 IMPORT_C void GetElementsByTagNameL(RXmlEngNodeList<TXmlEngElement>& aList,
924 const TDesC8& aLocalName,
925 const TDesC8& aNamespaceUri = KNullDesC8) const;
928 * Sets value of attribute; attribute is created if there is no such attribute yet
931 * @param aLocalName Attribute name
932 * @param aValue Attribute value
933 * @param aNamespaceUri Namespace URI - default is NULL
934 * @param aPrefix Namespace prefix - default is NULL
937 * If prefix is not NULL (or ""), then namespace URI may not be empty
938 * see http://www.w3.org/TR/REC-xml-names/#ns-decl (Definition #3)
940 IMPORT_C void SetAttributeL(const TDesC8& aLocalName,
941 const TDesC8& aValue,
942 const TDesC8& aNamespaceUri = KNullDesC8,
943 const TDesC8& aPrefix = KNullDesC8);
946 * Removes attribute with given name and namespace URI(if such exists).
947 * Memory allocated for the attribute is freed.
950 * @param aLocalName Name of the attribute
951 * @param aNamespaceUri Attribute namespace URI, default is NULL
953 IMPORT_C void RemoveAttributeL(const TDesC8& aLocalName,
954 const TDesC8& aNamespaceUri = KNullDesC8);
957 * Retrieves attribute node from specific namespace by its name.
960 * @param aLocalName Name of the attribute
961 * @param aNamespaceUri Attribute namespace URI, default is NULL
962 * @return Attribute node with matching namespace URI and name
964 IMPORT_C TXmlEngAttr AttributeNodeL(const TDesC8& aLocalName,
965 const TDesC8& aNamespaceUri = KNullDesC8) const;
968 * Check if element has attribute with given parameters.
971 * @param aLocalName Name of attribute
972 * @param aNamespaceUri Namespace uri, default is NULL.
973 * @return TRUE if the element holds an attribute with such namespace URI and name.
975 * Same result gives AttributeNodeL(uri,name).NotNull()
977 inline TBool HasAttributeL(const TDesC8& aLocalName,
978 const TDesC8& aNamespaceUri = KNullDesC8) const;
981 * Links attribute into tree
984 * @param aNewAttr new attribute
986 * The replaced attribute node is not returned and just deleted
988 IMPORT_C void SetAttributeNodeL(TXmlEngAttr aNewAttr);
993 #include "xmlengelement.inl"
995 #endif /* XMLENGINE_ELEMENT_H_INCLUDED */