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


C++ pugi::xml_document类代码示例

本文整理汇总了C++中pugi::xml_document的典型用法代码示例。如果您正苦于以下问题:C++ xml_document类的具体用法?C++ xml_document怎么用?C++ xml_document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: appendValue

pugi::xml_node appendValue(pugi::xml_document & doc, string tag, string attribute, string newValue, bool overwriteMultiple){

    if (overwriteMultiple == true){
        // find the existing node...
        char xpathExpression[1024];
        sprintf(xpathExpression, "//%s[@%s='%s']", tag.c_str(), attribute.c_str(), newValue.c_str());
        pugi::xpath_node node = doc.select_single_node(xpathExpression);
        if(string(node.node().attribute(attribute.c_str()).value()).size() > 0){ // for some reason we get nulls here?
            // ...delete the existing node
            cout << "DELETING: " << node.node().name() << ": " << " " << node.node().attribute(attribute.c_str()).value() << endl;
            node.node().parent().remove_child(node.node());
        }
    }

    if (!doesTagAndAttributeExist(doc, tag, attribute, newValue)){
        // otherwise, add it please:
        char xpathExpression[1024];
        sprintf(xpathExpression, "//%s[@%s]", tag.c_str(), attribute.c_str());
        //cout << xpathExpression << endl;
        pugi::xpath_node_set add = doc.select_nodes(xpathExpression);
        pugi::xml_node node = add[add.size()-1].node();
        pugi::xml_node nodeAdded = node.parent().append_copy(node);
        nodeAdded.attribute(attribute.c_str()).set_value(newValue.c_str());
        return nodeAdded;
    }else{
    	return pugi::xml_node();
    }

}
开发者ID:CaterTsai,项目名称:openFrameworks,代码行数:29,代码来源:Utils.cpp

示例2: writer

void
docEdit::repaint( const pugi::xml_document& doc )
{
    if ( const pugi::xpath_node node = doc.select_single_node( "/article|/book" ) ) {
        try {
            detail::text_writer writer( *this );
            writer( node );
            auto cursor = textCursor();
            cursor.movePosition( QTextCursor::Start );
            ensureCursorVisible();
        } catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docEdit", ex.what() );
        }
    }
    else if ( const pugi::xpath_node node = doc.select_single_node( "/qtplatz_document" ) ) {
        // do nothing
    }
    else {
        try {
            detail::xhtml_writer writer( *this );
            writer( doc.select_single_node( "/" ) );
            auto cursor = textCursor();
            cursor.movePosition( QTextCursor::Start );
            ensureCursorVisible();
        }
        catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docEdit", ex.what() );
        }
    }
}
开发者ID:hermixy,项目名称:qtplatz,代码行数:30,代码来源:docedit.cpp

示例3: _LoadXmlDocment

BOOL SApplication::_LoadXmlDocment( LPCTSTR pszXmlName ,LPCTSTR pszType ,pugi::xml_document & xmlDoc,IResProvider *pResProvider/* = NULL*/)
{
    if(!pResProvider) 
    {
        if(IsFileType(pszType))
        {
            pugi::xml_parse_result result= xmlDoc.load_file(pszXmlName,pugi::parse_default,pugi::encoding_utf8);
            SASSERT_FMTW(result,L"parse xml error! xmlName=%s,desc=%s,offset=%d",pszXmlName,result.description(),result.offset);
            return result;
        }else
        {
            pResProvider = GetMatchResProvider(pszType,pszXmlName);
        }
    }
    if(!pResProvider) return FALSE;
    
    DWORD dwSize=pResProvider->GetRawBufferSize(pszType,pszXmlName);
    if(dwSize==0) return FALSE;

    CMyBuffer<char> strXml;
    strXml.Allocate(dwSize);
    pResProvider->GetRawBuffer(pszType,pszXmlName,strXml,dwSize);

    pugi::xml_parse_result result= xmlDoc.load_buffer(strXml,strXml.size(),pugi::parse_default,pugi::encoding_utf8);
    SASSERT_FMTW(result,L"parse xml error! xmlName=%s,desc=%s,offset=%d",pszXmlName,result.description(),result.offset);
    return result;
}
开发者ID:FuckGOV,项目名称:soui,代码行数:27,代码来源:SApp.cpp

示例4: writer

void
docTree::repaint( const pugi::xml_document& doc )
{
    QStandardItemModel& model = *model_;

    std::string xml;
    doc_->save( xml );

    model.clear();
    model.setColumnCount( 2 );

    if ( const pugi::xpath_node node = doc.select_single_node( "/article|/book" ) ) {
        try {
            detail::model_writer writer( *model_ );
            writer( node, QModelIndex() );
            expandAll();
        }
        catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docTree", ex.what() );
        }
    }
    else if ( const pugi::xpath_node node = doc.select_single_node( "/qtplatz_document" ) ) {
        try {
            detail::model_writer writer( *model_ );
            writer( node, QModelIndex() );
            expandAll();
        }
        catch ( pugi::xpath_exception& ex ) {
            QMessageBox::warning( this, "adpublisher::docTree", ex.what() );
        }
    }

}
开发者ID:hermixy,项目名称:qtplatz,代码行数:33,代码来源:doctree.cpp

示例5: initFromXML

bool XCScheme::initFromXML(const pugi::xml_document& doc)
{
  // Create an error reporter for parsing
  ErrorReporter reporter(SB_INFO, "Error parsing \"" + m_name + "\" scheme for \"" + m_parentProject->getName() + "\" project. ");
  
  // Find and process all BuildActionEntry nodes
  pugi::xpath_node_set baSet = doc.select_nodes("/Scheme/BuildAction/BuildActionEntries/BuildActionEntry");
  for (pugi::xpath_node_set::const_iterator it = baSet.begin(); it != baSet.end(); ++it)
    parseBuildAction(it->node(), reporter);
    
  // Find and process all ArchiveAction nodes
  pugi::xpath_node_set aaSet = doc.select_nodes("/Scheme/ArchiveAction");
  for (pugi::xpath_node_set::const_iterator it = aaSet.begin(); it != aaSet.end(); ++it)
    parseArchiveAction(it->node(), reporter);
  
  // Make sure we got enough information
  if (m_targets.empty()) {
    reporter.reportError("Failed to read any archiveable targets.");
    return false;
  } else if (m_configName.empty()) {
    reporter.reportError("Failed to read a valid build configuration name.");
    return false;
  } else {
    return true;
  }
}
开发者ID:GoogleInternetAuthorityG2SUNGHAN,项目名称:WinObjC,代码行数:26,代码来源:XCScheme.cpp

示例6: create_readings_xml

void Device::create_readings_xml(pugi::xml_document &doc, int n_readings)
{
        doc.reset();
        
        // client base node
        pugi::xml_node node = doc.append_child("client");
        
        xml_header(doc);
        xml_readings(doc, false, n_readings);
}
开发者ID:drkozuch,项目名称:CHARM,代码行数:10,代码来源:device.cpp

示例7: create_confirm_xml

void Device::create_confirm_xml(pugi::xml_document &doc, int n_readings)
{
        doc.reset();
        
        // client base node
        pugi::xml_node node = doc.append_child("server");
        
        xml_header(doc);
        xml_latest_readings(doc, true, n_readings);
}
开发者ID:drkozuch,项目名称:CHARM,代码行数:10,代码来源:device.cpp

示例8: deserialization

	bool FontExportSerializer::deserialization(pugi::xml_document& _doc)
	{
		if (_doc.select_single_node("MyGUI[@type=\"Resource\"]").node().empty())
			return false;

		pugi::xpath_node_set nodes = _doc.select_nodes("MyGUI/Resource[@type=\"ResourceTrueTypeFont\"]");
		for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++)
			parseFont((*node).node());

		return true;
	}
开发者ID:2asoft,项目名称:MMO-Framework,代码行数:11,代码来源:FontExportSerializer.cpp

示例9: saveXML

static bool saveXML(pugi::xml_document& document, const std::string& outputFile)
{
	pugi::xml_node decl = document.prepend_child(pugi::node_declaration);
	decl.append_attribute("version").set_value("1.0");
	decl.append_attribute("encoding").set_value("utf-8");
	if(!document.save_file(outputFile.c_str(), " ", 1U, pugi::encoding_utf8))
	{
		return false;
	}

	return true;
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例10: deserialization

	bool ImageExportSerializer::deserialization(pugi::xml_document& _doc)
	{
		if (_doc.select_single_node("MyGUI[@type=\"Resource\"]").node().empty())
			return false;

		pugi::xpath_node_set nodes = _doc.select_nodes("MyGUI/Resource[@type=\"ResourceImageSet\"]");
		for (pugi::xpath_node_set::const_iterator node = nodes.begin(); node != nodes.end(); node ++)
			parseImage((*node).node());

		updateImageProperty(DataManager::getInstance().getRoot());
		return true;
	}
开发者ID:MyGUI,项目名称:mygui,代码行数:12,代码来源:ImageExportSerializer.cpp

示例11: while

int HLR2::_exec(const char *url, const char *payload, unsigned short timeout, pugi::xml_document& doc, std::string& headers)
{
    const short maxTry = 3;
    short retry = 0;

    if (!url || !*url) {
        LOG_ERROR("%s::%s: Invalid URL!", __class__, __func__);
        return -1;
    }

    while (maxTry >= ++retry) {
        short status = _hc.httpPost(url, payload, "text/xml", timeout);
        LOG_INFO("%s::%s: url: %s, payload: %s, timeout: %d, status: %d, headers: %s, body: %s", __class__, __func__,
                url, payload, timeout, status, _hc.getResponseHeaders(), _hc.getResponseBody());

        if (200 != status && 307 != status) {
            return -1;
        }

        headers = _hc.getResponseHeaders();
        std::string body = _hc.getResponseBody();

        if (!doc.load(body.c_str())) {
            LOG_ERROR("%s::%s: Malformed XML response!: %s", __class__, __func__, body.c_str());
            return -1;
        }

        pugi::xml_node result = doc.find_node(_isResult);
        int resultCode = atoi(result.child("ResultCode").child_value());

        switch (resultCode) {
            case 0:
            case 3016:
            case 3810:
                //-- success, exit...
                return 0;
            case 5004:
                //-- invalid session, retry...
                LOG_INFO("%s::%s: Will retry: %d", __class__, __func__, retry);
                break;
            default:
                LOG_ERROR("%s::%s: ResultCode: %s, ResultDesc: %s", __class__, __func__,
                        result.child("ResultCode").child_value(), result.child("ResultDesc").child_value());
                return -1;
        }

        //-- wait for a while...
        sys_msleep(1000);
    }

    return -1;
}
开发者ID:zand3rs,项目名称:fun2,代码行数:52,代码来源:hlr2.cpp

示例12: InitConfig

int InitConfig(pugi::xml_document& config) {
	//check folders, create in dont exist
	wstring appDataPath = AppPath();

	wstring logPath;
	wstring rawCurrentPath;
	wstring logDailyPath;
	//config
	wstring configFile = appDataPath + L"\\etc\\sdr.xml";
	//because service runs at windows/System32 folder
	//we forced to use absolute path

	pugi::xml_parse_result result = config.load_file(configFile.data());
	if (result.status != pugi::status_ok) {
		return status_config_file_not_found;
	}
	//first install build directory tree

	logPath = L"\\log";
	rawCurrentPath = logPath + L"\\current\\";
	logDailyPath = logPath + L"\\daily\\";

	config.select_single_node(L"/sdr/recording/logs/base").node().attribute(
			L"path").set_value(logPath.data());
	config.select_single_node(L"/sdr/recording/logs/current").node().attribute(
			L"path").set_value(rawCurrentPath.data());
	config.select_single_node(L"/sdr/recording/logs/daily").node().attribute(
			L"path").set_value(logDailyPath.data());

	config.save_file(configFile.data());

	logPath = appDataPath + logPath;
	rawCurrentPath = appDataPath + rawCurrentPath;
	logDailyPath = appDataPath + logDailyPath;

	//create config folderst
	CreateDirectory(logPath.data(), 0);
	if (GetLastError() == ERROR_PATH_NOT_FOUND)
		return status_path_not_found;
	CreateDirectory(rawCurrentPath.data(), 0);
	if (GetLastError() == ERROR_PATH_NOT_FOUND)
		return status_path_not_found;
	CreateDirectory(logDailyPath.data(), 0);
	if (GetLastError() == ERROR_PATH_NOT_FOUND)
		return status_path_not_found;

	return status_ok;
}
开发者ID:systemdatarecorder,项目名称:recording,代码行数:48,代码来源:shared.cpp

示例13: read

bool program_data::read(const pugi::xml_document & doc)
{
    pugi::xml_node root_node = doc.child("program");
    if(root_node.empty())
        return false;

    pugi::xml_node vertex_node = root_node.child("shaders").child("vertex");
    if(vertex_node.text().empty())
        return false;
    pugi::xml_node fragment_node = root_node.child("shaders").child("fragment");
    if(fragment_node.text().empty())
        return false;

    v_shader_ = vertex_node.text().get();
    f_shader_ = fragment_node.text().get();

    pugi::xml_node a_locations_node = root_node.child("a_locations");
    for(const auto & value : a_locations_node.children("location"))
    {
        attribute_locations_.emplace_back(value.attribute("name").value(),
                                          value.attribute("index").as_int());
    }

    pugi::xml_node u_locations_node = root_node.child("u_locations");
    for(const auto & value : u_locations_node.children("location"))
    {
        uniform_locations_.emplace_back(value.attribute("name").value(),
                                        value.attribute("index").as_int());
    }

    return true;
}
开发者ID:jauseg,项目名称:elements,代码行数:32,代码来源:program_loader.cpp

示例14: _init

void Patent::_init(const pugi::xml_document& doc, const bool& loadAbstract, const bool& loadDescription) {
	pugi::xml_node root = doc.child("patent");

	text.clear();
	source_tfvec.clear();
	target_tfvec.clear();

	// walk through nodes below the root node to collect abstracts and descriptions
	for (pugi::xml_node node = root.first_child(); node; node = node.next_sibling()) {

		if ( strcmp(node.name(), "ucid") == 0 )
			ucid = node.text().as_string();
		else if ( strcmp(node.name(), "lang") == 0 )
			lang = node.text().as_string();
		else if ( loadAbstract
			 && strcmp(node.name(), "abstract") == 0 )
			this->loadText(node);
		else if ( loadDescription
			 && strcmp(node.name(), "description") == 0 )
			this->loadText(node);

	}

	s_count = text.size();

	isParsed = true;
}
开发者ID:fhieber,项目名称:cdec,代码行数:27,代码来源:patent.cpp

示例15: AppendDocumentCopy

	void AppendDocumentCopy(pugi::xml_node& target, pugi::xml_document& doc) {
		auto doc_children = doc.children();

		for(auto doc_child : doc_children) {
			target.append_copy(doc_child);
		}
	}
开发者ID:sashavolv2,项目名称:ge-xml,代码行数:7,代码来源:DOMUtils.cpp


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