# wso2wsf::OMElement Class Reference
[OMElement]

class OMElement A particular kind of node that represents an element infoset information item. An element has a collection of children, attributes, and namespaces. In contrast with DOM, this interface exposes namespaces separately from the attributes. More...

`#include <OMElement.h>`

Inheritance diagram for wso2wsf::OMElement:

List of all members.

## Public Member Functions
OMNamespace * | findNamespace (std::string uri, std::string prefix)
WSF_EXTERN | OMElement (std::string localname)
WSF_EXTERN | OMElement (std::string localname, OMNamespace *ns)
WSF_EXTERN | OMElement (OMNode *parent, std::string localname)
WSF_EXTERN | OMElement (OMNode *parent, std::string localname, OMNamespace *ns)
WSF_EXTERN | OMElement (OMNode *parent, axiom_node_t *node)
virtual | ~OMElement ()
virtual bool | removeChildLocal (OMNode *child)
virtual void | addChildLocal (OMNode *child)
virtual WSF_EXTERN std::vector < OMNode * > | getChildren ()
virtual WSF_EXTERN void | setChildren (std::vector< OMNode * > children)
WSF_EXTERN void | freeTree ()
WSF_EXTERN bool | insertSiblingAfter (OMNode *to_insert)
WSF_EXTERN bool | insertSiblingBefore (OMNode *to_insert)
WSF_EXTERN bool | setNamespace (OMNamespace *ns, bool no_find)
WSF_EXTERN OMNamespace * | getNamespace (bool is_default=false)
WSF_EXTERN OMNamespace * | getNamespaceLocal (bool is_default=false)
WSF_EXTERN bool | declareDefaultNamespace (std::string uri)
WSF_EXTERN bool | addAttribute (OMAttribute *attribute)
WSF_EXTERN OMAttribute * | getAttribute (std::string name, OMNamespace *ns)
WSF_EXTERN OMAttribute * | getAttribute (std::string name)
WSF_EXTERN std::string | getAttributeValue (std::string name, OMNamespace *ns)
WSF_EXTERN std::string | getAttributeValue (std::string name)
WSF_EXTERN bool | removeAttribute (OMAttribute *attribute)
WSF_EXTERN std::string | getLocalname ()
WSF_EXTERN bool | setText (std::string text)
WSF_EXTERN std::string | getText ()
WSF_EXTERN bool | addChild (OMNode *child)
WSF_EXTERN OMElement * | getFirstElement ()
WSF_EXTERN OMElement * | getChildElement (std::string localname, OMNamespace *ns)
WSF_EXTERN bool | build ()
WSF_EXTERN OMNode * | getFirstChild ()
WSF_EXTERN OMNode * | getLastChild ()
WSF_EXTERN axiom_types_t | nodeType ()

## Detailed Description

class OMElement A particular kind of node that represents an element infoset information item. An element has a collection of children, attributes, and namespaces. In contrast with DOM, this interface exposes namespaces separately from the attributes.

## Constructor & Destructor Documentation

WSF_EXTERN wso2wsf::OMElement::OMElement | ( | std::string | localname | ) |

Creates an om element struct.

Parameters:

  | localname | local name of the element. cannot be empty.

WSF_EXTERN wso2wsf::OMElement::OMElement | ( | std::string | localname,
|  | OMNamespace * | ns |
| ) |  |  |

Creates an om element struct.

Parameters:

  | localname | local name of the element. cannot be NULL.
  | ns | namespace of the element. can be NULL.

WSF_EXTERN wso2wsf::OMElement::OMElement | ( | OMNode * | parent,
|  | std::string | localname |
| ) |  |  |

Creates an om element struct.

Parameters:

  | parent | parent element.
  | localname | local name of the element. cannot be NULL.

WSF_EXTERN wso2wsf::OMElement::OMElement | ( | OMNode * | parent,
|  | std::string | localname,
|  | OMNamespace * | ns |
| ) |  |  |

Creates an om element struct.

Parameters:

  | parent | parent element.
  | localname | local name of the element. cannot be NULL.
  | ns | namespace of the element. can be NULL.

WSF_EXTERN wso2wsf::OMElement::OMElement | ( | OMNode * | parent,
|  | axiom_node_t * | node |
| ) |  |  |

Creates an om element struct.

Parameters:

  | parent | parent element.
  | node | node used to build the element. cannot be NULL.

virtual wso2wsf::OMElement::~OMElement | ( |  | ) | `[virtual]`

destructor that frees resources. Please note that all associated attributes, namespaces, and child nodes will also be removed.

## Member Function Documentation

WSF_EXTERN bool wso2wsf::OMElement::addAttribute | ( | OMAttribute * | attribute | ) |

Adds an attribute to current element

Parameters:

  | attribute | attribute to be added.

Returns:
  status of the op. true on success else false.

WSF_EXTERN bool wso2wsf::OMElement::addChild | ( | OMNode * | child | ) |

Adds given node as child to parent. child should not have a parent if child has a parent it will be detached from existing parent

Parameters:

  | child | child node.

Returns:
  status of the op. true on success else false.

virtual void wso2wsf::OMElement::addChildLocal | ( | OMNode * | child | ) | `[virtual]`

Adds given node as child to parent in C++ Level. child should not have a parent if child has a parent it will be detached from existing parent

Parameters:

  | child | child node.

Returns:
  status of the op. true on success else false.

WSF_EXTERN bool wso2wsf::OMElement::build | ( |  | ) |

builds this om_element_node completely, This is only possible if the om_stax_builder is associated with the om_element_node,

Returns:
  true if this element node was successfully completed, otherwise returns false.

WSF_EXTERN bool wso2wsf::OMElement::declareDefaultNamespace | ( | std::string | uri | ) |

declared a default namespace explicitly.

Parameters:

  | uri | namespace uri of the default namespace.

Returns:
  the declared namespace.

OMNamespace* wso2wsf::OMElement::findNamespace | ( | std::string | uri,
|  | std::string | prefix |
| ) |  |  |

Find a namespace in the scope of the document. Start to find from the given node and go up the hierarchy.

Parameters:

  | uri | namespace uri.
  | prefix | namespace prefix. can be NULL.

Returns:
  pointer to the namespace, if found, else NULL. On error, returns NULL and sets error code in environment,s error.

WSF_EXTERN void wso2wsf::OMElement::freeTree | ( |  | ) | `[virtual]`

Frees an om node and all of its children.

Reimplemented from wso2wsf::OMNode.

WSF_EXTERN OMAttribute* wso2wsf::OMElement::getAttribute | ( | std::string | name | ) |

Gets (finds) the attribute with the given name and namespace.

Parameters:

  | name | name of the attribute to be found. should not be NULL.

Returns:
  a pointer to the attribute with given name if found, else NULL. On error, returns NULL and sets the error code in environment's error struct.

WSF_EXTERN OMAttribute* wso2wsf::OMElement::getAttribute | ( | std::string | name,
|  | OMNamespace * | ns |
| ) |  |  |

Gets (finds) the attribute with the given name.

Parameters:

  | name | name of the attribute to be found. should not be NULL.
  | ns | namespace of the attribute to be found. can be NULL.

Returns:
  a pointer to the attribute with given name if found, else NULL. On error, returns NULL and sets the error code in environment's error struct.

WSF_EXTERN std::string wso2wsf::OMElement::getAttributeValue | ( | std::string | name | ) |

Gets (finds) the attribute value with the given name.

Parameters:

  | name | name of the attribute to be found. should not be NULL.

Returns:
  the attribute value with given name if found, else NULL.

WSF_EXTERN std::string wso2wsf::OMElement::getAttributeValue | ( | std::string | name,
|  | OMNamespace * | ns |
| ) |  |  |

Gets (finds) the attribute value with the given name and namespace.

Parameters:

  | name | name of the attribute to be found. should not be NULL.
  | ns | namespace of the attribute to be found. can be NULL.

Returns:
  the attribute value with given name if found, else NULL.

WSF_EXTERN OMElement* wso2wsf::OMElement::getChildElement | ( | std::string | localname,
|  | OMNamespace * | ns |
| ) |  |  |

returns the om_element corresponding to given local name and the namespace.

Parameters:

  | localname | local name of element.
  | ns | namespace of element. retrieved element.

virtual WSF_EXTERN std::vector<OMNode *> wso2wsf::OMElement::getChildren | ( |  | ) | `[virtual]`

Method to retrieve children of this node.

Returns:
  children of this node.

WSF_EXTERN OMNode* wso2wsf::OMElement::getFirstChild | ( |  | ) |

get the first child of node

Returns:
  pointer to first child node , NULL is returned on error with error code set in environments error

WSF_EXTERN OMElement* wso2wsf::OMElement::getFirstElement | ( |  | ) |

returns the first child om element of this om element node.

Returns:
  om element if one is available otherwise return NULL.

WSF_EXTERN OMNode* wso2wsf::OMElement::getLastChild | ( |  | ) |

get the last child

Returns:
  pointer to last child of this node , return NULL on error.

WSF_EXTERN std::string wso2wsf::OMElement::getLocalname | ( |  | ) |

returns the localname of this element

Returns:
  localname of element, returns NULL on error.

WSF_EXTERN OMNamespace* wso2wsf::OMElement::getNamespace | ( | bool | is_default = `false` | ) |

Get the OMNamespace of associated with this element. If the object is not yet built, it will be built and returned.

Parameters:

  | is_default | whether the retrieved namespace is default. If the default value is set, it will only return a namespace, if a default namespace exists. Otherwise, the namespace applicable to this element will be returned. Note:- The is_default parameter is Deprecated and is kept for backward compatibility. It will be dropped in future releases.

Returns:
  pointer to Namespace. NULL if there is no namespace.

WSF_EXTERN OMNamespace* wso2wsf::OMElement::getNamespaceLocal | ( | bool | is_default = `false` | ) |

Get the existing OMNamespace of om_element. If this is not yet build, NULL will be returned. The parameter is_default is deprecated and will be dropped in future releases.

Parameters:

  | is_default | whether the retrieved namespace is default.

Returns:
  pointer to Namespace. NULL if there is no namespace. associated with the element.

WSF_EXTERN std::string wso2wsf::OMElement::getText | ( |  | ) |

select all the text children and concatenate them to a single string.

Returns:
  the contaminated text of all text children text values return null if no text children is available or on error.

WSF_EXTERN bool wso2wsf::OMElement::insertSiblingAfter | ( | OMNode * | to_insert | ) | `[virtual]`

Inserts a sibling node after the given node.

Parameters:

  | to_insert | the node to be inserted. Cannot be NULL.

Returns:
  status of the op, true on success else false.

Reimplemented from wso2wsf::OMNode.

WSF_EXTERN bool wso2wsf::OMElement::insertSiblingBefore | ( | OMNode * | to_insert | ) | `[virtual]`

Inserts a sibling node before the given current node.

Parameters:

  | to_insert | the node to be inserted. Cannot be NULL.

Returns:
  status of the op, AXIS2_SUCCESS on success else AXIS2_FAILURE.

Reimplemented from wso2wsf::OMNode.

WSF_EXTERN axiom_types_t wso2wsf::OMElement::nodeType | ( |  | ) | `[virtual]`

get the node type of this element Node type can be one of AXIOM_ELEMENT, AXIOM_COMMENT, AXIOM_TEXT AXIOM_DOCTYPE, AXIOM_PROCESSING_INSTRUCTION

Returns:
  node type

Implements wso2wsf::OMNode.

WSF_EXTERN bool wso2wsf::OMElement::removeAttribute | ( | OMAttribute * | attribute | ) |

removes an attribute from the element attribute list user must free this attribute, element free function does not free attributes that are not is it's attribute list.

Parameters:

  | attribute | attribute to be removed.

Returns:
  true if attribute was found and removed, else false.

virtual bool wso2wsf::OMElement::removeChildLocal | ( | OMNode * | child | ) | `[virtual]`

Removes the given node from parent in C++ Level. child should have a parent and the parent must be this node. If you want to remove a child globally, use the detach method in the child node instead.

Parameters:

  | child | child node.

Returns:
  status of the op. true on success else false.

virtual WSF_EXTERN void wso2wsf::OMElement::setChildren | ( | std::vector< OMNode * > | children | ) | `[virtual]`

Method to set children of this node.

Parameters:

  | children | child node array.

Returns:
  children of this node.

WSF_EXTERN bool wso2wsf::OMElement::setNamespace | ( | OMNamespace * | ns,
|  | bool | no_find |
| ) |  |  |

Declare a namespace in current element (in the scope of this element). It checks to see if it is already declared. If no_find is true, this will not search the namespace in the scope nor will declare in the current element, as in set_namespace. This will just assign the given namespace to the element.

Parameters:

  | ns | pointer to the namespace struct to be declared.
  | no_find | true for no-find mode.

Returns:
  status of the op. true on success else false.

WSF_EXTERN bool wso2wsf::OMElement::setText | ( | std::string | text | ) |

Sets the text of the given element. caution - This method will wipe out all the text elements (and hence any mixed content) before setting the text.

Parameters:

  | text | text to be set.

Returns:
  true if text was set, else false.

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

- OMElement.h