C12Adapter Opensource C++ Interface
MXmlNode Class Reference

DOM representation of XML node. More...

Inheritance diagram for MXmlNode:

Public Types

enum  NodeTypeEnum {
  NodeDocument = 1,
  NodeElement = 2,
  NodePcdata = 3,
  NodeCdata = 4,
  NodeComment = 5,
  NodePi = 6,
  NodeDeclaration = 7,
  NodeDoctype = 8
}
 Type of the node. More...
 
typedef M_TEMPLATE_CLASS std::vector< MXmlNode * > NodeVector
 Convenience type, vector of nodes.
 

Public Member Functions

NodeTypeEnum GetNodeType () const
 Type of the node. More...
 
MStdString AsString () const
 XML String representation of this element, and all its children. More...
 
MXmlNodeGetParent () const
 Access parent of this node. More...
 
bool HasChildren () const
 Whether the node has one or more children. More...
 
MXmlNode::NodeVector GetChildren () const
 Get the read-only array of all children of the node. More...
 
MVariant GetAllChildren () const
 Get the read-only array of all children of the node. More...
 
MXmlNodeGetFirstChild () const
 Return the first child of the node, if present. More...
 
MXmlNodeGetLastChild () const
 Return the last child of the node, if present. More...
 
MXmlNodeGetPreviousSibling () const
 Return the sibling that is previous to this node. More...
 
MXmlNodeGetNextSibling () const
 Return the sibling that is next to this node. More...
 
MXmlNodeGetChild (const MStdString &name) const
 Access the first child by name, if it is present. More...
 
bool IsChildPresent (const MStdString &name) const
 Is the child with such name present within the node. More...
 
MXmlNodeGetExistingChild (const MStdString &name) const
 Access the first child by name, or throw an exception if there is no such child. More...
 
void RemoveAllAttributes ()
 Remove all attributes of the item.
 
bool IsAttributePresent (const MStdString &name) const
 Whether an attribute with such name is present in the node. More...
 
MStdStringVector GetAllAttributeNames () const
 Access the collection of node attribute names. More...
 
bool RemoveAttribute (const MStdString &name)
 Remove attribute by name or do nothing if there is no such attribute already. More...
 
void RemoveExistingAttribute (const MStdString &name)
 Remove attribute by name. More...
 
MVariant GetAttribute (const MStdString &name) const
 Get attribute value by name. More...
 
MStdString GetAttributeAsString (const MStdString &name) const
 Get string attribute value by name, a C++ convenience call. More...
 
MConstChars GetAttributeAsChars (const MStdString &name) const
 Get const char* attribute value, a C++ convenience call. More...
 
int GetAttributeAsInt (const MStdString &name) const
 Get integer attribute value, a C++ convenience call. More...
 
double GetAttributeAsDouble (const MStdString &name) const
 Get a double precision floating point attribute value, a C++ convenience call. More...
 
bool SetAttribute (const MStdString &name, const MVariant &value)
 Set a value to attribute of a given name. More...
 
MXmlNodePrependAttribute (const MStdString &name, const MVariant &value)
 Create an attribute that will be the first in the list of node attributes. More...
 
MXmlNodeAppendAttribute (const MStdString &name, const MVariant &value)
 Create an attribute that will be the last in the list of node attributes. More...
 
void InsertAttributeBefore (const MStdString &targetName, const MStdString &name, const MVariant &value)
 Create an attribute and place it before another attribute. More...
 
MXmlNodeAppendChild (NodeTypeEnum type)
 Append a child node of a given type and return a freshly created node. More...
 
MXmlNodePrependChild (NodeTypeEnum type)
 Prepend a child node of a given type and return a freshly created node. More...
 
MXmlNodeInsertChildBefore (const MXmlNode *node, NodeTypeEnum type)
 Insert a child node before the given node. More...
 
MXmlNodeAppendChildElement (const MStdString &name)
 Append element child node and return a freshly created element object. More...
 
MXmlNodePrependChildElement (const MStdString &name)
 Prepend element child node and return a freshly created element object. More...
 
MXmlNodeInsertChildElementBefore (const MXmlNode *node, const MStdString &name)
 Insert element child node prior to a given child. More...
 
void AppendFragment (const MStdString &contents)
 Parse the string buffer as an XML document fragment and append all nodes as children to the current node. More...
 
void AppendFragmentFromBuffer (const char *buff, unsigned size)
 Parse the raw buffer as an XML document fragment and append all nodes as children to the current node. More...
 
void AppendFragmentFromChars (const char *buff)
 Parse the raw buffer as an XML document fragment and append all nodes as children to the current node. More...
 
void RemoveAllChildren ()
 Remove all children of the node. More...
 
bool RemoveChild (const MVariant &nameOrNodeObject)
 Remove a child node, do nothing if there is no such node. More...
 
bool RemoveChildByName (const MStdString &name)
 Remove a child node by name, do nothing if there is no such node. More...
 
bool RemoveChildByObject (MXmlNode *node)
 Remove a child object, do nothing if there is no such node. More...
 
void RemoveExistingChild (const MVariant &nameOrNodeObject)
 Remove an existing child node. More...
 
void RemoveExistingChildByName (const MStdString &name)
 Remove an existing child node by name. More...
 
void RemoveExistingChildByObject (MXmlNode *node)
 Remove an existing child object. More...
 
MStdString GetPath () const
 Return the node path from the root of XML document. More...
 
MXmlNodeGetFirstElementByPath (const MStdString &path) const
 Convenience function that returns elements by path. More...
 
MXmlNodeGetDocumentElement () const
 Access the main element of the document from any child. More...
 
MStdString GetName () const
 
void SetName (const MStdString &)
 
MVariant GetValue () const
 
void SetValue (const MVariant &)
 
MStdString GetStringValue () const
 
void SetStringValue (const MStdString &)
 
MVariant GetText () const
 
void SetText (const MVariant &)
 
MStdString GetStringText () const
 
void SetStringText (const MStdString &)
 
MVariant GetAllAttributes () const
 
void SetAllAttributes (const MVariant &)
 
virtual MXmlDocumentGetRoot ()
 
const MXmlDocumentGetRootConst () const
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Friends

class M_CLASS MXmlDocument
 

Additional Inherited Members

- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

DOM representation of XML node.

All different kinds of nodes are represented by this single class. Possible node types are defined by GetNodeType.

Member Enumeration Documentation

Type of the node.

Enumerator
NodeDocument 

Document tree root node.

Document has neither Name, nor Value, nor does it have Text. Typically, document has xml processing instruction of node type NodePi, comments (of type NodeComment), and the main single node element accessible from any node with property DocumentElement.

NodeElement 

Element, the most common node type.

Elements have nonempty property Name, but there is no Value property. Elements can have children and property Text, which is a child of type NodePcdata. Here is the placement of all properties of the element:

<Name attr1="attr-value1" attr2="attr-value2">Text</Name>
NodePcdata 

Plain character data such as 'plain characters'.

This node has only value. It cannot have children, attributes or name.

NodeCdata 

Character data block such as '<![CDATA[characters]]>'.

This node has only value. It cannot have children, attributes or name.

NodeComment 

XML comment such as ''.

This node has only value. It cannot have children, attributes or name.

NodePi 

Processing instruction such as '<?processing ?>'.

This node has name and value. It cannot have children or attributes. Here is the placement of all properties of the element:

<?Name Value?>
NodeDeclaration 

Document declaration such as '<?xml version="1.0"?>'.

Document declaration is typically the first node of the document. While it has similar syntax to NodePi, this node can have name and attributes, but cannot have children and Value.

<?Name attr1="attr-value1" attr2="attr-value2"?>

Name is typically "xml".

NodeDoctype 

Document type declaration, such as '<!DOCTYPE doc>'.

This type has name and value, but not children or attributes. Placement of properties:

<!Name Value!>

Member Function Documentation

MXmlNode* MXmlNode::AppendAttribute ( const MStdString name,
const MVariant value 
)

Create an attribute that will be the last in the list of node attributes.

No check is done whether the attribute with such name is already present.

Parameters
nameName of the attribute to modify.
valueThe new value of the attribute.
Returns
MXmlNode the call returns this object so the calls can be chained.
See also
PrependAttribute - prepend attribute with given name and value.
MXmlNode* MXmlNode::AppendChild ( NodeTypeEnum  type)

Append a child node of a given type and return a freshly created node.

The memory of the created node is managed by the document, the node should not be deleted.

Parameters
typeType of the node to create.
Returns
MXmlNode that is appended to this node.
See also
PrependChild
MXmlNode* MXmlNode::AppendChildElement ( const MStdString name)

Append element child node and return a freshly created element object.

The appended child will be the last in the list if children. The memory of the created node is managed by the document, the node should not be deleted.

Parameters
nameThe name of the element that will be created.
Returns
MXmlNode of type NodeElement that is appended to the list if children.
See also
AppendChild - append a generic child.
void MXmlNode::AppendFragment ( const MStdString contents)

Parse the string buffer as an XML document fragment and append all nodes as children to the current node.

Copies/converts the buffer, so it may be deleted or changed after the function returns.

Parameters
contentsXML fragment that is to be parsed and added to this node as a set of children.
void MXmlNode::AppendFragmentFromBuffer ( const char *  buff,
unsigned  size 
)

Parse the raw buffer as an XML document fragment and append all nodes as children to the current node.

Parameters
buffPointer to XML fragment that is to be parsed and added to this node as a set of children.
sizeByte size of the argument buff.
See also
AppendFragment - append a string.
void MXmlNode::AppendFragmentFromChars ( const char *  buff)
inline

Parse the raw buffer as an XML document fragment and append all nodes as children to the current node.

Parameters
buffZero terminated string, XML fragment that is to be parsed and added to this node as a set of children.
See also
AppendFragment - append a string.
MStdString MXmlNode::AsString ( ) const

XML String representation of this element, and all its children.

The result would look like:

<records><name>text value is here, manageable by Text property</name></records>

The exact format - whether there are new lines and how indentation is performed - is sensitive to MXmlDocument::GetParseMask and MXmlDocument::GetIndentationSequence.

MStdStringVector MXmlNode::GetAllAttributeNames ( ) const

Access the collection of node attribute names.

If the node does not have any attributes an empty collection is returned.

MVariant MXmlNode::GetAllAttributes ( ) const

Access map of names and values that comprises attributes of this node.

When getting the map, no type transformation is performed, strings are returned for values. When setting values, every value is converted into string.

MVariant MXmlNode::GetAllChildren ( ) const

Get the read-only array of all children of the node.

The returned variant array has all children of the node.

MVariant MXmlNode::GetAttribute ( const MStdString name) const

Get attribute value by name.

If the node does not have such attribute throw an exception.

Parameters
nameName of the attribute.
Returns
MVariant - value, convertible to a type that the user prefers.
MConstChars MXmlNode::GetAttributeAsChars ( const MStdString name) const

Get const char* attribute value, a C++ convenience call.

Parameters
nameName of the attribute.
See also
GetAttribute that returns MVariant type.
double MXmlNode::GetAttributeAsDouble ( const MStdString name) const

Get a double precision floating point attribute value, a C++ convenience call.

If the attribute is not convertible to a double, an exception is thrown.

Parameters
nameName of the attribute.
See also
GetAttribute that returns MVariant type.
int MXmlNode::GetAttributeAsInt ( const MStdString name) const

Get integer attribute value, a C++ convenience call.

If the attribute is not convertible to integer, an exception is thrown.

Parameters
nameName of the attribute.
See also
GetAttribute that returns MVariant type.
MStdString MXmlNode::GetAttributeAsString ( const MStdString name) const

Get string attribute value by name, a C++ convenience call.

Parameters
nameName of the attribute.
See also
GetAttribute that returns MVariant type.
MXmlNode* MXmlNode::GetChild ( const MStdString name) const

Access the first child by name, if it is present.

If such child is not present, null is returned. If there is more than one child with such name, one cannot reach them all with this call. The memory of the created node is managed by the document, the node should not be deleted.

Parameters
nameName of the child.
Returns
MXmlNode, child with the given name or null.
See also
GetExistingChild - access child by name, throws an exception if there is no such child.
GetFirstChild - access first child of this node.
GetLastChild - access last child of this node.
MXmlNode::NodeVector MXmlNode::GetChildren ( ) const

Get the read-only array of all children of the node.

The returned variant array has all children of the node.

See also
GetAllChildren - reflected version of this call that returns a variant.
MXmlNode* MXmlNode::GetDocumentElement ( ) const

Access the main element of the document from any child.

For a typical HTML document this would be an element with name "html". Document element is one of the children of the document root, the only child of type element.

If the document is empty, null is returned as there is no document element present.

MXmlNode* MXmlNode::GetExistingChild ( const MStdString name) const

Access the first child by name, or throw an exception if there is no such child.

If such child is not present, throw an error. If there is more than one child with such name, one cannot reach them all with this call. The memory of the created node is managed by the document, the node should not be deleted.

Parameters
nameName of the child.
Returns
MXmlNode, child with the given name, never a null.
See also
GetChild - if there is no such node return null.
GetFirstChild - access first child of this node.
GetLastChild - access first child of this node.
MXmlNode* MXmlNode::GetFirstChild ( ) const

Return the first child of the node, if present.

Children form a circular double linked list, but there is the first and the last child in the ring. If the node has no children, null is returned.

See also
GetChild - access child by name, or return null if there is no such child.
GetExistingChild - access child by name, throws an exception if there is no such child.
MXmlNode* MXmlNode::GetFirstElementByPath ( const MStdString path) const

Convenience function that returns elements by path.

The path given should use the value of property MXmlDocument::GetPathDelimiter for delimiting its components. If such node does not exist, an error is returned.

Parameters
pathPath of the element of interest.
Returns
MXmlNode the object.
MXmlNode* MXmlNode::GetLastChild ( ) const

Return the last child of the node, if present.

Children form a circular double linked list, but there is the first and the last child in the ring. If the node has no children, null is returned.

See also
GetChild - access child by name, or return null if there is no such child.
GetExistingChild - access child by name, throws an exception if there is no such child.
MStdString MXmlNode::GetName ( ) const

Name of the node.

Only NodeElement, NodePi, NodeDeclaration, and NodeDoctype will have nonempty name. When assigning Name to nodes of other type, an exception will be thrown. When getting Name to nodes of other type, empty string is returned.

Here are the examples of names in different node types:

<Name attr1="attr-val1"> <!-- NodeElement -->
<!Name Value!> <!-- NodeDoctype -->
<?Name attr1="attr-val1"?> <!-- NodeDeclaration -->
<?Name Value!> <!-- NodePi -->
MXmlNode* MXmlNode::GetNextSibling ( ) const

Return the sibling that is next to this node.

Nodes form a circular double linked list, therefore, when traversing through next siblings one reaches the initial node. If the node has no siblings, its next sibling is self.

NodeTypeEnum MXmlNode::GetNodeType ( ) const

Type of the node.

All different XML nodes have the same class, but they differentiate by type. Possible values for this property are defined in the enumeration:

  • NodeDocument = 1
  • NodeElement = 2
  • NodePcdata = 3
  • NodeCdata = 4
  • NodeComment = 5
  • NodePi = 6
  • NodeDeclaration = 7
  • NodeDoctype = 8
MXmlNode* MXmlNode::GetParent ( ) const

Access parent of this node.

The only node that has no parent is document node, of type NodeDoctype. Such node returns a null pointer as its parent.

MStdString MXmlNode::GetPath ( ) const

Return the node path from the root of XML document.

The string returned comprises the full element path delimited by MXmlDocument::GetPathDelimiter. Here is what a typical path looks like, delimited by forward slashes, the default:

/document-element/record/subnod
MXmlNode* MXmlNode::GetPreviousSibling ( ) const

Return the sibling that is previous to this node.

Nodes form a circular double linked list, therefore, when traversing through previous siblings one reaches the initial node. If the node has no siblings, its previous sibling is self.

virtual MXmlDocument* MXmlNode::GetRoot ( )
virtual

Access root document object from any child.

The root document is always present.

Reimplemented in MXmlDocument.

const MXmlDocument* MXmlNode::GetRootConst ( ) const
inline

Access root document object from any child.

The root document is always present.

MStdString MXmlNode::GetStringText ( ) const

String representation of text, C++ convenience function.

See also
GetText - same as this, but handles a variant data type.
MStdString MXmlNode::GetStringValue ( ) const

String representation of value, C++ convenience function.

See also
GetValue - same as this, but handles a variant data type.
MVariant MXmlNode::GetText ( ) const

Text associated with the node.

Accessing Text of any node of type other than NodeElement will always return an empty string. Assigning Text to a non-NodeElement will throw an exception as only NodeElement can have children.

Texts inside node elements are either of type NodeCdata or NodePcdata. Text property makes it convenient to access such immediate child from parent. Here is where the text is located:

<records>
<name>text value is here, manageable by Text property</name>
</records>

Therefore, having node record:

record->GetChild("name")->GetText()

If the node does not have a cnode or pcnode, an empty string is returned. When the property is assigned but there is no cnode child, a cnode is created and value is assigned to it.

MVariant MXmlNode::GetValue ( ) const

Value of the node.

When parsed from a document, values will be present in element types NodePcdata, NodeCdata, NodeComment, NodePi, and in NodeDoctype. Here are examples:

<![CDATA[this is the value]]>
this is also the value, pcdata
<!-- in a comment, this text is a value -->
<!DOCTYPE this is a value of doctype>

All other node types will return empty strings when accessed, and will throw an exception when assigned.

bool MXmlNode::HasChildren ( ) const

Whether the node has one or more children.

See also
RemoveAllChildren - remove all children of the node.
GetAllChildren - return an array of all children.
void MXmlNode::InsertAttributeBefore ( const MStdString targetName,
const MStdString name,
const MVariant value 
)

Create an attribute and place it before another attribute.

No check is done whether the attribute with such name is already present.

Parameters
targetNameName of the attribute before which a new one should be appended.
nameName of the attribute to modify.
valueThe new value of the attribute.
See also
AppendAttribute - append attribute with given name and value.
PrependAttribute - prepend attribute with given name and value.
MXmlNode* MXmlNode::InsertChildBefore ( const MXmlNode node,
NodeTypeEnum  type 
)

Insert a child node before the given node.

The memory of the created node is managed by the document, the node should not be deleted.

Parameters
nodeChild node before which a new one needs to be prepended.
typeType of the node to create.
Returns
MXmlNode that is inserted to this node.
MXmlNode* MXmlNode::InsertChildElementBefore ( const MXmlNode node,
const MStdString name 
)

Insert element child node prior to a given child.

The appended child will be the last in the list if children. The memory of the created node is managed by the document, the node should not be deleted.

Parameters
nodeThe child before which the new element is to be created.
nameThe name of the element that will be created.
Returns
MXmlNode of type NodeElement that is appended to the list if children.
See also
AppendChild - append a generic child.
bool MXmlNode::IsAttributePresent ( const MStdString name) const

Whether an attribute with such name is present in the node.

Parameters
nameNode of the attribute.
Returns
bool, whether such attribute is present.
bool MXmlNode::IsChildPresent ( const MStdString name) const
inline

Is the child with such name present within the node.

Parameters
nameName of the child.
Returns
bool, whether such child is present.
MXmlNode* MXmlNode::PrependAttribute ( const MStdString name,
const MVariant value 
)

Create an attribute that will be the first in the list of node attributes.

No check is done whether the attribute with such name is already present.

Parameters
nameName of the attribute to modify.
valueThe new value of the attribute.
Returns
MXmlNode the call returns this object so the calls can be chained.
See also
AppendAttribute - append attribute with given name and value.
MXmlNode* MXmlNode::PrependChild ( NodeTypeEnum  type)

Prepend a child node of a given type and return a freshly created node.

The memory of the created node is managed by the document, the node should not be deleted.

Parameters
typeType of the node to create.
Returns
MXmlNode that is prepended to this node.
See also
AppendChild
MXmlNode* MXmlNode::PrependChildElement ( const MStdString name)

Prepend element child node and return a freshly created element object.

The prepended child will be the last in the list of children. The memory of the created node is managed by the document, the node should not be deleted.

Parameters
nameThe name of the element that will be created.
Returns
MXmlNode of type NodeElement that is prepended to the list if children.
See also
PrependChild - append a generic child.
void MXmlNode::RemoveAllChildren ( )

Remove all children of the node.

See also
HasChildren - test whether the node has children.
bool MXmlNode::RemoveAttribute ( const MStdString name)

Remove attribute by name or do nothing if there is no such attribute already.

Parameters
nameName of the attribute to remove.
Returns
bool - True if the attribute existed and it was removed.
See also
RemoveExistingAttribute - will thrown an error if there is no such attribute.
bool MXmlNode::RemoveChild ( const MVariant nameOrNodeObject)

Remove a child node, do nothing if there is no such node.

The memory is managed by XmlDocument, do not attempt to delete the node.

Parameters
nameOrNodeObjectThis is either a name of the object, or it is the object itself.
Returns
bool, true if the child was present.
See also
RemoveExistingChild - throws an exception if there is no such child.
bool MXmlNode::RemoveChildByName ( const MStdString name)

Remove a child node by name, do nothing if there is no such node.

The memory is managed by XmlDocument, do not attempt to delete the node.

Parameters
nameName of the child.
Returns
bool, true if the child was present.
See also
RemoveChild
RemoveExistingChildByName - throws an exception if there is no such child.
bool MXmlNode::RemoveChildByObject ( MXmlNode node)

Remove a child object, do nothing if there is no such node.

The memory is managed by XmlDocument, do not attempt to delete the node.

Parameters
nodeObject that needs to be removed.
Returns
bool, true if the child was present.
See also
RemoveChild
RemoveExistingChildByObject - throws an exception if there is no such child.
void MXmlNode::RemoveExistingAttribute ( const MStdString name)

Remove attribute by name.

If there was no such attribute, throw an error.

Parameters
nameName of the attribute to remove.
See also
RemoveAttribute - will not throw, but instead return false if there is no such attribute.
void MXmlNode::RemoveExistingChild ( const MVariant nameOrNodeObject)

Remove an existing child node.

Throw an exception if there is no such child. The memory is managed by XmlDocument, do not attempt to delete the node.

Parameters
nameOrNodeObjectThis is either a name of the object, or it is the object itself.
See also
RemoveChild - return False if such child does not exist.
void MXmlNode::RemoveExistingChildByName ( const MStdString name)

Remove an existing child node by name.

Throw an exception if there is no such child. The memory is managed by XmlDocument, do not attempt to delete the node.

Parameters
nameName of the child.
See also
RemoveChild - return False if such child does not exist.
RemoveExistingChild
void MXmlNode::RemoveExistingChildByObject ( MXmlNode node)

Remove an existing child object.

Throw an exception if there is no such child. The memory is managed by XmlDocument, do not attempt to delete the node.

Parameters
nodeObject that needs to be removed.
See also
RemoveChild - return False if such child does not exist.
RemoveExistingChild
void MXmlNode::SetAllAttributes ( const MVariant )

Access map of names and values that comprises attributes of this node.

When getting the map, no type transformation is performed, strings are returned for values. When setting values, every value is converted into string.

bool MXmlNode::SetAttribute ( const MStdString name,
const MVariant value 
)

Set a value to attribute of a given name.

If such attribute does not exist, but the node type assumes presence of attributes, a new attribute is created. Otherwise an existing value is modified.

Parameters
nameName of the attribute to modify.
valueThe new value of the attribute.
Returns
bool, True if the value had to be added, false if an existing attribute modified.
See also
PrependAttribute - prepend attribute with given name and value.
AppendAttribute - append attribute with given name and value.
void MXmlNode::SetName ( const MStdString )

Name of the node.

Only NodeElement, NodePi, NodeDeclaration, and NodeDoctype will have nonempty name. When assigning Name to nodes of other type, an exception will be thrown. When getting Name to nodes of other type, empty string is returned.

Here are the examples of names in different node types:

<Name attr1="attr-val1"> <!-- NodeElement -->
<!Name Value!> <!-- NodeDoctype -->
<?Name attr1="attr-val1"?> <!-- NodeDeclaration -->
<?Name Value!> <!-- NodePi -->
void MXmlNode::SetStringText ( const MStdString )

String representation of text, C++ convenience function.

See also
GetText - same as this, but handles a variant data type.
void MXmlNode::SetStringValue ( const MStdString )

String representation of value, C++ convenience function.

See also
GetValue - same as this, but handles a variant data type.
void MXmlNode::SetText ( const MVariant )

Text associated with the node.

Accessing Text of any node of type other than NodeElement will always return an empty string. Assigning Text to a non-NodeElement will throw an exception as only NodeElement can have children.

Texts inside node elements are either of type NodeCdata or NodePcdata. Text property makes it convenient to access such immediate child from parent. Here is where the text is located:

<records>
<name>text value is here, manageable by Text property</name>
</records>

Therefore, having node record:

record->GetChild("name")->GetText()

If the node does not have a cnode or pcnode, an empty string is returned. When the property is assigned but there is no cnode child, a cnode is created and value is assigned to it.

void MXmlNode::SetValue ( const MVariant )

Value of the node.

When parsed from a document, values will be present in element types NodePcdata, NodeCdata, NodeComment, NodePi, and in NodeDoctype. Here are examples:

<![CDATA[this is the value]]>
this is also the value, pcdata
<!-- in a comment, this text is a value -->
<!DOCTYPE this is a value of doctype>

All other node types will return empty strings when accessed, and will throw an exception when assigned.