Link against: xmlengineDOM.lib
#include <xmlengelement.h>
Inherits TXmlEngNode.
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:
<a xmlns=""> .. </a>
<a xmlns:="http://some.uri.com/"> ... </a>
Declaration of "" namespace with NULL prefix results in:
<a xmlns=""> ... </a>
So, it is wrong to write something like this:
<a xmlns="ns_uri" attr="value"> ... </a>
HINTS:
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 | |
| |
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. |
|
Default constructor for automatic variables (not initialized).
|
|
Constructor.
|
|
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.
|
|
Creates new attribute on the element. Namespace declaration for the attribute namespace is created too.
|
|
Creates new attribute node and add it to the element. Provided handle to namespace declaration is used to set up attribute's namespace.
|
|
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
TXmlEngElement el = ... ; // get some element el.AddNewAttributeL("version","0.1").SetAsFirstSibling();
|
|
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.
|
|
Creates new attributes using namespace, which is bound to the specified prefix.
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); }
// 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> ... // |
|
Creates new attributes using namespace in the scope, which has specified URI. Almost the same as AddNewAttributeUsePrefixL(...) but does lookup by namespace URI
|
|
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.
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 ...
|
|
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.
|
|
Creates new child element with provided name and namespace declaration.
|
|
Adds child element with no namespace.
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! |
|
Adds child element with same namespace (and prefix if present) as parent element has.
|
|
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
|
|
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
|
|
Adds text as a child of the element.
|
|
Add attribute to element that will be used as Xml:Id. No check if such attribute exists are made.
|
|
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.
|
|
Retrieves attribute node from specific namespace by its name.
|
|
Returns value of attribute with given name and namespace URI.
|
|
Removes all element contents: child nodes, attributes and namespace declarations.
|
|
Copies attributes from another element. It may be a very convenient method for initializing element with a set of predefined attributes.
|
|
Copies a list of elements. Elements are appended to the element's children list.
|
|
Specialized version of TXmlEngNode::CopyL().
Reimplemented from TXmlEngNode. |
|
Get default namespace for element.
Equivalent to LookupNamespaceByPrefixL(const TDesC8&) with NULL (or "") prefix provided |
|
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.
|
|
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.
|
|
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.
|
|
Retrieves list of attribute nodes of the element.
... TXmlEngElement root = doc.DocumentElement(); RXmlEngNodeList<TXmlEngAttr> attlist; root.GetAttributes(attlist); while (attlist.HasNext()) processAttribute(attlist.Next()); ... attlist.Close();
|
|
Retrieves list of child elements of the element.
|
|
Initializes list of child elements with matching name and namespace URI.
|
|
Check if element has attribute with given parameters.
|
|
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
|
|
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.
|
|
Finds namespace declaration that has specific namespace URI in the scope for the given node.
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). 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> 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.
|
|
Removes attribute with given name and namespace URI(if such exists). Memory allocated for the attribute is freed.
|
|
Resets element's attributes.
|
|
Removes attribute with given name and namespace URI(if such exists). Memory allocated for the attribute is freed.
|
|
Resets element's content: all child nodes are removed.
|
|
Resets all namespace declarations made in the element.
|
|
Sets value of attribute; attribute is created if there is no such attribute yet.
|
|
Links attribute into tree.
|
|
Adds default namespace declaration.
|
|
Sets text content of the element from escaped string.
|
|
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.
|
|
Sets text contents for the element. Any child nodes are removed. Same as TXmlEngNode::SetValueL(TDesC8&)
|
|
Sets new element value exactly as presented in the string. Predefined entities are not converted into characters they represent. Any child nodes are removed.
|
|
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.
|
|
Retrieves implicitly declared on every XML infoset binding of 'xml' prefix to XML's namespace URI: "http://www.w3.org/XML/1998/namespace".
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)
|