C12Adapter Opensource C++ Interface
|
DOM representation of XML node. More...
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... | |
MXmlNode * | GetParent () 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... | |
MXmlNode * | GetFirstChild () const |
Return the first child of the node, if present. More... | |
MXmlNode * | GetLastChild () const |
Return the last child of the node, if present. More... | |
MXmlNode * | GetPreviousSibling () const |
Return the sibling that is previous to this node. More... | |
MXmlNode * | GetNextSibling () const |
Return the sibling that is next to this node. More... | |
MXmlNode * | GetChild (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... | |
MXmlNode * | GetExistingChild (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... | |
MXmlNode * | PrependAttribute (const MStdString &name, const MVariant &value) |
Create an attribute that will be the first in the list of node attributes. More... | |
MXmlNode * | AppendAttribute (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... | |
MXmlNode * | AppendChild (NodeTypeEnum type) |
Append a child node of a given type and return a freshly created node. More... | |
MXmlNode * | PrependChild (NodeTypeEnum type) |
Prepend a child node of a given type and return a freshly created node. More... | |
MXmlNode * | InsertChildBefore (const MXmlNode *node, NodeTypeEnum type) |
Insert a child node before the given node. More... | |
MXmlNode * | AppendChildElement (const MStdString &name) |
Append element child node and return a freshly created element object. More... | |
MXmlNode * | PrependChildElement (const MStdString &name) |
Prepend element child node and return a freshly created element object. More... | |
MXmlNode * | InsertChildElementBefore (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... | |
MXmlNode * | GetFirstElementByPath (const MStdString &path) const |
Convenience function that returns elements by path. More... | |
MXmlNode * | GetDocumentElement () 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 MXmlDocument * | GetRoot () |
const MXmlDocument * | GetRootConst () const |
![]() | |
virtual | ~MObject () |
Object destructor. | |
virtual const MClass * | GetClass () 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 ¶ms) |
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 ¶ms) |
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 const MClass * | GetStaticClass () |
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 const MClass | s_class |
Class of 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... | |
DOM representation of XML node.
All different kinds of nodes are represented by this single class. Possible node types are defined by GetNodeType.
Type of the node.
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.
name | Name of the attribute to modify. |
value | The new value of the attribute. |
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.
type | Type of the node to create. |
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.
name | The name of the element that will be created. |
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.
contents | XML 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.
buff | Pointer to XML fragment that is to be parsed and added to this node as a set of children. |
size | Byte size of the argument buff. |
|
inline |
Parse the raw buffer as an XML document fragment and append all nodes as children to the current node.
buff | Zero terminated string, XML fragment that is to be parsed and added to this node as a set of children. |
MStdString MXmlNode::AsString | ( | ) | const |
XML String representation of this element, and all its children.
The result would look like:
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.
name | Name of the attribute. |
MConstChars MXmlNode::GetAttributeAsChars | ( | const MStdString & | name | ) | const |
Get const char* attribute value, a C++ convenience call.
name | Name of the attribute. |
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.
name | Name of the attribute. |
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.
name | Name of the attribute. |
MStdString MXmlNode::GetAttributeAsString | ( | const MStdString & | name | ) | const |
Get string attribute value by name, a C++ convenience call.
name | Name of the attribute. |
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.
name | Name of the child. |
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.
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.
name | Name of the child. |
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.
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.
path | Path of the element of interest. |
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.
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:
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:
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:
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 |
Access root document object from any child.
The root document is always present.
Reimplemented in MXmlDocument.
|
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.
MStdString MXmlNode::GetStringValue | ( | ) | const |
String representation of value, C++ convenience function.
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:
Therefore, having node record:
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:
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.
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.
targetName | Name of the attribute before which a new one should be appended. |
name | Name of the attribute to modify. |
value | The new value of the attribute. |
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.
node | Child node before which a new one needs to be prepended. |
type | Type of the node to create. |
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.
node | The child before which the new element is to be created. |
name | The name of the element that will be created. |
bool MXmlNode::IsAttributePresent | ( | const MStdString & | name | ) | const |
Whether an attribute with such name is present in the node.
name | Node of the attribute. |
|
inline |
Is the child with such name present within the node.
name | Name of the child. |
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.
name | Name of the attribute to modify. |
value | The new value of the attribute. |
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.
type | Type of the node to create. |
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.
name | The name of the element that will be created. |
void MXmlNode::RemoveAllChildren | ( | ) |
Remove all children of the node.
bool MXmlNode::RemoveAttribute | ( | const MStdString & | name | ) |
Remove attribute by name or do nothing if there is no such attribute already.
name | Name of the attribute to remove. |
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.
nameOrNodeObject | This is either a name of the object, or it is the object itself. |
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.
name | Name of the 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.
node | Object that needs to be removed. |
void MXmlNode::RemoveExistingAttribute | ( | const MStdString & | name | ) |
Remove attribute by name.
If there was no such attribute, throw an error.
name | Name of the attribute to remove. |
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.
nameOrNodeObject | This is either a name of the object, or it is the object itself. |
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.
name | Name of the child. |
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.
node | Object that needs to be removed. |
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.
name | Name of the attribute to modify. |
value | The new value of the attribute. |
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:
void MXmlNode::SetStringText | ( | const MStdString & | ) |
String representation of text, C++ convenience function.
void MXmlNode::SetStringValue | ( | const MStdString & | ) |
String representation of value, C++ convenience function.
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:
Therefore, having node record:
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:
All other node types will return empty strings when accessed, and will throw an exception when assigned.