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


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

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


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

示例1: getNodeAttr

void getNodeAttr(string& result, const xml_node &node, const string& attrName) {
  result = "";
  for (auto attr: node.attributes()) {
    if (attr.name() == attrName) {
      result = attr.value();
      break;
    }
  }
}
开发者ID:CurataEng,项目名称:cyrss,代码行数:9,代码来源:pugi_util.cpp

示例2: LoadFromXml

	void Setting::LoadFromXml(xml_node& node) {
		name = node.attribute("name").as_string("");

		for (auto itemNode : node.children("item")) {
			
			SettingItem item = SettingItem();
			item.key = itemNode.attribute("key").as_string("");

			auto value = itemNode.attribute("value");

			if (value) {
				// single string  <item key="abc" value="def" />
				item.AddValues(value.as_string(""));
			}
			else {
				/* more xml elements:
				<item key="abc">
				<value>val1</value>
				<value>val2</value>
				</item>
				*/
				for (auto valueNode : itemNode.children("value")) {
					string val = valueNode.value();
					item.AddValues(val);
				}
			}

			items[item.key] = item;
		}

		// items may be declared as attributes, e.g. <setting name="myset" key1="value1" key2="value2" />
		for (auto attrNode : node.attributes()) {
			auto attrName = attrNode.name();
			if (string(attrName).compare("name") != 0) {
				string val = attrNode.value();
				items[attrName] = SettingItem(attrName, val);
			}
		}
	}
开发者ID:dormantor,项目名称:ofxCogEngine,代码行数:39,代码来源:Settings.cpp

示例3: initialise

bool Action::initialise(const xml_node& node)
{
	// The result of the initialisation
	bool result = true;

	// Set the path
	mPath = xvnu::path(node);

	// Get the action name
	string action = node.name();
	// Iterate over all valid action strings
	bool action_is_valid = false;
	for(string str : ACTIONS)
	{
		// If it is a valid action, set the flag true and break from the loop
		if(str == action)
		{
			action_is_valid = true;
			break;
		}
	}

	// If the boolean flag is still in a false state, no match was found. Report error and set results flag false.
	if(action_is_valid == false)
	{
		cout << "[email protected]" << mPath << " - \"" << action << "\" is not a valid action" << endl;
		result = false;
	}

	// Set the action
	mAction = action;

	// If the node has an attribute for the first variable, set it
	if(node.attribute("variable"))
		mVariableName = node.attribute("variable").as_string();
	// If it does not contain this attribute, report the error and set the result flag to false
	else
	{
		cout << "[email protected]" << mPath << " - \"variable\" attribute not found" << endl;
		result = false;
	}

	// Iterate over all attributes to find the second effector attribute
	for(auto& attribute : node.attributes())
	{
		// Get the attributes name
		string attribute_name = attribute.name();

		// Only consider attributes with names starting with "as", "to" or "by" as effector attributes.
		if(attribute_name.substr(0,2) == "as" || attribute_name.substr(0,2) == "to" || attribute_name.substr(0,2) == "by")
		{
			// If the end of the attributes name is "_variable", the attribute value is the effector variables name
			if(attribute_name.rfind("_") != string::npos && attribute_name.substr(attribute_name.rfind("_")) == "_variable")
				mEffectorVariableName = attribute.value();
			// Else the attribute value is the effector's literal value i.e. "123"
			else
				mEffectorVariableValue = attribute.value();
			break;
		}
	}

	// If both effector strings are empty, no suitable attribute was found. Report the error and set the result flag to false.
	if(mEffectorVariableValue.empty() && mEffectorVariableName.empty())
	{
		cout << "[email protected]" << mPath << " - no valid effector attribute found" << endl;
		result = false;
	}

	// Return the result of the initialise
	return result;
}
开发者ID:TVOHM,项目名称:xvn,代码行数:71,代码来源:Action.cpp


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