TXmlEngElement Class Reference

Link against: xmlengineDOM.lib


#include <
xmlengelement.h>

Inherits TXmlEngNode.


Detailed Description

Instance of TXmlEngElement class represents an XML element in the DOM tree.

Namespace handling:

Namespace of XML element is an URI that in pair with local part of element's name consistute expanded-name of element. It is said that "the element is of NNN namespace".

XML elements are shown as belonging to a specific namespace by using prefixes that previously were bound to some namespace URIs. The scope of a prefix is the element, where it was declared and all its child (sub-)elements.

Namespace declaration is created by using special xmlns:{prefix-name} attribute (which is not really considered as attribute in DOM):

    <a xmlns:pr="http://some.uri.com/"> ... </a>
 OR
    <pr:a xmlns:pr="http://some.uri.com/"> ... </a>
    <a xmlns="http://some.uri.com/"> ... </a>

The latter two examples are equivalent and show the use of default namespace.

Implementation notes:

Declaration of "" namespace with NULL prefix results in:

       <a xmlns=""> ... </a>
which undeclares any existing (in some parent element) default namespace for the scope of element 'a': element, its attributes and all child nodes of DOM tree. Note, that such "undeclaration" will be added only if neccessary.

So, it is wrong to write something like this:

     <a xmlns="ns_uri"  attr="value"> ... </a>
and assume that the attr belongs to namespace pointed to with ns_uri.

HINTS:

Dll XmlEngineDOM.lib
Since:
S60 v3.1

Public Member Functions

 TXmlEngElement ()
 Default constructor for automatic variables (not initialized).
 TXmlEngElement (void *aInternal)
 Constructor.
XmlEngine's non-DOM extensions
IMPORT_C void GetAttributes (RXmlEngNodeList< TXmlEngAttr > &aList) const
 Retrieves list of attribute nodes of the element.
IMPORT_C void GetChildElements (RXmlEngNodeList< TXmlEngElement > &aList) const
 Retrieves list of child elements of the element.
IMPORT_C TXmlEngAttr AddNewAttributeL (const TDesC8 &aName, const TDesC8 &aValue)
 Creates new attribute node out of any namespace (i.e.
IMPORT_C TXmlEngAttr AddNewAttributeL (const TDesC8 &aName, const TDesC8 &aValue, const TXmlEngNamespace aNsDef)
 Creates new attribute node and add it to the element.
IMPORT_C TXmlEngAttr AddNewAttributeL (const TDesC8 &aName, const TDesC8 &aValue, const TDesC8 &aNsUri, const TDesC8 &aPrefix)
 Creates new attribute on the element.
TXmlEngAttr AddNewAttributeSameNsL (const TDesC8 &aName, const TDesC8 &aValue)
 Creates new attribute node using namespace of its parent element (this element), sets attribute's value and links it as the last attribute of the element.
IMPORT_C TXmlEngAttr AddNewAttributeUsePrefixL (const TDesC8 &aLocalName, const TDesC8 &aValue, const TDesC8 &aPrefix)
 Creates new attributes using namespace, which is bound to the specified prefix.
IMPORT_C TXmlEngAttr AddNewAttributeWithNsL (const TDesC8 &aLocalName, const TDesC8 &aValue, const TDesC8 &aNsUri)
 Creates new attributes using namespace in the scope, which has specified URI.
IMPORT_C TXmlEngAttr AddXmlIdL (const TDesC8 &aLocalName, const TDesC8 &aValue, TXmlEngNamespace aNs=TXmlEngNamespace())
 Add attribute to element that will be used as Xml:Id.
IMPORT_C TXmlEngElement AddNewElementL (const TDesC8 &aName)
 Adds child element with no namespace.
IMPORT_C TXmlEngElement AddNewElementL (const TDesC8 &aLocalName, TXmlEngNamespace aNsDecl)
 Creates new child element with provided name and namespace declaration.
IMPORT_C TXmlEngElement AddNewElementL (const TDesC8 &aLocalName, const TDesC8 &aNsUri, const TDesC8 &aPrefix)
 Creates new child element with provided name, prefix and namespace URI.
IMPORT_C TXmlEngElement AddNewElementSameNsL (const TDesC8 &aLocalName)
 Adds child element with same namespace (and prefix if present) as parent element has.
IMPORT_C TXmlEngElement AddNewElementUsePrefixL (const TDesC8 &aLocalName, const TDesC8 &aPrefix)
 Performs lookup for the namespace declaration for specified prefix and adds new child element with found namespace.
IMPORT_C TXmlEngElement AddNewElementWithNsL (const TDesC8 &aLocalName, const TDesC8 &aNsUri)
 Performs lookup for the namespace declaration for specified namespace URI and adds new child element with found namespace.
IMPORT_C TXmlEngElement AddNewElementAutoPrefixL (const TDesC8 &aLocalName, const TDesC8 &aNsUri, TXmlEngElement aNsDeclTarget)
 Creates new child element; if there is no a prefix binding for new element's namespace, a namespace decaration is created with generated prefix at specified element.
IMPORT_C TPtrC8 Text () const
 Get element content.
IMPORT_C void AddTextL (const TDesC8 &aString)
 Adds text as a child of the element.
IMPORT_C void SetTextL (const TDesC8 &aString)
 Sets text contents for the element.
IMPORT_C void SetEscapedTextL (const TDesC8 &aEscapedString)
 Sets text content of the element from escaped string.
IMPORT_C void SetTextNoEncL (const TDesC8 &aNotEncString)
 Sets new element value exactly as presented in the string.
IMPORT_C void AppendTextNoEncL (const TDesC8 &aNotEncString)
 Appends new text node with the value exactly as presented in the string.
IMPORT_C TXmlEngNamespace AddNamespaceDeclarationL (const TDesC8 &aNsUri, const TDesC8 &aPrefix)
 Adds namespace declaration to the current element, a binding of prefix to namespace URI.
IMPORT_C TXmlEngNamespace SetDefaultNamespaceL (const TDesC8 &aNsUri)
 Adds default namespace declaration.
IMPORT_C void SetNoDefaultNamespaceL ()
 Undeclares any default namespace for current element and its descendants.
IMPORT_C TXmlEngNamespace LookupNamespaceByPrefixL (const TDesC8 &aPrefix) const
 Finds namespace declaration that has specific prefix in the scope for given node.
IMPORT_C TXmlEngNamespace LookupNamespaceByUriL (const TDesC8 &aUri) const
 Finds namespace declaration that has specific namespace URI in the scope for the given node.
IMPORT_C TXmlEngNamespace TheXMLNamespaceL () const
 Retrieves implicitly declared on every XML infoset binding of 'xml' prefix to XML's namespace URI: "http://www.w3.org/XML/1998/namespace".
TXmlEngNamespace DefaultNamespaceL () const
 Get default namespace for element.
IMPORT_C TXmlEngNamespace FindOrCreateNsDeclL (const TDesC8 &aNsUri, const TDesC8 &aPrefix)
 Performs search of namespace handler in the scope of the element.
IMPORT_C TXmlEngNamespace FindOrCreateNsDeclL (const TDesC8 &aNsUri)
 Performs search on the element and its ascendants for any namespace declaration with given URI and create a new namespace declaration with some (unique) prefix if the search was not successful.
IMPORT_C TBool HasNsDeclarationForPrefixL (const TDesC8 &aPrefix) const
 Checks whether a prefix has been bound in this element (not in one of its ascendants).
IMPORT_C TXmlEngElement ElementCopyNoChildrenL (TBool preserveNsContext) const
 Copies the element with its attributes, but not child nodes.
TXmlEngElement CopyL () const
 Specialized version of TXmlEngNode::CopyL().
IMPORT_C void RemoveChildren ()
 Resets element's content: all child nodes are removed.
IMPORT_C void RemoveAttributes ()
 Resets element's attributes.
IMPORT_C void RemoveNamespaceDeclarations ()
 Resets all namespace declarations made in the element.
void ClearElement ()
 Removes all element contents: child nodes, attributes and namespace declarations.
IMPORT_C void CopyAttributesL (TXmlEngElement aSrc)
 Copies attributes from another element.
IMPORT_C void CopyChildrenL (TXmlEngElement aSrc)
 Copies a list of elements.
IMPORT_C void RemoveChildElementsL (const TDesC8 &aLocalName, const TDesC8 &aNamespaceUri)
 Removes attribute with given name and namespace URI(if such exists).
DOM Level 3 Core methods
Note:
Most methods of DOM spec operate with fully-qualified names (QNames) of elements and attributes. It is different in this API - all methods instead accept prefix and localName parts of QName.


IMPORT_C TPtrC8 AttributeValueL (const TDesC8 &aLocalName, const TDesC8 &aNamespaceUri=KNullDesC8) const
 Returns value of attribute with given name and namespace URI.
IMPORT_C void GetElementsByTagNameL (RXmlEngNodeList< TXmlEngElement > &aList, const TDesC8 &aLocalName, const TDesC8 &aNamespaceUri=KNullDesC8) const
 Initializes list of child elements with matching name and namespace URI.
IMPORT_C void SetAttributeL (const TDesC8 &aLocalName, const TDesC8 &aValue, const TDesC8 &aNamespaceUri=KNullDesC8, const TDesC8 &aPrefix=KNullDesC8)
 Sets value of attribute; attribute is created if there is no such attribute yet.
IMPORT_C void RemoveAttributeL (const TDesC8 &aLocalName, const TDesC8 &aNamespaceUri=KNullDesC8)
 Removes attribute with given name and namespace URI(if such exists).
IMPORT_C TXmlEngAttr AttributeNodeL (const TDesC8 &aLocalName, const TDesC8 &aNamespaceUri=KNullDesC8) const
 Retrieves attribute node from specific namespace by its name.
TBool HasAttributeL (const TDesC8 &aLocalName, const TDesC8 &aNamespaceUri=KNullDesC8) const
 Check if element has attribute with given parameters.
IMPORT_C void SetAttributeNodeL (TXmlEngAttr aNewAttr)
 Links attribute into tree.

Constructor & Destructor Documentation

TXmlEngElement::TXmlEngElement  )  [inline]
 

Default constructor for automatic variables (not initialized).

Since:
S60 v3.1
TXmlEngElement::TXmlEngElement void aInternal  )  [inline]
 

Constructor.

Since:
S60 v3.1
Parameters:
aInternal element pointer

Member Function Documentation

IMPORT_C TXmlEngNamespace TXmlEngElement::AddNamespaceDeclarationL const TDesC8 &  aNsUri,
const TDesC8 &  aPrefix
 

Adds namespace declaration to the current element, a binding of prefix to namespace URI.

If same namespace declaration exists (same prefix and URI), redundant namespace declaration will not be created.

Both NULL or "" (empty string) may be used for "UNDEFINED URI" and "NO PREFIX" values of arguments.

Since:
S60 v3.1
Parameters:
aNsUri Namespace URI
aPrefix Namespace prefix
Returns:
A handle to the created (or found, if there is such) namespace declaration node. If namespace undeclaration is being created, NULL handle is returned -- it can be used in node-creation methods that take namespace handle as an argument.
Note:
Undeclaring of default namespace (xmlns="") is supported by SetNoDefaultNamespace() method
See also:
SetNoDefaulNamespace()
Note:
By adding namespace declaration that rebinds prefix mapping (or default namespace) used by nodes lower in the tree, document tree may become wrongly constructed, because references to namespace declaration are not updated. However, after serialization the document will have desired structure. Use this method with care!
IMPORT_C TXmlEngAttr TXmlEngElement::AddNewAttributeL const TDesC8 &  aName,
const TDesC8 &  aValue,
const TDesC8 &  aNsUri,
const TDesC8 &  aPrefix
 

Creates new attribute on the element.

Namespace declaration for the attribute namespace is created too.

Since:
S60 v3.1
Parameters:
aName A local name of attribute
aValue Value to set for new attribute or NULL (sets value to "")
aNsUri Namespace uri
aPrefix Namespace prefix
Returns:
A handler to the newly created attribute node;
Note:
  • Namespace declarations are reused if possible (no redundant ones are created)
IMPORT_C TXmlEngAttr TXmlEngElement::AddNewAttributeL const TDesC8 &  aName,
const TDesC8 &  aValue,
const TXmlEngNamespace  aNsDef
 

Creates new attribute node and add it to the element.

Provided handle to namespace declaration is used to set up attribute's namespace.

Since:
S60 v3.1
Parameters:
aName A local name of attribute
aValue Value to set for new attribute or NULL (sets value to "")
aNsDef Namespace to add to the attribute
Returns:
A handler to the newly created attribute node;
Note:
If aNsDef is not defined in some of attributes ascendants (including this element), then ReconcileNamespacesL() method must be called on this element later.
IMPORT_C TXmlEngAttr TXmlEngElement::AddNewAttributeL const TDesC8 &  aName,
const TDesC8 &  aValue
 

Creates new attribute node out of any namespace (i.e.

it has no prefix), sets attribute's value and links it as the last attribute of the current element

Since:
S60 v3.1
Parameters:
aName A local name of attribute
aValue Value to set for new attribute or NULL (sets value to "")
Returns:
A handler to the newly created attribute node;
For adding attribute as the first one, use TXmlEngNode::SetAsFirstSibling() on the attribute:
     TXmlEngElement el = ... ; // get some element
     el.AddNewAttributeL("version","0.1").SetAsFirstSibling();
See also:
SetAsLastSibling(), MoveBeforeSibling(TXmlEngNode) and MoveAfterSibling(TXmlEngNode)
Note:
- No checks are made that attribute with such name exists Use this method only on newly created elements! Otherwise, use TXmlEngElement::SetAttributeL(..)
  • Attributes do not inherit default namespace of its element (http://w3.org/TR/REC-xml-names/#defaulting)
  • attribute's value is the second argument in all AddNewAttributeL(..) methods
  • Use of NULL as value is more preferrable then ""
TXmlEngAttr TXmlEngElement::AddNewAttributeSameNsL const TDesC8 &  aName,
const TDesC8 &  aValue
[inline]
 

Creates new attribute node using namespace of its parent element (this element), sets attribute's value and links it as the last attribute of the element.

Since:
S60 v3.1
Parameters:
aName Local name of attribute
aValue Value to set for new attribute or NULL (sets value to "")
Returns:
A handler to the newly created attribute node;
For more hints how to use it refer to AddNewAttributeL(const TDesC8&,const TDesC8&)
Note:
  • No checks are made that attribute with such name exists
  • if namespace of the parent element is default (i.e. bound prefix is NULL), then temporary prefix will be used and bound to the same namespace URI as elements (It is due to the fact that default namespaces do not spread on unprefixed attributes, see http://w3.org/TR/REC-xml-names/#defaulting)
IMPORT_C TXmlEngAttr TXmlEngElement::AddNewAttributeUsePrefixL const TDesC8 &  aLocalName,
const TDesC8 &  aValue,
const TDesC8 &  aPrefix
 

Creates new attributes using namespace, which is bound to the specified prefix.

Since:
S60 v3.1
Parameters:
aLocalName A local name of attribute
aValue Value to set for new attribute or NULL (sets value to "")
aPrefix Namespace prefix for new attribute
Returns:
A handler to the newly created attribute node;
Use this mothod only for construction of new parts of DOM tree, where you know for sure that prefix is bound in the given scope.
     TXmlEngElement el = parent.AddNewAttributeUsePrefixL("property","ObjName","rdf");
     el.AddNewAttributeUsePrefixL("type", "xs:integer", "rdf");

Otherwise, you should check that prefix is bound like this example shows:

     TXmlEngNamespace boundNS = TXmlEngNamespace::LookupByPrefix(thisElement, prefix);
     if (boundNS.NotNull()){
         thisElement.AddNewAttributeUsePrefixL("name", value, prefix);
     }
Note:
Use AddNewAttributeNsL(name,value,nsDefNode) as much as you can, because it is most efficient way to create namespaced DOM elements (no additional lookups for namespace declarations are required).
     // If namespace with given URI is not in the scope, then it will be declared
     // and bound to "data" prefix.
     TXmlEngNamespace nsDef = elem.FindOrCreateNsDefL("http://../Data", "data");
     elem.AddNewAttributeL("location", "...", nsDef);
     elem.AddNewElementL("child", nsDef).AddNewAttributeL("attr","...value...");
     // the result is
         ...
      <elem xmlns:data="http://../Data" data:location="...">
         <data:child attr="...value..."/>
      </elem>
         ...
     //
IMPORT_C TXmlEngAttr TXmlEngElement::AddNewAttributeWithNsL const TDesC8 &  aLocalName,
const TDesC8 &  aValue,
const TDesC8 &  aNsUri
 

Creates new attributes using namespace in the scope, which has specified URI.

Almost the same as AddNewAttributeUsePrefixL(...) but does lookup by namespace URI

Since:
S60 v3.1
Parameters:
aLocalName A local name of attribute
aValue Value to set for new attribute or NULL (sets value to "")
aNsUri Namespace uri for new attribute
Returns:
- NULL attribute if namespace declaration is not found OR newly added to the end of attribute list attribute of this element.
See also:
AddNewAttributeUsePrefixL(const TDesC8&,const TDesC8&,const TDesC8&)
IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementAutoPrefixL const TDesC8 &  aLocalName,
const TDesC8 &  aNsUri,
TXmlEngElement  aNsDeclTarget
 

Creates new child element; if there is no a prefix binding for new element's namespace, a namespace decaration is created with generated prefix at specified element.

Since:
S60 v3.1
Parameters:
aLocalName Name of the element to create
aNsUri Namespace URI of the new element
aNsDeclTarget An element where namespace declaraton should be placed if there is a needed to create new namespace declaration; NULL is used to specify the created element itself
As aNsDeclTarget any ascendant of the new node may be provided:
     el.AddNewElementAutoPrefixL(tagName,uri,NULL); // declare on the new element
     el.AddNewElementAutoPrefixL(tagName,uri,el);   // declare on the parent element
     el.AddNewElementAutoPrefixL(tagName,uri,doc.DocumentElement()); // declare on the root element
    ...
Note:
The farther namespace declaration up in the document tree, the longer time namespace declaration lookups take.
IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementL const TDesC8 &  aLocalName,
const TDesC8 &  aNsUri,
const TDesC8 &  aPrefix
 

Creates new child element with provided name, prefix and namespace URI.

New namespace declaration will be attached to the parent (this) element and used as namespace for newly created child element. If such binding already exists (same prefix is bound to same URI), it will be reused. If the prefix is already bound to some another namespace URI, it will be rebound by the new namespace declaration node.

Since:
S60 v3.1
Parameters:
aLocalName Name of the element
aNsUri URI of element's namespace
aPrefix Prefix of the element
Returns:
Created element node (and added as the last child of its parent)
IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementL const TDesC8 &  aLocalName,
TXmlEngNamespace  aNsDecl
 

Creates new child element with provided name and namespace declaration.

Since:
S60 v3.1
Parameters:
aLocalName Name of the element
aNsDecl Handle of the namespace declaration, that must be retrieved from one of the ascendant nodes of the new elements (and its prefix should not be remapped to another namespace URI for the scope of the new element)
Returns:
Created element node (and added as the last child of its parent)
IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementL const TDesC8 &  aName  ) 
 

Adds child element with no namespace.

Since:
S60 v3.1
Parameters:
aName name of the element
Returns:
A handler to the newly created element node;
Results in adding element with aName and no prefix.

This method is the best for creation of non-namespace based documents or document fragments, where no default namespace declared.

It may be used also as a method for adding element from default namespace, BUT namespace will be assigned ONLY after serialization of the current document and parsing it back into a DOM tree!! If you need that default namespace was inherited by new element immediately use:

    ...
    TXmlEngNamespace defns = element.DefaultNamespace();
    TXmlEngElement newEl = element.AddNewElementL("Name",defns);
    ...

If truly undefined namespace for the element is required, then DO NOT USE this method if there is a default namespace in the scope!

IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementSameNsL const TDesC8 &  aLocalName  ) 
 

Adds child element with same namespace (and prefix if present) as parent element has.

Since:
S60 v3.1
Parameters:
aLocalName element's name
Returns:
New element that was added to the end of children list of its parent (this element)
IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementUsePrefixL const TDesC8 &  aLocalName,
const TDesC8 &  aPrefix
 

Performs lookup for the namespace declaration for specified prefix and adds new child element with found namespace.

The assumption is that prefix is bound, otherwise run-time error (Symbian's Leave or exception) occurs

Note:
Use this method only if there is a binding for the given prefix.
Since:
S60 v3.1
Parameters:
aLocalName element's name
aPrefix prefix to use
Returns:
new TXmlEngElement that was added to the end of children list of its parent (this element)
IMPORT_C TXmlEngElement TXmlEngElement::AddNewElementWithNsL const TDesC8 &  aLocalName,
const TDesC8 &  aNsUri
 

Performs lookup for the namespace declaration for specified namespace URI and adds new child element with found namespace.

The assumption is that namespace with given URI was declared, otherwise run-time error (Symbian' Leave or exception) occurs

Note:
Use this method only if namespace declaration for the provided URI exists.
Since:
S60 v3.1
Parameters:
aLocalName element's name
aNsUri namespace of element
Returns:
new TXmlEngElement that was added to the end of children list of its parent (this element)
IMPORT_C void TXmlEngElement::AddTextL const TDesC8 &  aString  ) 
 

Adds text as a child of the element.

Since:
S60 v3.1
Parameters:
aString text to be added as element's content.
Note:
There may be several TXmlEngTextNode and TXmlEngEntityReference nodes added actually, depending on the aString value
IMPORT_C TXmlEngAttr TXmlEngElement::AddXmlIdL const TDesC8 &  aLocalName,
const TDesC8 &  aValue,
TXmlEngNamespace  aNs = TXmlEngNamespace()
 

Add attribute to element that will be used as Xml:Id.

No check if such attribute exists are made.

Since:
S60 v3.2
Parameters:
aLocalName Name of attribute that should be add.
aValue Value of the attribute
aNs Namespace of the attribute
Returns:
Attribute if created. Null attribute if Id exist
Note:
Call RXmlEngDocument.RegisterXmlIdL(aName,aNsUri) first to register existed id's in the document.
IMPORT_C void TXmlEngElement::AppendTextNoEncL const TDesC8 &  aNotEncString  ) 
 

Appends new text node with the value exactly as presented in the string.

Predefined entities are not converted into characters they represent. Existing child nodes are not removed.

Since:
S60 v3.2
Parameters:
aNotEncText Appended element value
See also:
TXmlEngAttr::SetValueNoEncL(const TDesC8& aNewValue);
IMPORT_C TXmlEngAttr TXmlEngElement::AttributeNodeL const TDesC8 &  aLocalName,
const TDesC8 &  aNamespaceUri = KNullDesC8
const
 

Retrieves attribute node from specific namespace by its name.

Since:
S60 v3.1
Parameters:
aLocalName Name of the attribute
aNamespaceUri Attribute namespace URI, default is NULL
Returns:
Attribute node with matching namespace URI and name
IMPORT_C TPtrC8 TXmlEngElement::AttributeValueL const TDesC8 &  aLocalName,
const TDesC8 &  aNamespaceUri = KNullDesC8
const
 

Returns value of attribute with given name and namespace URI.

Since:
S60 v3.1
Parameters:
aLocalName Local name of attribute node
aNamespaceUri Namespace URI of attribute
Returns:
Attribute value
void TXmlEngElement::ClearElement  )  [inline]
 

Removes all element contents: child nodes, attributes and namespace declarations.

See also:
RemoveChildren(), RemoveAttributes(), RemoveNamespaceDeclarations();
Since:
S60 v3.1
IMPORT_C void TXmlEngElement::CopyAttributesL TXmlEngElement  aSrc  ) 
 

Copies attributes from another element.

It may be a very convenient method for initializing element with a set of predefined attributes.

Since:
S60 v3.1
Parameters:
aSrc source element
Note:
Namespaces of the this element may need to be reconciled if copied attributes belong to any namespace that is not declared on some ascendant of this node.
See also:
ReconcileNamespacesL()
IMPORT_C void TXmlEngElement::CopyChildrenL TXmlEngElement  aSrc  ) 
 

Copies a list of elements.

Elements are appended to the element's children list.

Since:
S60 v3.1
Parameters:
aSrc source element
Note:
Namespaces of the this element may need to be reconciled after copy operation
See also:
ReconcileNamespacesL()
TXmlEngElement TXmlEngElement::CopyL  )  const [inline]
 

Specialized version of TXmlEngNode::CopyL().

Since:
S60 v3.1
Returns:
Deep copy of the element.

Reimplemented from TXmlEngNode.

TXmlEngNamespace TXmlEngElement::DefaultNamespaceL  )  const [inline]
 

Get default namespace for element.

Since:
S60 v3.1
Returns:
Default namespace in the scope of the element
NULL TXmlEngNamespace means that element with no prefix have no namespace associated because no default namespace was declared or default namespace was undeclared with xmlns=""

Equivalent to LookupNamespaceByPrefixL(const TDesC8&) with NULL (or "") prefix provided

IMPORT_C TXmlEngElement TXmlEngElement::ElementCopyNoChildrenL TBool  preserveNsContext  )  const
 

Copies the element with its attributes, but not child nodes.

If context is preserved, then all namespace declarations that are in the element are writen to element's start tag too.

Since:
S60 v3.1
Parameters:
preserveNsContext TRUE if context should be preserved
Returns:
handle to copy of element
IMPORT_C TXmlEngNamespace TXmlEngElement::FindOrCreateNsDeclL const TDesC8 &  aNsUri  ) 
 

Performs search on the element and its ascendants for any namespace declaration with given URI and create a new namespace declaration with some (unique) prefix if the search was not successful.

Since:
S60 v3.1
Parameters:
aNsUri Searched namespace
Returns:
TXmlEngNamespace handler that may be used to create new attributes and child elements of the element. The namespace may be one of those existed previously or was created
IMPORT_C TXmlEngNamespace TXmlEngElement::FindOrCreateNsDeclL const TDesC8 &  aNsUri,
const TDesC8 &  aPrefix
 

Performs search of namespace handler in the scope of the element.

This method will create new namespace declaration on the element if such namespace is not available.

Since:
S60 v3.1
Parameters:
aNsUri Searched namespace
aPrefix Prefix to use for new namespace declaration (if it is to be created)
Returns:
TXmlEngNamespace handler that may be used to create new attributes and child elements of the element. The namespace may be one of those existed previously or was created
Note:
Be sure not to use the result of this method for non-descendants of the element or in situations when prefix overlapping might occur (read also about general general considerations of attributes and elements creation using namespace handlers)
IMPORT_C void TXmlEngElement::GetAttributes RXmlEngNodeList< TXmlEngAttr > &  aList  )  const
 

Retrieves list of attribute nodes of the element.

Parameters:
aList - a node list object to initialize
Passed by reference list of nodes is initialized and after call to Attributes(..) is ready for use with HasNext() and Next() methods:
       ...
       TXmlEngElement root = doc.DocumentElement();
       RXmlEngNodeList<TXmlEngAttr>    attlist;
       root.GetAttributes(attlist);
       while (attlist.HasNext())
           processAttribute(attlist.Next());
       ...
       attlist.Close();
Since:
S60 v3.1
IMPORT_C void TXmlEngElement::GetChildElements RXmlEngNodeList< TXmlEngElement > &  aList  )  const
 

Retrieves list of child elements of the element.

Since:
S60 v3.1
Parameters:
aList - a node list object to initialize
Passed by reference list of nodes is initialized and after the call it is ready for use with HasNext() and Next() methods:
Note:
Returned list is a "filtered view" of the underlying list of all element's children (with text nodes, comments processing instructions, etc.)
IMPORT_C void TXmlEngElement::GetElementsByTagNameL RXmlEngNodeList< TXmlEngElement > &  aList,
const TDesC8 &  aLocalName,
const TDesC8 &  aNamespaceUri = KNullDesC8
const
 

Initializes list of child elements with matching name and namespace URI.

Since:
S60 v3.1
Parameters:
aList Node list to be initialized
aLocalName Element name
aNamespaceUri Namespace URI, default is NULL
Note:
This method does not lists all descedants of the element, only child elements
TBool TXmlEngElement::HasAttributeL const TDesC8 &  aLocalName,
const TDesC8 &  aNamespaceUri = KNullDesC8
const [inline]
 

Check if element has attribute with given parameters.

Since:
S60 v3.1
Parameters:
aLocalName Name of attribute
aNamespaceUri Namespace uri, default is NULL.
Returns:
TRUE if the element holds an attribute with such namespace URI and name.
Same result gives AttributeNodeL(uri,name).NotNull()
IMPORT_C TBool TXmlEngElement::HasNsDeclarationForPrefixL const TDesC8 &  aPrefix  )  const
 

Checks whether a prefix has been bound in this element (not in one of its ascendants).

Use this method for preventig prefix-name collision in a element node

Since:
S60 v3.1
Parameters:
aPrefix Namespace prefix
Returns:
TRUE if there is already namespace declaration that uses aPrefix on this element
IMPORT_C TXmlEngNamespace TXmlEngElement::LookupNamespaceByPrefixL const TDesC8 &  aPrefix  )  const
 

Finds namespace declaration that has specific prefix in the scope for given node.

Prefix "" or NULL are considered the same, meaning "<b>NO PREFIX</b>". If namespace declaration for "no prefix" is searched, then default namespace is returned.

Since:
S60 v3.1
Parameters:
aPrefix Namespace prefix
Returns:
Namespace handler, which may be NULL if prefix is not bound.
NULL result for "no prefix" means that default namespace is undefined.
IMPORT_C TXmlEngNamespace TXmlEngElement::LookupNamespaceByUriL const TDesC8 &  aUri  )  const
 

Finds namespace declaration that has specific namespace URI in the scope for the given node.

Since:
S60 v3.1
Parameters:
aUri Namespace URI, for which namespace declaration is searched
Returns:
Handler to the namespace declaration that binds given namespace URI to some prefix or sets it a default namespace.
NULL value of aUri is equivalent to "" and means "<b>UNDEFINED NAMESPACE</b>". For such URI a NULL namespace handle is always returned even if there is namespace undeclaration, which has "" URI (and NULL prefix).

Hint:

Use returned instance of TXmlEngNamespace as aNsDef argument to element's methods that create new element's child elements and attributes. The same handler may be used on more deep descentants of the reference element (and doing this way will generally increase performance of DOM tree construction).
However, if namespace bindings are not controlled for element's children and prefix, which is bound to the search namespace, is rebound to some other namespace URI, then reusing namespace may lead to unwanted result.

Consider an example:

     TXmlEngElement root = doc.DocumentElement();
     TXmlEngNamespace targetNs = root.AddNamespaceDeclarationL("http://example.com/","ex");
     TXmlEngElement el_1 = root.AddNewElementL("outer", targetNs);
     TXmlEngElement el_2 = el_1.AddNewElementL("inner"); // element without prefix
 
     // NOTE: prefix "ex" is not bound to "http://example.com/" anymore!
     el_2.AddNamespaceDeclarationL("http://whatever.com/","ex");
     TXmlEngElement el_3 = el_2.AddNewElementL("problem", targetNs);
     ...

The sought result was (showing expanded names of elements):

     --> "root"
         --> {"http://example.com/","outer"}
         --> "inner"
             -->{"http://example.com/","problem"}
                 ...
             <--
         <-- "inner"
         <-- {"http://example.com/","outer"}
         ...
     <-- </root>
and it may look that it has been achieved. Indeed, if namespace of element "problem" was queried, it would have URI "http://example.com/" and prefix "ex". However, if namespace URI was looked up by "problem"'s prefix, it would be "http://whatever.com/". We have created illegal DOM tree.

The actual DOM tree in serialized form will be:

     <root>
         <ex:outer xmlns:ex="http://example.com/">
             <inner xmlns:ex="http://whatever.com/">
                 <ex:problem>
                 ...
                 </ex:problem>
             </inner>
         </ex:outer>
         ...
     </root>

So, reuse of namespace handlers should be performed with special care.

Note:
At the moment it is possible to retrieve namespace declaration nodes whose prefixes were rebound. Be careful when use returned TXmlEngNamespace object for creation of new elements. In later releases, this method will perform safe lookup. And so far, it is better to make check that prefix of returned namespace declaration has not rebound:
     TXmlEngNamespace ns = element.LookupNamespaceByUri("a_uri");
     if (element.LookupNamespaceByPrefix(ns.Prefix()).IsSameNode(ns)){
         ... // now it is safe to create new elements by using "ns"
         element.AddNewElementL("product",ns);
         ...
     }
IMPORT_C void TXmlEngElement::RemoveAttributeL const TDesC8 &  aLocalName,
const TDesC8 &  aNamespaceUri = KNullDesC8
 

Removes attribute with given name and namespace URI(if such exists).

Memory allocated for the attribute is freed.

Since:
S60 v3.1
Parameters:
aLocalName Name of the attribute
aNamespaceUri Attribute namespace URI, default is NULL
IMPORT_C void TXmlEngElement::RemoveAttributes  ) 
 

Resets element's attributes.

Since:
S60 v3.1
IMPORT_C void TXmlEngElement::RemoveChildElementsL const TDesC8 &  aLocalName,
const TDesC8 &  aNamespaceUri
 

Removes attribute with given name and namespace URI(if such exists).

Memory allocated for the attribute is freed.

Since:
S60 v3.1
Parameters:
aLocalName Element name
aNamespaceUri Element namespace
IMPORT_C void TXmlEngElement::RemoveChildren  ) 
 

Resets element's content: all child nodes are removed.

Since:
S60 v3.1
IMPORT_C void TXmlEngElement::RemoveNamespaceDeclarations  ) 
 

Resets all namespace declarations made in the element.

Note:
There can be references to these namespace declaration from elsewhere! Use ReconcileNamespacesL() to fix that.
Since:
S60 v3.1
IMPORT_C void TXmlEngElement::SetAttributeL const TDesC8 &  aLocalName,
const TDesC8 &  aValue,
const TDesC8 &  aNamespaceUri = KNullDesC8,
const TDesC8 &  aPrefix = KNullDesC8
 

Sets value of attribute; attribute is created if there is no such attribute yet.

Since:
S60 v3.1
Parameters:
aLocalName Attribute name
aValue Attribute value
aNamespaceUri Namespace URI - default is NULL
aPrefix Namespace prefix - default is NULL
Note:
If prefix is not NULL (or ""), then namespace URI may not be empty see http://www.w3.org/TR/REC-xml-names/#ns-decl (Definition #3)
IMPORT_C void TXmlEngElement::SetAttributeNodeL TXmlEngAttr  aNewAttr  ) 
 

Links attribute into tree.

Since:
S60 v3.1
Parameters:
aNewAttr new attribute
The replaced attribute node is not returned and just deleted
IMPORT_C TXmlEngNamespace TXmlEngElement::SetDefaultNamespaceL const TDesC8 &  aNsUri  ) 
 

Adds default namespace declaration.

Since:
S60 v3.1
Parameters:
aNsUri Namespace URI; both NULL and "" (empty string) are allowed to represent UNDEFINED NAMSPACE
Returns:
Handle to the created namespace declaration (NULL for UNDEFINED NAMESPACE)
Same result as with AddNamespaceDeclarationL(aNsUri, NULL), but additionally element's namespace modified (if it has no prefix and there were no default namespace declaration in the scope) to the new default one.
IMPORT_C void TXmlEngElement::SetEscapedTextL const TDesC8 &  aEscapedString  ) 
 

Sets text content of the element from escaped string.

Since:
S60 v3.1
Parameters:
aEscapedString New value
See also:
TXmlEngAttr::SetEscapedValueL(TDesC8&)
IMPORT_C void TXmlEngElement::SetNoDefaultNamespaceL  ) 
 

Undeclares any default namespace for current element and its descendants.

If there is already some default namespace, xmlns="" namespace declaration is added. Otherwise, nothing happens, since element with no prefix in such scope is automaticaly considered as out of any namespace.

The side effect of this method is that namespace of the current element may change from previous default namespace to NULL TXmlEngNamespace, which is considered an absence of namespace.

If the element has prefix (i.e. not having default namespace), then the only effect for the element is undeclaration of existing default namespace.

If element is in the scope of another xmlns="" undeclaration, no actions are taken.

Note:
Use AddNamespaceDeclarationL(NULL,NULL) to force creation of xmlns="" declaration within scope of another such declaration (otherwise unneccessary/duplicate declarations are not created)

This method should be called on elements before adding children, because default namespace undeclaration is not spread into its subtree and descedants' default namespaces are not reset to NULL. This should be taken into account if later some processing on the subtree occurs. However, after serialization and deserialization, undeclared default namespace will affect whole element's subtree correctly.

Since:
S60 v3.1
IMPORT_C void TXmlEngElement::SetTextL const TDesC8 &  aString  ) 
 

Sets text contents for the element.

Any child nodes are removed. Same as TXmlEngNode::SetValueL(TDesC8&)

Since:
S60 v3.1
Parameters:
aString text to be set as element's content.
See also:
TXmlEngNode::SetValueL(TDesC8&)
IMPORT_C void TXmlEngElement::SetTextNoEncL const TDesC8 &  aNotEncString  ) 
 

Sets new element value exactly as presented in the string.

Predefined entities are not converted into characters they represent. Any child nodes are removed.

Since:
S60 v3.2
Parameters:
aNotEncText New element value
See also:
TXmlEngAttr::SetValueNoEncL(const TDesC8& aNewValue);
IMPORT_C TPtrC8 TXmlEngElement::Text  )  const
 

Get element content.

This method may be used in most cases, when element has only simple text content (without entity references embedded). If element's contents is mixed (other types of nodes present), only contents of first child node is returned if it is a TXmlEngTextNode node. For getting mixed contents of the element of contents with entity references, WholeTextValueCopyL() should be used.

Since:
S60 v3.1
Returns:
Basic contents of the element
See also:
TXmlEngNode::WholeTextContentsCopyL()
IMPORT_C TXmlEngNamespace TXmlEngElement::TheXMLNamespaceL  )  const
 

Retrieves implicitly declared on every XML infoset binding of 'xml' prefix to XML's namespace URI: "http://www.w3.org/XML/1998/namespace".

Since:
S60 v3.1
Returns:
Handler to {xml,"http://www.w3.org/XML/1998/namespace"} prefix binding in the current document
The result should be used for creating attributes beloging to the XML namespace (xml:lang, xml:space, xml:id , etc.)

DO NOT USE methods LookupNamespaceByUriL(const TDesC8&) and LookupNamespaceByPrefixL(const TDesC8&) (with "http://www.w3.org/XML/1998/namespace" and "xml" arguments) for retrieving namespace node, since in a case of [possible] memory allocation fault NULL result is returned (and breaks your program silently)

Note:
Normally 'xml' prefix is bound to XML namespace URI in the document node, BUT if current node is not a part of the document tree yet, the requested namespace declaration WILL BE ADDED to the current node. This is the reason why the method may fail in OOM conditions.

The documentation for this class was generated from the following files:

Copyright © Nokia Corporation 2001-2007
Back to top