当前位置: 首页>>代码示例>>C++>>正文


C++ xml_node::append_child方法代码示例

本文整理汇总了C++中xml_node::append_child方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_node::append_child方法的具体用法?C++ xml_node::append_child怎么用?C++ xml_node::append_child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml_node的用法示例。


在下文中一共展示了xml_node::append_child方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: appendNode

xml_node ModelToXmlConverter::appendNode(const Node& node, xml_node& xnode)
{
    Logger::entry("info") << "Appending child " << node.name();
    xml_node newNode = xnode.append_child(node.name().c_str());
    if (node.hasValue())
    {
        newNode.append_child(node_pcdata).set_value(node.value().c_str());
    }
    if (newNode.empty())
    {
        Logger::entry("info") << "Error when adding new xml node " << node.name() << ". Skipping node.";
        return newNode;
    }
    list< Attribute > attributes = node.attributes();
    list< Attribute >::iterator attrIt = attributes.begin();
    for (; attrIt != attributes.end(); ++attrIt)
    {
        xml_attribute attr = newNode.append_attribute(attrIt->name().c_str());
        if (attr.empty())
        {
            Logger::entry("info") << "Error when adding new attribute " << attrIt->name() << " to node " << node.name() << ". Skipping attribute.";
            continue;
        }
        attr.set_value(attrIt->value().c_str());
    }
    return newNode;
}
开发者ID:flaviu-toader,项目名称:vanetizer-c--,代码行数:27,代码来源:modeltoxmlconverter.cpp

示例2: appendObject

void appendObject(Value& val, xml_node& node)
{
    xml_node children;
    switch(val.getType())
    {
        case Value::Type::MAP:
            children = node.append_child("dict");
            for(ValueMap::iterator it = val.asValueMap().begin(); it != val.asValueMap().end(); ++it) {
                children.append_child("key").append_child(node_pcdata).set_value(it->first.c_str());
                appendObject(it->second, children);
            }
            break;
        case Value::Type::INT_KEY_MAP:
            children = node.append_child("intKeydict");
            for(ValueMapIntKey::iterator it = val.asIntKeyMap().begin(); it != val.asIntKeyMap().end(); ++it)
            {
                children.append_child("key").append_child(node_pcdata).set_value(std::to_string(it->first).c_str());
                appendObject(it->second, children);
            }
            break;
        case Value::Type::VECTOR:
            children = node.append_child("array");
            for(ValueVector::iterator it = val.asValueVector().begin(); it < val.asValueVector().end(); it++) {
                appendObject(*it, children);
            }
            break;
        case Value::Type::STRING:
            node.append_child("string").append_child(node_pcdata).set_value(val.asString().c_str());
            break;
        case Value::Type::INTEGER:
            node.append_child("integer").append_child(node_pcdata).set_value(val.asString().c_str());
            break;
        case Value::Type::FLOAT:
        case Value::Type::DOUBLE:
            node.append_child("real").append_child(node_pcdata).set_value(val.asString().c_str());
            break;
        case Value::Type::BOOLEAN:
            node.append_child(val.asBool() ? "true" : "false");
            break;
        default:
#if VERBOSE_SAVE_PLIST
            log("Warning: unrecognized Value type when saving plist, check if the object is in plist format. Value description: %s", val.getDescription().c_str());
#endif
            break;
    }
}
开发者ID:FenneX,项目名称:FenneXEmptyProject,代码行数:46,代码来源:PListPersist.cpp

示例3: appendObject

void appendObject(Ref* obj, xml_node& node)
{
    if(isKindOfClass(obj, CCDictionary))
    {
        //CCLOG("Dictionary recognized");
        CCDictionary* dict = (CCDictionary*)obj;
        xml_node children = node.append_child("dict");
        CCArray* keys = dict->allKeys();
        if(keys != NULL)
        {
            for(int i = 0; i < keys->count(); i++)
            {
                CCString* key = (CCString*)keys->objectAtIndex(i);
                children.append_child("key").append_child(node_pcdata).set_value(key->getCString());
                appendObject(dict->objectForKey(key->getCString()), children);
            }
        }
    }
    else if(isKindOfClass(obj, CCArray))
    {
        //CCLOG("Array recognized");
        CCArray* array = (CCArray*)obj;
        xml_node children = node.append_child("array");
        for(int i = 0; i < array->count(); i++)
        {
            Ref* child = (Ref*)array->objectAtIndex(i);
            appendObject(child, children);
        }
    }
    else if (isKindOfClass(obj, CCString))
    {
        //CCLOG("String recognized");
        node.append_child("string").append_child(node_pcdata).set_value(((CCString*)obj)->getCString());
    }
    else if (isKindOfClass(obj, CCInteger))
    {
        //CCLOG("Integer recognized");
        int value = TOINT(obj);
        CCString* stringVal = ScreateF("%d", value);
        node.append_child("integer").append_child(node_pcdata).set_value(stringVal->getCString());
    }
    else if (isKindOfClass(obj, CCFloat))
    {
        //CCLOG("Float recognized");
        float value = TOFLOAT(obj);
        CCString* stringVal = ScreateF("%g", value);
        node.append_child("real").append_child(node_pcdata).set_value(stringVal->getCString());
    }
    else if (isKindOfClass(obj, CCBool))
    {
        //CCLOG("Bool recognized");
        bool value = TOBOOL(obj);
        node.append_child(value ? "true" : "false");
    }
#if VERBOSE_SAVE_PLIST
    else
    {
        CCLOG("Warning: unrecognized type %s when saving plist, check if the object is in plist format", typeid(*obj).name());
    }
#endif
}
开发者ID:FenneX,项目名称:FenneXTestProject,代码行数:61,代码来源:PListPersist.cpp

示例4: ImportResource

void ImportResource(xml_node xmlNode, const tstring & strUiresDir,const tstring & strNamePrefix,xml_node xmlSkin)
{
    WIN32_FIND_DATA fd;
    HANDLE hContext = ::FindFirstFile((strUiresDir+_T("\\*.*")).c_str(), &fd);
    if(hContext!=INVALID_HANDLE_VALUE)
    {
        while(::FindNextFile(hContext,&fd))
        {
            if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                if(_tcscmp(fd.cFileName,_T(".")) == 0 || _tcscmp(fd.cFileName,_T("..")) == 0)
                    continue;
                ImportResource(xmlNode, strUiresDir+_T("\\")+ fd.cFileName, strNamePrefix+ fd.cFileName + _T("."),xmlSkin);
            }else
            {
                xml_node newFile = xmlNode.append_child(_T("file"));
                TCHAR szName[MAX_PATH],szExt[50];
                _tsplitpath(fd.cFileName,NULL,NULL,szName,szExt);

                tstring strName,strPath;
                strName = strNamePrefix+szName;
                strPath = strUiresDir + _T("\\") + fd.cFileName;
                if(xmlSkin)
                {
                    LPTSTR p = _tcsrchr(szName,'[');
                    {
                        if(p) *p = 0;
                        strName = strNamePrefix+szName;
                        tstring src = xmlNode.name();
                        src += _T(":");
                        src += strName;
                        
                        xml_node node = xmlSkin.find_child_by_attribute(_T("name"),strName.c_str());
                        if(node) xmlSkin.remove_child(node);//自动使用新的皮肤替换原有皮肤。

                        int nStates=1, left=-1,top=-1,right=-1,bottom=-1;
                        int nValues = 0;

                        int nColorize = g_bEnableColorize?1:0, //着色标志 {ec=0/1}
                            nAutoFit = 1,  //自适应标志{fit=0/1}
                            nTile = 0,     //平铺标志{tile=0/1}
                            nVertical = 0, //子图垂直排列标志{vert=0/1}
                            nFilter=0;     //绘制滤镜:{filter=0/1/2/3} 0=null,1=low,2=midium,3=high
                        
                        if(p)
                        {
                            nValues = _stscanf(p+1,_T("%d{%d,%d,%d,%d}]"),&nStates,&left,&top,&right,&bottom);

                            LPCTSTR pszFind = _tcsstr(p+1,_T("{ec="));
                            if(pszFind) nColorize = _ttoi(pszFind+4);
                            pszFind = _tcsstr(p+1,_T("{fit="));
                            if(pszFind) nAutoFit = _ttoi(pszFind+5);
                            pszFind = _tcsstr(p+1,_T("{filter="));
                            if(pszFind) nFilter = _ttoi(pszFind+8);
                            pszFind = _tcsstr(p+1,_T("{tile="));
                            if(pszFind) nTile = _ttoi(pszFind+6);
                            pszFind = _tcsstr(p+1,_T("{vert="));
                            if(pszFind) nVertical = _ttoi(pszFind+6);
                        }

                        xml_node il = xmlSkin.append_child();
                        il.append_attribute(_T("name")).set_value(strName.c_str());
                        il.append_attribute(_T("src")).set_value(src.c_str());
                        il.append_attribute(_T("states")).set_value(nStates);
                        if(nValues==0 || nValues == 1)
                        {//imglist
                            il.set_name(_T("imglist"));
                        }else if(nValues==3 || nValues == 5)
                        {//imgframe
                            il.set_name(_T("imgframe"));

                            TCHAR szMargin[100];
                            _stprintf(szMargin,_T("%d,%d,%d,%d"),left,top,right==-1?left:right,bottom==-1?top:bottom);
                            il.append_attribute(_T("margin")).set_value(szMargin);
                        }

                        //设置各种可先属性
                        if(nColorize == 0) il.append_attribute(_T("enableColorize")).set_value(0);
                        if(nAutoFit == 0) il.append_attribute(_T("autoFit")).set_value(0);
                        if(nTile !=0 ) il.append_attribute(_T("tile")).set_value(1);
                        if(nVertical != 0 ) il.append_attribute(_T("vertical")).set_value(1);
                        switch(nFilter)
                        {
                        case 1:il.append_attribute(_T("filterLevel")).set_value(_T("low"));break;
                        case 2:il.append_attribute(_T("filterLevel")).set_value(_T("midium"));break;
                        case 3:il.append_attribute(_T("filterLevel")).set_value(_T("high"));break;
                        }
                    }
                }
                newFile.append_attribute(L"name").set_value(strName.c_str());
                newFile.append_attribute(L"path").set_value(strPath.c_str());
            }
        }
        ::FindClose(hContext);
    }
}
开发者ID:FuckGOV,项目名称:soui,代码行数:96,代码来源:uiresImporter.cpp

示例5: xml_write_node

xml_node xml_write_node(Node *node, xml_node xml_root)
{
	xml_node xml_node = xml_root.append_child(node->type->name.c_str());

	xml_node.append_attribute("name") = node->name.c_str();

	foreach(const SocketType& socket, node->type->inputs) {
		if(socket.type == SocketType::CLOSURE || socket.type == SocketType::UNDEFINED) {
			continue;
		}
		if(socket.flags & SocketType::INTERNAL) {
			continue;
		}
		if(node->has_default_value(socket)) {
			continue;
		}

		xml_attribute attr = xml_node.append_attribute(socket.name.c_str());

		switch(socket.type)
		{
			case SocketType::BOOLEAN:
			{
				attr = xml_write_boolean(node->get_bool(socket));
				break;
			}
			case SocketType::BOOLEAN_ARRAY:
			{
				std::stringstream ss;
				const array<bool>& value = node->get_bool_array(socket);
				for(size_t i = 0; i < value.size(); i++) {
					ss << xml_write_boolean(value[i]);
					if(i != value.size() - 1)
						ss << " ";
				}
				attr = ss.str().c_str();
				break;
			}
			case SocketType::FLOAT:
			{
				attr = (double)node->get_float(socket);
				break;
			}
			case SocketType::FLOAT_ARRAY:
			{
				std::stringstream ss;
				const array<float>& value = node->get_float_array(socket);
				for(size_t i = 0; i < value.size(); i++) {
					ss << value[i];
					if(i != value.size() - 1) {
						ss << " ";
					}
				}
				attr = ss.str().c_str();
				break;
			}
			case SocketType::INT:
			{
				attr = node->get_int(socket);
				break;
			}
			case SocketType::UINT:
			{
				attr = node->get_uint(socket);
				break;
			}
			case SocketType::INT_ARRAY:
			{
				std::stringstream ss;
				const array<int>& value = node->get_int_array(socket);
				for(size_t i = 0; i < value.size(); i++) {
					ss << value[i];
					if(i != value.size() - 1) {
						ss << " ";
					}
				}
				attr = ss.str().c_str();
				break;
			}
			case SocketType::COLOR:
			case SocketType::VECTOR:
			case SocketType::POINT:
			case SocketType::NORMAL:
			{
				float3 value = node->get_float3(socket);
				attr = string_printf("%g %g %g", (double)value.x, (double)value.y, (double)value.z).c_str();
				break;
			}
			case SocketType::COLOR_ARRAY:
			case SocketType::VECTOR_ARRAY:
			case SocketType::POINT_ARRAY:
			case SocketType::NORMAL_ARRAY:
			{
				std::stringstream ss;
				const array<float3>& value = node->get_float3_array(socket);
				for(size_t i = 0; i < value.size(); i++) {
					ss << string_printf("%g %g %g", (double)value[i].x, (double)value[i].y, (double)value[i].z);
					if(i != value.size() - 1) {
						ss << " ";
					}
//.........这里部分代码省略.........
开发者ID:bdancer,项目名称:blender-for-vray,代码行数:101,代码来源:node_xml.cpp


注:本文中的xml_node::append_child方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。