本文整理汇总了C++中XMLElement::FirstAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLElement::FirstAttribute方法的具体用法?C++ XMLElement::FirstAttribute怎么用?C++ XMLElement::FirstAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::FirstAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paeseXml
void LoadScene::paeseXml()
{
ValueVector xmlVector;
// //xml解析
//string fileName="loadXml";
//std::string filePath = FileUtils::getInstance()->getWritablePath() + fileName;
//std::string filePath=cocos2d::FileUtils::getInstance()->getStringFromFile("loadPicture.xml");
//获取文件在系统的绝对路径
//std::string filePath1=FileUtils::getInstance()->fullPathForFilename("loadPicture.xml");
//log("%s",filePath1.c_str());
XMLDocument *pDoc = new XMLDocument();
Data fileData=FileUtils::getInstance()->getDataFromFile("loadPicture.xml");
pDoc->Parse((const char*)fileData.getBytes());//开始解析
// XMLError errorId = pDoc->LoadFile(filePath1.c_str());
// if (errorId != 0) {
// //xml格式错误
// log("cuowu");
// }
//获取第一个节点属性
XMLElement *rootEle = pDoc->RootElement();
const XMLAttribute *attribute = rootEle->FirstAttribute();
//打印节点属性名和值
log("attribute<em>name = %s,attribute</em>value = %s", attribute->Name(), attribute->Value());
loadXmlElement(rootEle);
delete pDoc;
}
示例2: configure
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());
}
}
示例3:
// Restores the cached entries to the database. It's spawned off as a seperate
int
CXMLDb::Restore(DataContainerList &DataList, unsigned int maxRows)
{
pthread_mutex_lock(&FileMutex);
if(!LoadBackupFile())
{
syslog(LOG_ERR, "Error opening Backup file\n");
pthread_mutex_unlock(&FileMutex);
return false;
}
XMLElement *CurrentElement = m_BackupFile->FirstChildElement()->FirstChildElement("pd");
// file is empty. Return true
if(!CurrentElement)
{
pthread_mutex_unlock(&FileMutex);
return true;
}
std::list<struct XMLElement*> XmlList;
while(CurrentElement && DataList.size() < maxRows)
{
DataContainer CurrentData;
const XMLAttribute *CurrentAtt = CurrentElement->FirstAttribute();
while(CurrentAtt)
{
string Name = CurrentAtt->Name();
string Value = CurrentAtt->Value();
CurrentData[Name] = Value;
CurrentAtt = CurrentAtt->Next();
}
DataList.push_back(CurrentData);
XmlList.push_back(CurrentElement);
CurrentElement = CurrentElement->NextSiblingElement();
}
while(!XmlList.empty())
{
XMLElement *Element2Delete = XmlList.front();
m_BackupFile->FirstChildElement()->DeleteChild(Element2Delete);
XmlList.pop_front();
}
SaveBackupFile();
pthread_mutex_unlock(&FileMutex);
return true;
}
示例4: load
bool GraphDataStorageXML::load(const char* fullpath, GraphData& data, StageBaseData* baseData) {
try {
XMLDocument doc;
XMLDocument *myDocument = &doc;
if (! FileUtils::getInstance()->isFileExist(fullpath)) return false;
auto Data = FileUtils::getInstance()->getDataFromFile(fullpath);
if (myDocument->Parse((const char*)Data.getBytes(), Data.getSize())) return false;
//if (myDocument->LoadFile(fullpath)) return false;
static GraphData s_defGraphData = {
10/*row*/,
10/*column*/,
5/*vertex_num*/,
64/*box_heights*/,
64/*box_widths*/,
0/*diff_row_off_x*/,
32/*offsert_x*/,
32/*offsert_y*/
};
data = s_defGraphData;
for (XMLElement* property = myDocument->FirstChildElement("property"); property; property = property->NextSiblingElement("property")) {
data.cols = property->IntAttribute("cols");
data.rows = property->IntAttribute("rows");
if (baseData) {
baseData->m_bonusNeedStar = 12;
baseData->m_lbNeedScore = property->IntAttribute("score") * 5;
}
}
for (XMLElement* property = myDocument->FirstChildElement("map"); property; property = property->NextSiblingElement()) {
for (auto attribute = property->FirstAttribute(); attribute; attribute = attribute->Next()) {
const char* name = attribute->Name();
int row = 0, col = 0;
sscanf(name, "a%d_%d", &row, &col);
data.map[row][col] = GraphAttrib::make(NodeCategory::make(static_cast<enNodeColor>(attribute->IntValue()), CHESS_CATEGORY_NORM, 0));
}
}
} catch (std::string& e) {
cocos2d::log("%s\n", e.c_str());
return false;
}
return true;
}
示例5: CalculateElements
REUInt32 REXMLSerializableReader::CalculateElements(void * objectElement)
{
REUInt32 count = 0;
#ifndef __RE_NO_XML_PARSER_PRIVATE__
XMLElement * element = (XMLElement *)objectElement;
for (XMLElement * childElem = element->FirstChildElement(); childElem != NULL; childElem = childElem->NextSiblingElement())
{
const char * nodeValue = childElem->Value();
if (nodeValue)
{
for (const XMLAttribute * attrib = childElem->FirstAttribute(); attrib != NULL; attrib = attrib->Next())
{
count++;
}
if (strcmp(nodeValue, "object") == 0)
{
count += this->CalculateElements(childElem);
}
count++;
}
}
#endif
return count;
}
示例6: doc
bool cSDL2DSceneManager::loadFromXMLFile(std::string Filename)
{
XMLDocument doc(Filename.c_str());
std::list<c2DLayer*> List;
if(doc.LoadFile(Filename.c_str()) == XML_NO_ERROR)
{
//Find resources node
XMLNode* ResourceTree = doc.RootElement();
if(ResourceTree)
{
//Enumerate resource objects
for(XMLNode* child = ResourceTree->FirstChild(); child; child = child->NextSibling())
{
XMLElement *Element = child->ToElement();
if(Element)
{
c2DLayer *Layer = new c2DLayer();
Layer->m_ZOrder = m_Layers.size();
for(XMLAttribute* ElementAttrib = const_cast<XMLAttribute*>(Element->FirstAttribute()); ElementAttrib; ElementAttrib = const_cast<XMLAttribute*>(ElementAttrib->Next()))
{
//Examine layers
std::string AttribName = ElementAttrib->Name();
std::string AttribValue = ElementAttrib->Value();
//Detect resource type. Graphic? Audio? Text?
if(AttribName=="name")
{
Layer->m_Name=AttribValue;
continue;
}
if(AttribName=="posx")
{
Layer->m_PosX = atof(AttribValue.c_str());
}
if(AttribName=="posy")
{
Layer->m_PosY = atof(AttribValue.c_str());
}
if(AttribName=="visible")
{
if(AttribValue=="true")
Layer->m_bVisible=true;
else
Layer->m_bVisible=false;
}
}
m_Layers.push_back(Layer);
//Cycle through layer objects
for(XMLNode* objs = child->FirstChild(); objs; objs = objs->NextSibling())
{
if(std::string(objs->Value())=="objects")
{
for(XMLNode* obj = objs->FirstChild(); obj; obj = obj->NextSibling())
{
XMLElement *ObjElement = obj->ToElement();
addLayerObjects(Layer, ObjElement);
}
}
}
}
}
sortLayers();
return true;
}
}
return false;
}
示例7: main
//.........这里部分代码省略.........
XMLNode* copy = node->ShallowClone( &clone );
clone.InsertEndChild( copy );
}
clone.Print();
int count=0;
const XMLNode* a=clone.FirstChild();
const XMLNode* b=doc.FirstChild();
for( ; a && b; a=a->NextSibling(), b=b->NextSibling() ) {
++count;
XMLTest( "Clone and Equal", true, a->ShallowEqual( b ));
}
XMLTest( "Clone and Equal", 4, count );
}
{
// This shouldn't crash.
XMLDocument doc;
if(XML_NO_ERROR != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
{
doc.PrintError();
}
XMLTest( "Error in snprinf handling.", true, doc.Error() );
}
{
// Attribute ordering.
static const char* xml = "<element attrib1=\"1\" attrib2=\"2\" attrib3=\"3\" />";
XMLDocument doc;
doc.Parse( xml );
XMLElement* ele = doc.FirstChildElement();
const XMLAttribute* a = ele->FirstAttribute();
XMLTest( "Attribute order", "1", a->Value() );
a = a->Next();
XMLTest( "Attribute order", "2", a->Value() );
a = a->Next();
XMLTest( "Attribute order", "3", a->Value() );
XMLTest( "Attribute order", "attrib3", a->Name() );
ele->DeleteAttribute( "attrib2" );
a = ele->FirstAttribute();
XMLTest( "Attribute order", "1", a->Value() );
a = a->Next();
XMLTest( "Attribute order", "3", a->Value() );
ele->DeleteAttribute( "attrib1" );
ele->DeleteAttribute( "attrib3" );
XMLTest( "Attribute order (empty)", false, ele->FirstAttribute() ? true : false );
}
{
// Make sure an attribute with a space in it succeeds.
static const char* xml0 = "<element attribute1= \"Test Attribute\"/>";
static const char* xml1 = "<element attribute1 =\"Test Attribute\"/>";
static const char* xml2 = "<element attribute1 = \"Test Attribute\"/>";
XMLDocument doc0;
doc0.Parse( xml0 );
XMLDocument doc1;
doc1.Parse( xml1 );
XMLDocument doc2;
doc2.Parse( xml2 );
XMLElement* ele = 0;
ele = doc0.FirstChildElement();
示例8: main
//.........这里部分代码省略.........
XMLNode* copy = node->ShallowClone( &clone );
clone.InsertEndChild( copy );
}
clone.Print();
int count=0;
const XMLNode* a=clone.FirstChild();
const XMLNode* b=doc.FirstChild();
for( ; a && b; a=a->NextSibling(), b=b->NextSibling() ) {
++count;
XMLTest( "Clone and Equal", true, a->ShallowEqual( b ));
}
XMLTest( "Clone and Equal", 4, count );
}
{
// This shouldn't crash.
XMLDocument doc;
if(XML_NO_ERROR != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
{
doc.PrintError();
}
XMLTest( "Error in snprinf handling.", true, doc.Error() );
}
{
// Attribute ordering.
static const char* xml = "<element attrib1=\"1\" attrib2=\"2\" attrib3=\"3\" />";
XMLDocument doc;
doc.Parse( xml );
XMLElement* ele = doc.FirstChildElement();
const XMLAttribute* a = ele->FirstAttribute();
XMLTest( "Attribute order", "1", a->Value() );
a = a->Next();
XMLTest( "Attribute order", "2", a->Value() );
a = a->Next();
XMLTest( "Attribute order", "3", a->Value() );
XMLTest( "Attribute order", "attrib3", a->Name() );
ele->DeleteAttribute( "attrib2" );
a = ele->FirstAttribute();
XMLTest( "Attribute order", "1", a->Value() );
a = a->Next();
XMLTest( "Attribute order", "3", a->Value() );
ele->DeleteAttribute( "attrib1" );
ele->DeleteAttribute( "attrib3" );
XMLTest( "Attribute order (empty)", false, ele->FirstAttribute() ? true : false );
}
// -------- Handles ------------
{
static const char* xml = "<element attrib='bar'><sub>Text</sub></element>";
XMLDocument doc;
doc.Parse( xml );
XMLElement* ele = XMLHandle( doc ).FirstChildElement( "element" ).FirstChild().ToElement();
XMLTest( "Handle, success, mutable", ele->Value(), "sub" );
XMLHandle docH( doc );
ele = docH.FirstChildElement( "none" ).FirstChildElement( "element" ).ToElement();
XMLTest( "Handle, dne, mutable", false, ele != 0 );
}
示例9: ParseObject
REBOOL REXMLSerializableReader::ParseObject(void * objectElement, REGUIObject * obj, REGUIObject * fromCallBack)
{
#ifndef __RE_NO_XML_PARSER_PRIVATE__
XMLElement * element = (XMLElement *)objectElement;
for (XMLElement * childElem = element->FirstChildElement(); childElem != NULL; childElem = childElem->NextSiblingElement())
{
const char * nodeValue = childElem->Value();
if (nodeValue)
{
if (strcmp(nodeValue, "object") == 0)
{
const char * className = NULL;
const char * key = NULL;
for (const XMLAttribute * attrib = childElem->FirstAttribute(); attrib != NULL; attrib = attrib->Next())
{
const char * name = attrib->Name();
if (name)
{
if (strcmp(name, "class") == 0)
{
className = attrib->Value();
}
else if (strcmp(name, "key") == 0)
{
key = attrib->Value();
}
}
_processedElementsCount++;
}
REGUIObject * newObject = _callBack.CreateNewObject(_controller, className, key);
if (newObject)
{
REBOOL isAccepted = false;
//REGUIObject * xmlSerializable = newObject->GetCasted<IREXMLSerializable>();
//if (xmlSerializable)
//{
newObject->onPrepareGUIObjectForSetuping();
this->ParseObject(childElem, newObject, newObject);
isAccepted = obj->acceptObjectParameter(className, key, newObject);
newObject->onSetupingGUIObjectFinished(isAccepted);
//}
if (!isAccepted)
{
newObject->release();
}
}
else
{
return false;
}
}
else
{
const char * key = NULL;
for (const XMLAttribute * attrib = childElem->FirstAttribute(); attrib != NULL; attrib = attrib->Next())
{
const char * name = attrib->Name();
if (name)
{
if (strcmp(name, "key") == 0)
{
key = attrib->Value();
}
}
_processedElementsCount++;
}
if (key)
{
const char * value = childElem->GetText();
if (value)
{
if (strcmp(nodeValue, "property") == 0)
{
IREObjectProperty * prop = obj->getPropertyForKey(key);
if (prop)
{
int propIdentif = 0;
if (sscanf(value, "%i", &propIdentif) == 1)
{
REXMLSerializableReader::PropertyStruct newStruct;
newStruct.property = prop;
newStruct.editorid = (REInt32)propIdentif;
_properties.add(newStruct);
}
}
}
else if (strcmp(key, "editorid") == 0)
{
int propIdentif = 0;
if (sscanf(value, "%i", &propIdentif) == 1)
{
for (REUInt32 i = 0; i < _properties.count(); i++)
{
if (_properties[i].editorid == (REInt32)propIdentif)
{
IREObjectProperty * prop = _properties[i].property;
prop->setObject(fromCallBack);
_properties.removeAt(i);
//.........这里部分代码省略.........