MQXmlElement class

(new in Rev2.40)

MQXmlElement class manages XML data elements.

You can access XML data elements, text nodes and properties with multi-bytes characters in ANSI character code or wide characters in Unicode(UTF-16) through this class from plug-ins.


MQXmlElement MQXmlElement::AddChildElement(const char *name);
MQXmlElement MQXmlElement::AddChildElement(const wchar_t *name);

name
An element name
Return value
XML data element

It adds a new XML element as a child node to this XML element.


BOOL MQXmlElement::RemoveChildElement(MQXmlElement child);

child
A child element name
Return value
[TRUE] Succeeded
[FALSE] The specified child element does not exist

It deletes a child element.


MQXmlElement MQXmlElement::FirstChildElement(void);
MQXmlElement MQXmlElement::FirstChildElement(const char *name);
MQXmlElement MQXmlElement::FirstChildElement(const wchar_t *name);

name
A child element name
Return value
XML element (NULL if not exist)

It returns a top node in the child elements. And it returns a top node in the elements which element name is matched when you specified name.

It returns NULL if no child node exists or matched element name does not exist.


MQXmlElement MQXmlElement::NextChildElement(MQXmlElement child);
MQXmlElement MQXmlElement::NextChildElement(const char *name, MQXmlElement child);
MQXmlElement MQXmlElement::NextChildElement(const wchar_t *name, MQXmlElement child);

name
A child element name
child
A child XML element (It is a big brother of the return element.)
Return value
A XML element (NULL if not exist)

It returns a next child element. When name is specified, it returns the next child element which name matches. When a child element does not exist or it did not find matched name, it returns NULL.

You must call this function following FirstChildElement(). You can get all the child elements by continue calling FirstChildElement() and NextChidlElement() until the return value is set to be NULL.

Example
All names and texts in all child nodes are written to the debug window in this sample.
MQXmlElement child = elem->FirstChildElement();
while (child != NULL){
        std::string name = child->GetName();
        std::string text = child->GetText();
        OutputDebugString("<%s>%s</%s>\n",name.c_str(),text.c_str(),name.c_str());
        child = elem->NextChildElement(child);
}

MQXmlElement MQXmlElement::GetParentElement(void);

Return value
A parent element (NULL if not exist)

It gets a parent element.


std::string MQXmlElement::GetName(void);
std::wstring MQXmlElement::GetNameW(void);

Return value
A XML element name

It gets the element name.


std::string MQXmlElement::GetText(void);
std::wstring MQXmlElement::GetTextW(void);
BOOL MQXmlElement::GetText(std::string& result_str);
BOOL MQXmlElement::GetTextW(std::wstring& result_str);

result_str
A value of the XML text node
Return value
[std::string / std::wstring] A value in a XML text node (Empty string if the node does not exist)
[BOOL - TRUE] A text node exists
[BOOL - FALSE] A text node does not exist

It gets a value of a text node contained in the XML element.


std::string MQXmlElement::GetAttribute(const char *name);
std::wstring MQXmlElement::GetAttribute(const wchar_t *name);
BOOL MQXmlElement::GetAttribute(const char *name, std::string& result_str);
BOOL MQXmlElement::GetAttribute(const wchar_t *name, std::wstring& result_str);

name
An attribute name
result_str
A value of the attribute
Return value
[std::string / std::wstring] A value of an attribute (Empty string if the node does not exist)
[BOOL - TRUE] An attribute node exists
[BOOL - FALSE] An attribute node does not exist

It gets a value of the specified attribute contained in the XML element.


void MQXmlElement::SetText(const char *text);
void MQXmlElement::SetText(const wchar_t *text);

text
A value of the text

It adds a text node to the XML element.


void MQXmlElement::SetAttribute(const char *name, const char *value);
void MQXmlElement::SetAttribute(const wchar_t *name, const wchar_t *value);

name
An attribute name
value
A value of the attribute

It adds an attribute to the XML element.