本文整理汇总了C++中tinyxml2::XMLElement::Attribute方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLElement::Attribute方法的具体用法?C++ XMLElement::Attribute怎么用?C++ XMLElement::Attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinyxml2::XMLElement
的用法示例。
在下文中一共展示了XMLElement::Attribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadAttributedObject
/**
* Reads the attributed object id, comments, and artifacts.
*/
bool Translator::ReadAttributedObject( AttributedObject& aobj,
Context& ctxt, const tinyxml2::XMLElement & elem, bool bIdAttributeRequired )
{
//Grab the ID.
pcstr szid = elem.Attribute("id");
if( szid == NULL)
{
if( bIdAttributeRequired )
throw GnssMetadata::TranslationException( "Required id attribute not defined.");
}
else
aobj.Id(szid);
//Parse the comments.
const XMLElement* pelem = elem.FirstChildElement("comment");
for( ;pelem != NULL; pelem = pelem->NextSiblingElement("comment"))
{
const char* szFmt = pelem->Attribute("format");
Comment::CommentFormat fmt = (strcmp(szFmt, "text") == 0)
? Comment::text : Comment::html;
Comment comment( pelem->GetText(), fmt);
aobj.Comments().push_back( comment);
}
//Parse the Artifacts.
pelem = elem.FirstChildElement("artifact");
for( ;pelem != NULL; pelem = pelem->NextSiblingElement("artifact"))
{
AnyUri auri( pelem->GetText());
aobj.Artifacts().push_back( auri);
}
return true;
}
示例2: getAttribute
inline bool getAttribute(const tinyxml2::XMLElement& elt, const char* name,
std::string& value) {
auto ptr = elt.Attribute(name);
if(ptr) {
value = ptr;
return true;
}
return false;
}
示例3: Load
void Fruit::Load(tinyxml2::XMLElement const& element)
{
char const* sprite = element.Attribute("Sprite");
assert(sprite);
m_Sprite.Load(sprite);
m_Sprite.SetOriginToCentre();
m_Score = element.IntAttribute("Score");
m_Appear1 = element.IntAttribute("Appear1");
m_Appear2 = element.IntAttribute("Appear2");
m_Time = element.FloatAttribute("Time");
}
示例4: Read
void Sprite::Read( const tinyxml2::XMLElement& el_ )
{
Clear();
IAssetable::Read(el_);
const tinyxml2::XMLElement *pElem, *pChild;
m_AssetFileName = el_.FirstChildElement("AssetFileName")->GetText();
//m_Name = el_->Attribute("name");
//m_Name = el_->Attribute("id");
SetName(el_.Attribute("id")); // TODO : ID is not the name
m_pTexture2D = Texture::loadTexture(m_AssetFileName.c_str());
pElem = el_.FirstChildElement("PositionInTexture");
int x, y, w, h;
pElem->QueryIntAttribute("x", &x);
pElem->QueryIntAttribute("y", &y);
pElem->QueryIntAttribute("width", &w);
pElem->QueryIntAttribute("height", &h);
m_PositionInTexture.Set(x, y, w, h);
pElem = el_.FirstChildElement("HotSpot");
pElem->QueryIntAttribute("x", &m_Origin.x);
pElem->QueryIntAttribute("y", &m_Origin.y);
pElem = el_.FirstChildElement("CollisionList");
pChild = pElem->FirstChildElement("Shape");
while (pChild != nullptr)
{
IShape *pShape = IShape::LoadShape(*pChild);
m_CollisionShapes.push_back(pShape);
pChild = pChild->NextSiblingElement();
}
}
示例5: doc
/** sample ParaEngine mesh xml file
<mesh version=1 type=0>
<boundingbox minx=0 miny=0 minz=0 maxx=1 maxy=1 maxz=1/>
<shader index=3/>
<submesh loddist=10 filename="LOD_10.x"/>
<submesh loddist=50 filename="LOD_50.x"/>
</mesh>
*/
bool ParaEngine::CParaMeshXMLFile::LoadFromBuffer(const char* pData, int nSize)
{
#ifdef PARAENGINE_MOBILE
namespace TXML = tinyxml2;
try
{
TXML::XMLDocument doc(true, TXML::COLLAPSE_WHITESPACE);
doc.Parse(pData, nSize);
TXML::XMLElement* pRoot = doc.RootElement();
if (pRoot)
{
pRoot->QueryIntAttribute("version", &m_nVersion);
if (m_nVersion < SUPPORTED_MESH_FILE_VERSION)
{
OUTPUT_LOG("can not load para mesh xml file. because of a lower file version.\n");
}
int nType = 0;
pRoot->QueryIntAttribute("type", &nType);
m_nType = (ParaMeshXMLType)nType;
for (TXML::XMLNode* pChild = pRoot->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
{
TXML::XMLElement* pElement = pChild->ToElement();
if (pElement)
{
std::string tagName = pElement->Name();
if (tagName == "boundingbox")
{
pElement->QueryFloatAttribute("minx", &m_vMinPos.x);
pElement->QueryFloatAttribute("miny", &m_vMinPos.y);
pElement->QueryFloatAttribute("minz", &m_vMinPos.z);
pElement->QueryFloatAttribute("maxx", &m_vMaxPos.x);
pElement->QueryFloatAttribute("maxy", &m_vMaxPos.y);
pElement->QueryFloatAttribute("maxz", &m_vMaxPos.z);
}
else if (tagName == "shader")
{
pElement->QueryIntAttribute("index", &m_nPrimaryShader);
// TODO: for shader parameters
for (TXML::XMLNode* pSubChild = pElement->FirstChild(); pSubChild != 0; pSubChild = pSubChild->NextSibling())
{
TXML::XMLElement* pParamElement = pSubChild->ToElement();
if (pParamElement)
{
std::string tagName = pParamElement->Name();
if (tagName == "params")
{
CParameter p;
// param name
p.SetName(pParamElement->Attribute("name", ""));
p.SetTypeByString(pParamElement->Attribute("type", ""));
p.SetValueByString(pParamElement->GetText());
m_paramBlock.AddParameter(p);
}
}
}
}
else if (tagName == "submesh")
{
CSubMesh meshInfo;
pElement->QueryFloatAttribute("loddist", &meshInfo.m_fToCameraDist);
std::string filepath = pElement->Attribute("filename");
// check if it is relative path or absolute path
if (filepath.find('/') != string::npos || filepath.find('\\') != string::npos)
meshInfo.m_sFileName = filepath;
else
meshInfo.m_sFileName = m_sParentDirectory + filepath;
m_SubMeshes.push_back(meshInfo);
}
}
}
}
}
catch (...)
{
OUTPUT_LOG("error parsing xml file %s**.xml \n", m_sParentDirectory.c_str());
return false;
}
return m_SubMeshes.size() > 0;
#else
TiXmlDocument doc;
try
{
doc.Parse(pData, 0, TIXML_DEFAULT_ENCODING);
TiXmlElement* pRoot = doc.RootElement();
{
// get mesh file version
TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/@version");
TinyXPath::expression_result res = xpathProc.er_compute_xpath();
TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
{
//.........这里部分代码省略.........