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


C++ xml_document::first_node方法代码示例

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


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

示例1: loadSRSML

void loadSRSML()
{

	cout << "parsing srsml..." << endl;


	// Read the xml file into a vector
	ifstream theFile ("gastrectomy.xml");
	vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
	buffer.push_back('\0');
	// Parse the buffer using the xml file parsing library into doc
	doc.parse<0>(&buffer[0]);
	// Find our root node
	cout << "parsing a root element" << endl;
	root_node = doc.first_node("srsml");

	int size = strlen((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("name"))->value());
	int size2 = strlen((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("type"))->value());

	// variables for malloc
	elements=(char*) malloc(size+1);
	elements2=(char*) malloc(size2+1);

	strcpy ((char*)elements,(char*)((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("name"))->value()));
	strcpy ((char*)elements2,(char*)((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("type"))->value()));

	// variables for string
	str_elements.assign((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("name"))->value());
	str_elements2.assign((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("type"))->value());

	// Iterate over the vessels
	if (root_node){
		cout << "if there is a root element" << endl;
		for (xml_node<> * models_node = root_node->first_node("models"); models_node!=NULL; models_node = models_node->next_sibling())
		{
			cout << "here is in the model for loop" << endl;
			for (xml_node<> * vessels_node = models_node->first_node("vessels"); vessels_node!=NULL; vessels_node = vessels_node->next_sibling())
			{
				cout << "here is in the vessels for loop" << endl;
				printf("I have visited in. ");//,
					// Interate over the beers
				cout << "here is before the inner for loop" << endl;
				for(xml_node<> * vessel_node = vessels_node->first_node("vessel"); vessel_node; vessel_node = vessel_node->next_sibling())
				{
					printf("On, I tried their %s which is a %s. ",
							vessel_node->first_attribute("name")->value(),
							vessel_node->first_attribute("type")->value());
				}
				cout << endl;
			}
		}
	}
}
开发者ID:sunghee,项目名称:SRSdemo-dev,代码行数:53,代码来源:SRSdemo-dev.cpp

示例2: parse

XmlNodeRef XmlParserImp::parse(char* buffer, int bufLen, const char* rootNodeName, behaviac::string& errorString, bool isFinal)
{
    BEHAVIAC_UNUSED_VAR(bufLen);
    BEHAVIAC_UNUSED_VAR(errorString);
    BEHAVIAC_UNUSED_VAR(isFinal);

    m_parser.parse<0>(buffer);

    xml_node<>* xmlnode = m_parser.first_node(rootNodeName);

    XmlNodeRef node = cloneXmlNodeFrom(xmlnode);

    return node;
}
开发者ID:ag6ag,项目名称:behaviac,代码行数:14,代码来源:xmlparser.cpp

示例3: load_bounds

void osm_loader::load_bounds() 
{
    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;

    string str = root->first_node("bound")->first_attribute("box")->value();
    vector<string> strs;
    boost::split(strs, str, boost::is_any_of(","));

    mins.x = atof(strs[0].c_str());
    mins.y = atof(strs[1].c_str());
    maxs.x = atof(strs[2].c_str());
    maxs.y = atof(strs[3].c_str());
}
开发者ID:griver,项目名称:Shortest-paths-on-road-graphs,代码行数:15,代码来源:osm_loader.cpp

示例4: loadXML

void loadXML()
{

	cout << "Parsing my beer journal..." << endl;


	// Read the xml file into a vector
	cout << "before loading a xml file" << endl;
	ifstream theFile ("beerJournal.xml");
	cout << "after loading a xml file" << endl;
	vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
	buffer.push_back('\0');
	// Parse the buffer using the xml file parsing library into doc
	doc.parse<0>(&buffer[0]);
	// Find our root node
	cout << "before parsing a root element" << endl;
	root_node = doc.first_node("MyBeerJournal");
	// Iterate over the brewerys
//	elements = "sldfjlsdjfldsjfldsjflsdjflds";
	elements=(char*) malloc(strlen(((((root_node)->first_node("Brewery"))->first_attribute("name"))->value()))+1);

	strcpy ((char*)elements,(char*)(((root_node)->first_node("Brewery"))->first_attribute("name"))->value());
	elements[strlen(((((root_node)->first_node("Brewery"))->first_attribute("name"))->value()))]='\0';
//	elements = "char";
	printf("here is element:%s\n",elements);
	cout << "after parsing a root element" << endl;
	if (root_node){
		cout << "if there is a root element" << endl;
		for (xml_node<> * brewery_node = root_node->first_node("Brewery"); brewery_node!=NULL; brewery_node = brewery_node->next_sibling())
		{
			cout << "here is in the for loop" << endl;
			printf("I have visited %s in %s. ",
				brewery_node->first_attribute("name")->value(),
				brewery_node->first_attribute("location")->value());
				// Interate over the beers
			cout << "here is before the inner for loop" << endl;
			for(xml_node<> * beer_node = brewery_node->first_node("Beer"); beer_node; beer_node = beer_node->next_sibling())
			{
				printf("On %s, I tried their %s which is a %s. ",
					beer_node->first_attribute("dateSampled")->value(),
					beer_node->first_attribute("name")->value(),
					beer_node->first_attribute("description")->value());
				printf("I gave it the following review: %s", beer_node->value());
			}
			cout << endl;
		}
	}
}
开发者ID:sunghee,项目名称:SRSdemo-dev,代码行数:48,代码来源:SRSdemo-dev.cpp

示例5: prepare_verts

void osm_loader::prepare_verts(unordered_set<xml_id> &verts_pending) 
{
    cout << "Preparing verts" << endl;
    
    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;

    size_t counter = 0;
    xml_node *node = root->first_node("node");
    while (node != NULL)
    {
        xml_id id = atol(node->first_attribute("id")->value());
        verts_pending.insert(id);
        node = node->next_sibling("node");
    }
}
开发者ID:griver,项目名称:Shortest-paths-on-road-graphs,代码行数:17,代码来源:osm_loader.cpp

示例6: load_verts

void osm_loader::load_verts() 
{
    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;
    
    size_t counter = 0;
    xml_node *node = root->first_node("node");
    while (node != NULL)
    {
        if (counter >= MAX_VERTS)
            break;
        xml_id id = atol(node->first_attribute("id")->value());

        if (pgraph_->vertex_exists(id))
        {
            vis_coord coord (atof(node->first_attribute("lat")->value()),
                             atof(node->first_attribute("lon")->value()));

            
            vis_vertex &v = pgraph_->get_vertex(id);
            vis_vertex_data &ref_data = v.get_data();

            ref_data.c = coord;
            
            int degree = v.get_out_degree();
            if (degree >= degrees_stats_.size())
                degrees_stats_.resize(degree + 1, 0);
            ++degrees_stats_[degree];
            

            if (counter % 100000 == 0)
                cout << counter << " verts loaded" << endl;
            ++counter;
        }
        node = node->next_sibling("node");
    }

    update_edge_weights();

}
开发者ID:griver,项目名称:Shortest-paths-on-road-graphs,代码行数:41,代码来源:osm_loader.cpp

示例7: load_edges

void osm_loader::load_edges()
{
    unordered_set<xml_id> verts_pending;
    prepare_verts(verts_pending);

    cout << "Loading edges" << endl;

    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;

    xml_node *node = root->first_node("way");
    while (node != NULL)
    {
        if (pgraph_->v_count() >= MAX_VERTS)
            break;

        load_way (node, verts_pending);
        node = node->next_sibling("way");
    }

}
开发者ID:griver,项目名称:Shortest-paths-on-road-graphs,代码行数:22,代码来源:osm_loader.cpp

示例8:

\endverbatim
//! <c>doc</c> object is now a root of DOM tree containing representation of the parsed XML.
//! Because all RapidXml interface is contained inside namespace <c>rapidxml</c>, 
//! users must either bring contents of this namespace into scope, or fully qualify all the names.
//! Class xml_document represents a root of the DOM hierarchy. 
//! By means of public inheritance, it is also an xml_node and a memory_pool.
//! Template parameter of xml_document::parse() function is used to specify parsing flags, 
//! with which you can fine-tune behaviour of the parser.
//! Note that flags must be a compile-time constant.
//!
//! \subsection accessing_dom_tree Accessing The DOM Tree
//!
//! To access the DOM tree, use methods of xml_node and xml_attribute classes:
//! \verbatim
cout << "Name of my first node is: " << doc.first_node()->name() << "\n";
xml_node<> *node = doc.first_node("foobar");
cout << "Node foobar has value " << node->value() << "\n";
for (xml_attribute<> *attr = node->first_attribute();
     attr; attr = attr->next_attribute())
{
    cout << "Node foobar has attribute " << attr->name() << " ";
    cout << "with value " << attr->value() << "\n";
}
\endverbatim
//!
//! \subsection modifying_dom_tree Modifying The DOM Tree
//!
//! DOM tree produced by the parser is fully modifiable. Nodes and attributes can be added/removed,
//! and their contents changed. The below example creates a HTML document, whose sole contents is a link to google.com website:
//! \verbatim
xml_document<> doc;
开发者ID:smanders,项目名称:rapidxml,代码行数:31,代码来源:manual-for-doxygen.hpp

示例9: loadEnvironment

void ProjectManager::loadEnvironment(xml_document<> &doc)
{
	objects.clear();

	cout << "loading environment..." << "\n" << flush;
	xml_node<> *profile = doc.first_node()->first_node("profile");
	xml_node<> *user = profile->first_node("user");
	xml_node<> *objecties = profile->first_node("object");
	//read x y z h p r from user block and place object there
	
	cout << "obtained variables..." << "\n" << flush;
	//look at obj nodes, then check the doc for the location, then import and position at the correct location
	
	string path = projectDir + "\\data\\obj";
	//string filename = objecties->first_node("resourceName")->value();
	cout << "projdir: " << projectDir << "\n" << flush;
	vector<string> pathv;
	vector<string> filenamev;
	vector<float> objx;
	vector<float> objy;
	vector<float> objz;
	vector<float> objh;
	vector<float> objp;
	vector<float> objr;
	vector<float> objscale;
	vector<char *> objname;
	//filenamev.push_back(filename);
	
	xml_node<> *userlocation = user->first_node("startingLocation");
	if (userlocation != 0)
	{
		float x = atof(userlocation->first_node("x")->value());
		float y = atof(userlocation->first_node("y")->value());
		float z = atof(userlocation->first_node("z")->value());
		float h = atof(userlocation->first_node("heading")->value());
		float p = atof(userlocation->first_node("pitch")->value());
		float r = atof(userlocation->first_node("roll")->value());
		char *name = user->first_node("name")->value();
		
		objx.push_back(x);
		objy.push_back(y+3.3); //for mrbody this should be y+3
		objz.push_back(z);
		objh.push_back(h);
		objp.push_back(p+180); //for mrbody this should be p-12
		objr.push_back(r);
		objscale.push_back(4); //for mrbody this should be 4
		objname.push_back(name);
		
		//string filename = "MrBodyWithHands.obj";
		string filename = "batman.obj";
		filenamev.push_back(filename);
		string pathy = PATH+"Kosmos\\data\\obj";
		pathv.push_back(pathy);
		//Import::import("cello.obj", x, y, z, h, p, r, "C:\\aszgard5\\szg\\projects\\Kosmos\\data\\obj");
	}
	
	
	
	
	while(objecties != 0)
	{
		cout << "loading object..." << "\n" << flush;
		//filename = "";
		// get xyzhpr and import object
		
		string filename = objecties->first_node("resourceName")->value();
		filenamev.push_back(filename);
		pathv.push_back(path);
		/*int length = filename.length();
		if (filename[length-1] == 'j' && filename[length-2] == 'b' && filename[length-3] == 'o')
		{
			cout << "wth file is obj " << "\n" << flush;
		}*/
		float x = atof(objecties->first_node("x")->value());
		float y = atof(objecties->first_node("y")->value());
		float z = atof(objecties->first_node("z")->value());
		float h = atof(objecties->first_node("heading")->value());
		float p = atof(objecties->first_node("pitch")->value());
		float r = atof(objecties->first_node("roll")->value());
		float s = atof(objecties->first_node("scale")->value());
		char *name = objecties->first_node("name")->value();
		
		objx.push_back(x);
		objy.push_back(y);
		objz.push_back(z);
		objh.push_back(h);
		objp.push_back(p);
		objr.push_back(r);
		objscale.push_back(s);
		objname.push_back(name);
		/*
			<resourceName>cello.obj</resourceName>
			<x>0</x>
			<y>4</y>
			<z>-4</z>
			<heading>0</heading>
			<pitch>0</pitch>
			<roll>0</roll>
		*/
		objecties = objecties->next_sibling();
//.........这里部分代码省略.........
开发者ID:KosmosSIDE,项目名称:Kosmos,代码行数:101,代码来源:ProjectManager.cpp


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