Пример #1
0
void XmlTree::appendRapidXmlNode( rapidxml::xml_document<char> &doc, rapidxml::xml_node<char> *parent ) const
{
	rapidxml::node_type type;
	switch( getNodeType() ) {
		case XmlTree::NODE_ELEMENT: type = rapidxml::node_element; break;
		case XmlTree::NODE_COMMENT: type = rapidxml::node_comment; break;
		case XmlTree::NODE_CDATA: type = rapidxml::node_cdata; break;
		case XmlTree::NODE_DATA: type = rapidxml::node_data; break;
		
		default: throw ExcUnknownNodeType();
	}
	rapidxml::xml_node<char> *node = 0;
	if( type == rapidxml::node_data ) {
		node = doc.allocate_node( type, NULL, doc.allocate_string( getValue().c_str() ) );
	}
	else if( type == rapidxml::node_comment ) {
		node = doc.allocate_node( type, doc.allocate_string( getTag().c_str() ), doc.allocate_string( getValue().c_str() ) );
	}
	else {
		node = doc.allocate_node( type, doc.allocate_string( getTag().c_str() ), NULL );
		if( ! getValue().empty() )
			node->append_node( doc.allocate_node( rapidxml::node_data, NULL, doc.allocate_string( getValue().c_str() ) ) );
	}
	parent->append_node( node );

	for( list<Attr>::const_iterator attrIt = mAttributes.begin(); attrIt != mAttributes.end(); ++attrIt )
		node->append_attribute( doc.allocate_attribute( doc.allocate_string( attrIt->getName().c_str() ), doc.allocate_string( attrIt->getValue().c_str() ) ) );
		
	for( Container::const_iterator childIt = mChildren.begin(); childIt != mChildren.end(); ++childIt )
		(*childIt)->appendRapidXmlNode( doc, node );
}
Пример #2
0
    void SetXMLValueForKey(const char* pKey, const char* value, rapidxml::xml_document<>& doc, rapidxml::xml_node<>* parentNode)
    {
        // check the params
        if (!pKey || !value || !parentNode)
        {
            return;
        }

        // find the node
        rapidxml::xml_node<>* node = parentNode->first_node(pKey);

        if (node)
        {
            if (node->first_node())
            {
                node->first_node()->value(doc.allocate_string(value));
            }
            else
            {
                node->value(doc.allocate_string(value));
            }
        }
        else
        {
            parentNode->append_node(doc.allocate_node(rapidxml::node_element, doc.allocate_string(pKey), doc.allocate_string(value)));
        }
    }
Пример #3
0
void XmlParse::InitXml(rapidxml::xml_document<> &doc)
{
    xml_node<> *node = doc.allocate_node(node_declaration, "", "");
    doc.append_node(node);
    xml_attribute<> *attr1 = doc.allocate_attribute("version", "1.0");
    xml_attribute<> *attr2 = doc.allocate_attribute("encoding", "UTF-8");
    node->append_attribute(attr1);
    node->append_attribute(attr2);
}
Пример #4
0
bool struct_xml(rapidxml::xml_node<> * & node, const ReqDeviceInfo & in, rapidxml::xml_document<> & doc)
{
node = doc.allocate_node(rapidxml::node_element, doc.allocate_string("ReqDeviceInfo"));
/* @generate [ userId:int ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, "userId", doc.allocate_string(get_string(in.userId).c_str()));
node->append_node(node1);
}
/* @generate [ userId:int ] end @ */

/* @generate [ deviceId:int ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, "deviceId", doc.allocate_string(get_string(in.deviceId).c_str()));
node->append_node(node1);
}
/* @generate [ deviceId:int ] end @ */

return true;
}
Пример #5
0
bool struct_xml(rapidxml::xml_node<> * & node, const RetDeviceInfo & in, rapidxml::xml_document<> & doc)
{
node = doc.allocate_node(rapidxml::node_element, doc.allocate_string("RetDeviceInfo"));
/* @generate [ userId:int ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, "userId", doc.allocate_string(get_string(in.userId).c_str()));
node->append_node(node1);
}
/* @generate [ userId:int ] end @ */

/* @generate [ deviceId:int ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, "deviceId", doc.allocate_string(get_string(in.deviceId).c_str()));
node->append_node(node1);
}
/* @generate [ deviceId:int ] end @ */

/* @generate [ deviceInfos:std::vector< ReqDeviceInfo > ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("deviceInfos"));
node->append_node(node1);
auto node2 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("Vector"));
node1->append_node(node2);
for(auto i = in.deviceInfos.begin(); i != in.deviceInfos.end(); ++i)
{
rapidxml::xml_node<> * tmp = 0;
if(!struct_xml(tmp, *i, doc))
return false;
node2->append_node(tmp);
}
}
/* @generate [ deviceInfos:std::vector< ReqDeviceInfo > ] end @ */

/* @generate [ deviceInfos2:std::vector< int > ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("deviceInfos2"));
node->append_node(node1);
auto node2 = doc.allocate_node(rapidxml::node_element, doc.allocate_string("Vector"));
node1->append_node(node2);
for(auto i = in.deviceInfos2.begin(); i != in.deviceInfos2.end(); ++i)
{
rapidxml::xml_node<> * tmp = 0;
if(!struct_xml(tmp, *i, doc))
return false;
node2->append_node(tmp);
}
}
/* @generate [ deviceInfos2:std::vector< int > ] end @ */

/* @generate [ deviceInfo:ReqDeviceInfo ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, "deviceInfo");
node->append_node(node1);
rapidxml::xml_node<> * node2 = 0;
if(!struct_xml(node2, in.deviceInfo, doc))
return false;
node1->append_node(node2);
}
/* @generate [ deviceInfo:ReqDeviceInfo ] end @ */

/* @generate [ time:int ] begin @ */

{
auto node1 = doc.allocate_node(rapidxml::node_element, "time", doc.allocate_string(get_string(in.time).c_str()));
node->append_node(node1);
}
/* @generate [ time:int ] end @ */

return true;
}