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


C++ XMLAttribute类代码示例

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


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

示例1: if

void AttrWidgetVectorFloat::Refresh(const XMLAttribute &attribute)
{
    AttributeWidget::Refresh(attribute);

    XMLAttribute::Type attrType = attribute.GetType();

    Array<float> vf;
    if (attrType == XMLAttribute::Type::Float)
    {
        float v = attribute.GetFloat();
        vf = {v};
    }
    else if (attrType == XMLAttribute::Type::Vector2)
    {
        Vector2 v = attribute.GetVector2();
        vf = {v.x, v.y};
    }
    else if (attrType == XMLAttribute::Type::Vector3)
    {
        Vector3 v = attribute.GetVector3();
        vf = {v.x, v.y, v.z};
    }
    else if (attrType == XMLAttribute::Type::Vector4 ||
             attrType == XMLAttribute::Type::Quaternion ||
             attrType == XMLAttribute::Type::Rect)
    {
        Vector4 v = attribute.GetVector4();
        vf = {v.x, v.y, v.z, v.w};
    }

    SetValue(vf);
}
开发者ID:sephirot47,项目名称:Bang,代码行数:32,代码来源:AttrWidgetVectorFloat.cpp

示例2: new

XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
{
    XMLAttribute* last = 0;
    XMLAttribute* attrib = 0;
    for( attrib = rootAttribute;
         attrib;
         last = attrib, attrib = attrib->next )
    {
        if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
            break;
        }
    }
    if ( !attrib ) {
        attrib = new (document->attributePool.Alloc() ) XMLAttribute();
        attrib->memPool = &document->attributePool;
        if ( last ) {
            last->next = attrib;
        }
        else {
            rootAttribute = attrib;
        }
        attrib->SetName( name );
    }
    return attrib;
}
开发者ID:CoryXie,项目名称:Mindroid.cpp,代码行数:25,代码来源:tinyxml2.cpp

示例3:

XMLAttribute *XMLTreeNode::GetAttribute(const char *name) const
{
	XMLAttribute *a;

	a=attributes;

	while (a)
	{
		if (a->GetName())
		{
			switch (mmode)
			{
			case MATCH_CASE:
				if (!strcmp(a->GetName(), name)) return a;

			case MATCH_NOCASE:
				if (!stricmp(a->GetName(), name)) return a;
			}
		}

		a=a->GetNext();
	}

	return 0;
}
开发者ID:Coolstreamto,项目名称:Coolto,代码行数:25,代码来源:xmltree.cpp

示例4: new

	XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
	{
		XMLAttribute* last = 0;
		XMLAttribute* attrib = 0;
		for( attrib = _rootAttribute;
			attrib;
			last = attrib, attrib = attrib->_next ) {
				if ( XMLUtil::StringEqual( attrib->Name(), name ) ) {
					break;
				}
		}
		if ( !attrib ) {
			attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
			attrib->_memPool = &_document->_attributePool;
			if ( last ) {
				last->_next = attrib;
			}
			else {
				_rootAttribute = attrib;
			}
			attrib->SetName( name );
			attrib->_memPool->SetTracked(); // always created and linked.
		}
		return attrib;
	}
开发者ID:dominik-uebele,项目名称:E1,代码行数:25,代码来源:tinyxml2.cpp

示例5: while

void ConfigSingleton::configure(std::string xml_file_path)
{
    //Open XML config file and try to load it
    XMLDocument doc;
    if(doc.LoadFile(xml_file_path.c_str()) != XML_SUCCESS)
    {
        std::cerr << "Cannot reach configuration file: " << xml_file_path << "!" << std::endl;
        return;
    }

    //Look for <config> element
    XMLElement* pConfig = doc.FirstChildElement("root")->FirstChildElement("config");
    if(pConfig==nullptr)
    {
        std::cerr << "Invalid configuration file: " << xml_file_path << "!" << std::endl;
        return;
    }

    //Iterate attribute list and set parameter values
    //Version 2 of TinyXML won't let me iterate over Attribute list this way by returning
    //const XMLAttribute*. I'm forced to const_cast before I find an elegant way of doing this.
    XMLAttribute* pAttrib = const_cast<XMLAttribute*>(pConfig->FirstAttribute());
    while(pAttrib != nullptr)
    {
        set_parameter(pAttrib->Name(),pAttrib->Value());
        pAttrib = const_cast<XMLAttribute*>(pAttrib->Next());
    }
}
开发者ID:ndoxx,项目名称:BinnoBot,代码行数:28,代码来源:ConfigSingleton.cpp

示例6: walker

void XMLElement::walkTree(Log::ModuleId logModule, Log::Level level,
        unsigned int depth, XMLElement node) {
#ifdef PUGIXML
    xml_tree_walker walker(logModule, level);
    node.nodePtr.traverse(walker);
#else
    while (node.isValid()) {
        XMLElement::Type nodeType = node.getType();
        XMLAttribute attr;
        xmlChar *value;

        if (XMLElement::ELEMENT_NODE == nodeType) {
            if (node.nodePtr->name) {
                Log::log(logModule, level, "Element = %s",
                        node.nodePtr->name);
            } else {
                Log::log(logModule, level, "Element, unnamed");
            }

            for (attr = node.getFirstAttribute(); attr.isValid(); attr.next()) {
                attr.log(logModule, level, depth);
            }

            walkTree(logModule, level, depth + 1, node.getFirstSubElement());
        } else if (XMLElement::CDATA_NODE == nodeType) {
            value = xmlNodeGetContent(node.nodePtr);
            if (value) {
                Log::log(logModule, level, "CDATA = '%s'",
                        value);
                xmlFree(value);
            } else {
                Log::log(logModule, level, "CDATA unable to retrieve value");
            }
        } else if (XMLElement::TEXT_NODE == nodeType) {
            value = xmlNodeGetContent(node.nodePtr);
            if (value) {
                Log::log(logModule, level, "TEXT = '%s'", value);
                xmlFree(value);
            } else {
                Log::log(logModule, level, "TEXT unable to retrieve value");
            }
        } else {
            value = xmlNodeGetContent(node.nodePtr);
            if (value) {
                Log::log(logModule, level, "Type = %d, value = %s",
                        nodeType, value);
                xmlFree(value);
            } else {
                Log::log(logModule, level,
                        "Type = %d, unable to retrieve value",
                        nodeType);
            }
        }

        node.nextSibling();
    }
#endif
}
开发者ID:JonathanFu,项目名称:OpenAM-1,代码行数:58,代码来源:xml_element.cpp

示例7: FindAttribute

const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
{
	XMLAttribute* a = 0;
	for( a=rootAttribute; a; a = a->next ) {
		if ( XMLUtil::StringEqual( a->Name(), name ) )
			return a;
	}
	return 0;
}
开发者ID:jebradwell,项目名称:Eternal-Elucidation,代码行数:9,代码来源:tinyxml2.cpp

示例8: getRealValue

/** helper function to return the real value of the string (HEX or normal) */
static std::string getRealValue(XMLElement* e)
{
	std::string str = e->getFirstText();
	XMLAttribute* a = e->getAttribute("type");

	if (a && a->getValue() == "HEX")
		return StringFilter::hexparser(str);

	return str;
}
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:11,代码来源:PacketFilterCfg.cpp

示例9: preciceTrace1

void XMLTag:: addAttribute
(
  const XMLAttribute<double>& attribute )
{
  preciceTrace1 ( "addAttribute<double>()", attribute.getName() );
  assertion(not utils::contained(attribute.getName(), _attributes));
  _attributes.insert(attribute.getName());
  _doubleAttributes.insert(std::pair<std::string,XMLAttribute<double> >
                           (attribute.getName(), attribute));
}
开发者ID:Alexander-Shukaev,项目名称:precice,代码行数:10,代码来源:XMLTag.cpp

示例10: while

	char* XMLElement::ParseAttributes( char* p )
	{
		const char* start = p;
		XMLAttribute* prevAttribute = 0;

		// Read the attributes.
		while( p ) {
			p = XMLUtil::SkipWhiteSpace( p );
			if ( !p || !(*p) ) {
				_document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() );
				return 0;
			}

			// attribute.
			if (XMLUtil::IsNameStartChar( *p ) ) {
				XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
				attrib->_memPool = &_document->_attributePool;
				attrib->_memPool->SetTracked();

				p = attrib->ParseDeep( p, _document->ProcessEntities() );
				if ( !p || Attribute( attrib->Name() ) ) {
					DELETE_ATTRIBUTE( attrib );
					_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p );
					return 0;
				}
				// There is a minor bug here: if the attribute in the source xml
				// document is duplicated, it will not be detected and the
				// attribute will be doubly added. However, tracking the 'prevAttribute'
				// avoids re-scanning the attribute list. Preferring performance for
				// now, may reconsider in the future.
				if ( prevAttribute ) {
					prevAttribute->_next = attrib;
				}
				else {
					_rootAttribute = attrib;
				}
				prevAttribute = attrib;
			}
			// end of the tag
			else if ( *p == '/' && *(p+1) == '>' ) {
				_closingType = CLOSED;
				return p+2;	// done; sealed element.
			}
			// end of the tag
			else if ( *p == '>' ) {
				++p;
				break;
			}
			else {
				_document->SetError( XML_ERROR_PARSING_ELEMENT, start, p );
				return 0;
			}
		}
		return p;
	}
开发者ID:dominik-uebele,项目名称:E1,代码行数:55,代码来源:tinyxml2.cpp

示例11: proceedNode

bool Parser::proceedNode(Node* node, rapidxml::xml_node<>* xml_node)
{
	if (node && xml_node)
	{
		// Check required attributes
		for (std::map<std::string, bool>::const_iterator it = node->getAttributes().begin(); it != node->getAttributes().end(); ++it)
		{
			XMLAttribute* attr = xml_node->first_attribute(it->first.c_str());

			if (attr == NULL && it->second)
			{
				std::cout << "Error: Attribute `" << it->first << "` in node `" << node->getName() << "` is required." << std::endl;
				return false;
			}
		}

		// Check unsupported attributes
		for (XMLAttribute* attr = xml_node->first_attribute(); attr; attr = attr->next_attribute())
		{
			if (!node->hasAttribute(attr->name()))
				std::cout << "Warning: Attribute `" << attr->name() << "` in node `" << node->getName() << "` not supported." << std::endl;
		}

		// Node callback
		if (node->getName().compare(xml_node->name()) == 0)
			(*node)(xml_node);

		// Proceed sibling nodes
		XMLNode* sibling = xml_node->next_sibling();
		if (sibling && sibling->name())
		{
			if (node->hasSibling(sibling->name()))
			{
				if (!this->proceedNode(node->getSibling(sibling->name()), sibling))
					return false;
			}
			else
				std::cout << "Warning: Sibling `" << sibling->name() << "` of `" << node->getName() << "` not supported." << std::endl;
		}

		// Proceed child nodes
		XMLNode* child = xml_node->first_node();
		if (child && child->name())
		{
			if (node->hasChild(child->name()))
			{
				if (!this->proceedNode(node->getChild(child->name()), child))
					return false;
			}
			else
				std::cout << "Warning: Child `" << child->name() << "` of `" << node->getName() << "` not supported." << std::endl;
		}
	}
	return true;
}
开发者ID:Inozuma,项目名称:SkinEngine,代码行数:55,代码来源:Parser.cpp

示例12: FindAttribute

	const XMLAttribute* XMLElement::FindAttribute(const char* name) const
	{
		for (XMLAttribute* a = _rootAttribute; a; a = a->_next)
		{
			if (XMLUtil::StringEqual(a->Name(), name))
			{
				return a;
			}
		}
		return 0;
	}
开发者ID:CooperCoders,项目名称:GraphicsProject,代码行数:11,代码来源:tinyxml2.cpp

示例13: getXMLTypeAttribute

std::string getXMLTypeAttribute(const XMLNode& node)
{
	if (rapidxml::count_attributes(const_cast<XMLNode*>(&node)) != 1)
		raiseXMLException(node, "Expected 1 attribute");

	XMLAttribute* attr = node.first_attribute();
	if (strcmp(attr->name(), "type"))
		raiseXMLException(node, "Missing \"type\" attribute");

	return std::string(attr->value());
}
开发者ID:dsmo7206,项目名称:genesis,代码行数:11,代码来源:xml.cpp

示例14: fprintf

//来自:TinyXML
void XMLElement::ToFile(FILE *file,int blankdepth)
{
	int i;
	for ( i = 0; i < blankdepth; i++ )
	{
		fprintf( file, "    " );
	}

	fprintf_s( file, "<%s", value.c_str() );

	XMLAttribute* attri = NULL;
	for ( attri = attributes.First(); attri; attri = attri->Next() )
	{
		fprintf_s( file, " " );
		attri->ToFile( file, blankdepth );
	}

	// There are 3 different formatting approaches:
	// 1) An element without children is printed as a <foo /> node
	// 2) An element with only a text child is printed as <foo> text </foo>
	// 3) An element with children is printed on multiple lines.
	
	if ( !firstChild )
	{
		fprintf_s( file, " />" );
	}
	else if ( firstChild == lastChild && firstChild->ToText() )
	{
		fprintf_s( file, ">" );
		firstChild->ToFile( file, blankdepth + 1 );
		fprintf_s( file, "</%s>", value.c_str() );
	}
	else
	{
		XMLNode* node = NULL;
		fprintf_s( file, ">" );
		for ( node = firstChild; node; node=node->NextSibling() )
		{
			if ( !node->ToText() )
			{
				fprintf_s( file, "\n" );
			}
			node->ToFile( file, blankdepth + 1 );
		}
		fprintf_s( file, "\n" );
		for( i=0; i < blankdepth; ++i )
			fprintf_s( file, "    " );
		fprintf_s( file, "</%s>", value.c_str() );
	}
}
开发者ID:zipxin,项目名称:OnlyXML,代码行数:51,代码来源:OnlyXMLToFile.cpp

示例15: AttributeWidget

AttrWidgetVectorFloat::AttrWidgetVectorFloat(const XMLAttribute &xmlAttribute,
                                             InspectorWidget *inspectorWidget) :
    AttributeWidget(xmlAttribute, inspectorWidget, false, true, true)
{
    QHBoxLayout *hLayout = new QHBoxLayout();
    m_layout->addLayout(hLayout, 1);
    m_layout->setSpacing(0);
    m_layout->setMargin(0);

    String labels[] = {"X", "Y", "Z", "W"};
    int numberOfFields = xmlAttribute.GetNumberOfFieldsOfType();
    for (unsigned int i = 0; i < numberOfFields; ++i)
    {
        AttrWidgetFloat *s = new AttrWidgetFloat(xmlAttribute, inspectorWidget, true);
        m_floatSlots.PushBack(s);

        QLabel *label = new QLabel(QString::fromStdString(labels[i]));
        if (i != 0)
        {
            hLayout->setSpacing(3);
        }
        hLayout->addWidget(label, 0, Qt::AlignRight | Qt::AlignVCenter);
        hLayout->addWidget(s,     0, Qt::AlignLeft | Qt::AlignVCenter);
    }

    setMinimumWidth(40);
    setFixedHeight(20);
    AfterConstructor();
}
开发者ID:sephirot47,项目名称:Bang,代码行数:29,代码来源:AttrWidgetVectorFloat.cpp


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