Karlsruhe Institute of Technology (KIT) Logo

Master Motor Map

Whole-body human reference model and tools for unifying representations of whole-body human motion

Rapid XML

Rapid XML is a very fast header only C++ XML reader which is used within the MMM framework.

Process XML string

// include MMM XMLTools
#include "XMLTools.h"
// include rapidxml
void myXMLParseMethod(std::string &xmlString)
{
try
{
rapidxml::xml_document<char> doc; // character type defaults to char
char* y = doc.allocate_string(xmlString.c_str()); // the memory is automatically deleted when doc dies
doc.parse<0>(y); // 0 means default parse flags
// get first tag
while (node)
{
std::string nodeName = XML::getLowerCase(node->name());
// process xml tag with name nodeName, e.g.
if (nodeName == "myCustomTag")
processTag(node);
// get next tag
node = node->next_sibling();
}
}
{
// some error processing
}
}

Access XML hierarchy and attributes

bool processTag(rapidxml::xml_node<char>* tag)
{
// get an attribute
rapidxml::xml_attribute<> *attr = tag->first_attribute("type", 0, false);
if (attr)
{
// process attribute as float
float f = XML::convertToFloat(attr->value());
// process string attribute
std::string s = attr->value();
}
// get second level tag hierarchy
while (node)
{
std::string nodeName = XML::getLowerCase(node->name());
// process second level tags ...
node = node->next_sibling();
}
}

RapidXmlHelper

To process motions in MMM Data Format we are using two helper classes for easier access to the API.
The MMM::RapidXMLReader is used to read the information from an XML document. Each XML node is type of MMM::RapidXMLReaderNode. If a node or attribute is not included an exception is thrown.
Here is an example:

// include RapidXMLReader
#include "RapidXML/RapidXMLReader.h"
void exampleXMLParseMethod(std::string &xmlString)
{
RapidXMLReaderPtr reader = RapidXMLReader::FromXmlString(xmlString);
RapidXMLReaderNodePtr node = reader->getRoot();
std::string nodeName = node->name();
if (node->name() == "ExampleRootNode" && node->has_attribute("type") && node->attribute_value("type") == "Example") {
for (RapidXMLReaderNodePtr child : node->nodes("ExampleChildNode") {
std::string s = child->value();
std::cout << s; // print content of <ExampleChildNode>
}
}
}
int main() {
exampleXMLParseMethod(
"<?xml version='1.0' encoding='utf-8'?>"
"<ExampleRootNode type='Example'>"
" <ExampleChildNode>Some </ExampleChildNode>"
" <ExampleChildNode2>non interesting </ExampleChildNode2>"
" <ExampleChildNode>content</ExampleChildNode>"
"</ExampleRootNode>"
); // prints "Some content"
}


The MMM::RapidXMLWriter is used to convert C++ objects to an XML document. Each XML node is type of MMM::RapidXMLWriterNode.
Here is an example:

// include RapidXMLWriter
#include "RapidXML/RapidXMLWriter.h"
int main() {
RapidXMLWriterPtr writer(new RapidXMLWriter());
RapidXMLWriterNodePtr node = writer->createRootNode("ExampleRootNode");
node->append_attribute("type", "Example");
RapidXMLWriterNodePtr childNode = node->append_node("ExampleChildNode");
childNode->append_data_node("Some content");
// "<?xml version='1.0' encoding='utf-8'?>
// <ExampleRootNode type='Example'>
// <ExampleChildNode>Some content</ExampleChildNode>
// </ExampleRootNode>"
std::cout << writer->print(true);
// "<?xml version='1.0' encoding='utf-8'?><ExampleRootNode type='Example'><ExampleChildNode>Some content</ExampleChildNode></ExampleRootNode>"
std::cout << writer->print(false);
}
KoroiBot Logo WALK-MAN Logo Xperience Logo SecondHands Logo TimeStorm Logo I-SUPPORT Logo
PACO-PLUS Logo SFB-588 Logo SPP1527 Logo