本文整理汇总了C++中tinyxml2::XMLElement类的典型用法代码示例。如果您正苦于以下问题:C++ XMLElement类的具体用法?C++ XMLElement怎么用?C++ XMLElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getVector
EReturn getVector(const tinyxml2::XMLElement & xml_vector,
Eigen::VectorXd & eigen_vector)
{
//!< Temporaries
double temp_entry;
int i = 0;
if (!xml_vector.GetText())
{
INDICATE_FAILURE
;
eigen_vector = Eigen::VectorXd(); //!< Null matrix again
return PAR_ERR;
}
std::istringstream text_parser(xml_vector.GetText());
//!< Initialise looping
text_parser >> temp_entry;
while (!(text_parser.fail() || text_parser.bad())) //!< No commenting!
{
eigen_vector.conservativeResize(++i); //!< Allocate storage for this entry (by increasing i)
eigen_vector(i - 1) = temp_entry;
text_parser >> temp_entry;
}
return (i > 0) ? SUCCESS : PAR_ERR;
}
示例2: cf
bool ChannelFavoritesSerializer::GetFavoritesResponseXmlDataDeserializer::VisitEnter(const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* attribute)
{
if (strcmp(element.Name(), "favorite") == 0)
{
std::string id = Util::GetXmlFirstChildElementText(&element, "id");
std::string name = Util::GetXmlFirstChildElementText(&element, "name");
//channels
ChannelFavorite::favorite_channel_list_t channels;
const tinyxml2::XMLElement* channels_element = element.FirstChildElement("channels");
if (channels_element != NULL)
{
const tinyxml2::XMLElement* channel_element = channels_element->FirstChildElement();
while (channel_element != NULL)
{
if (strcmp(channel_element->Name(), "channel") == 0)
{
if (channel_element->GetText() != NULL)
channels.push_back(channel_element->GetText());
}
channel_element = channel_element->NextSiblingElement();
}
}
ChannelFavorite cf(id, name, channels);
m_favoritesList.favorites_.push_back(cf);
return false;
}
return true;
}
示例3:
Vector3d<float> XMLHelper::parse(tinyxml2::XMLElement& elem)
{
const auto x = elem.FloatAttribute("x");
const auto y = elem.FloatAttribute("y");
const auto z = elem.FloatAttribute("z");
return Vector3d<float>(x, y, z);
}
示例4: 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;
}
示例5: decodeXML
void Restaurant::decodeXML(tinyxml2::XMLElement & xml)
{
Item::decodeXML(xml);
variant = xml.IntAttribute("variant");
open = xml.BoolAttribute("open");
updateSprite();
}
示例6: WriteAttributedObject
/**
* Writes the attributed object id, comments, and artifacts.
*/
void Translator::WriteAttributedObject(const AttributedObject& aobj, Context& ctxt, tinyxml2::XMLElement & elem, bool bIdAttributeRequired)
{
//Write the ID.
if( aobj.Id().length() > 0 )
elem.SetAttribute( "id", aobj.Id().c_str());
else if( bIdAttributeRequired )
throw GnssMetadata::TranslationException( "Required id attribute not defined.");
//Write the comments.
CommentList::const_iterator citer = aobj.Comments().begin();
for(; citer != aobj.Comments().end(); citer++)
{
XMLElement* pec = elem.GetDocument()->NewElement( "comment");
const Comment& cmt = *citer;
const char* szFormat = (cmt.Format() == Comment::text) ? "text":"html";
pec->SetAttribute("format",szFormat);
pec->SetText( cmt.Value().c_str());
elem.InsertEndChild(pec);
}
//Write the Artifacts.
AnyUriList::const_iterator aiter = aobj.Artifacts().begin();
for(; aiter != aobj.Artifacts().end(); aiter++)
{
XMLElement* pec = elem.GetDocument()->NewElement( "artifact");
pec->SetText( aiter->Value().c_str());
elem.InsertEndChild(pec);
}
}
示例7: RecordedTV
bool GetObjectResponseSerializer::ItemXmlDataDeserializer::VisitEnter(const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* attribute)
{
Item * item;
if (strcmp(element.Name(), "recorded_tv") == 0)
{
std::string objectId = Util::GetXmlFirstChildElementText(&element, "object_id");
std::string parentId = Util::GetXmlFirstChildElementText(&element, "parent_id");
std::string url = Util::GetXmlFirstChildElementText(&element, "url");
std::string thumbnail = Util::GetXmlFirstChildElementText(&element, "thumbnail");
std::string channelName = Util::GetXmlFirstChildElementText(&element, "channel_name");
bool canBeDeleted = Util::GetXmlFirstChildElementTextAsBoolean(&element, "can_be_deleted");
long size = Util::GetXmlFirstChildElementTextAsLong(&element, "size");
long creationTime = Util::GetXmlFirstChildElementTextAsLong(&element, "creation_time");
int channelNumber = Util::GetXmlFirstChildElementTextAsInt(&element, "channel_number");
int channelSubnumber = Util::GetXmlFirstChildElementTextAsInt(&element, "channel_subnumber");
RECORDEDTV_STATE state = (RECORDEDTV_STATE) Util::GetXmlFirstChildElementTextAsInt(&element, "state");
item = new RecordedTV(objectId, parentId, url,thumbnail,channelName,canBeDeleted,size,creationTime,channelNumber,channelSubnumber, state);
tinyxml2::XMLElement * vElement = (tinyxml2::XMLElement*)(&element)->FirstChildElement("video_info");
VideoInfoSerializer::Deserialize((XmlObjectSerializer<Response>&)m_parent, *vElement, ((RecordedTV*) item)->VInfo);
m_items.push_back(item);
return false;
}
if (strcmp(element.Name(), "video") == 0)
{
std::string objectId = Util::GetXmlFirstChildElementText(&element, "object_id");
std::string parentId = Util::GetXmlFirstChildElementText(&element, "parent_id");
std::string url = Util::GetXmlFirstChildElementText(&element, "url");
std::string thumbnail = Util::GetXmlFirstChildElementText(&element, "thumbnail");
std::string channelName = Util::GetXmlFirstChildElementText(&element, "channel_name");
bool canBeDeleted = Util::GetXmlFirstChildElementTextAsBoolean(&element, "can_be_deleted");
long size = Util::GetXmlFirstChildElementTextAsLong(&element, "size");
long creationTime = Util::GetXmlFirstChildElementTextAsLong(&element, "creation_time");
item = new Video(objectId, parentId, url,thumbnail,canBeDeleted,size,creationTime);
m_items.push_back(item);
return false;
}
if (strcmp(element.Name(), "audio") == 0)
{
item = new Audio();
m_items.push_back(item);
return false;
}
if (strcmp(element.Name(), "image") == 0)
{
item = new Image();
m_items.push_back(item);
return false;
}
return true;
}
示例8: WriteSaveSlot
/**
* @brief This function takes the passed in SaveSlot, and writes it to the .xml file.
* @param This is the SaveSlot to be written.
*/
void WriteSaveSlot(SaveSlot s){
string d = "SaveSlot" + std::to_string(s.m_id);
const char * c = d.c_str();
tinyxml2::XMLElement * saveSlot = xmlDoc.NewElement(c);
//Inserts Values to the .xml file
tinyxml2::XMLElement * pElement = xmlDoc.NewElement("TimePlayed");
pElement->SetText(s.m_timePlayed);
saveSlot->InsertEndChild(pElement);
pElement = xmlDoc.NewElement("CurrentGold");
pElement->SetText(s.m_currentGold);
saveSlot->InsertEndChild(pElement);
pElement = xmlDoc.NewElement("Levels");
for (int i = 0; i < 7; i++){
string level = "LVL" + std::to_string(i + 1);
const char * c = level.c_str();
tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
pListElement->SetText(s.m_LVL_DATA[level]);
pElement->InsertEndChild(pListElement);
saveGame->InsertEndChild(saveSlot);
saveSlot->InsertEndChild(pElement);
}
pElement = xmlDoc.NewElement("Achievements");
for (int i = 0; i < 21; i++) {
string ach = "ACH" + std::to_string(i + 1);
const char * c = ach.c_str();
tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
pListElement->SetText(s.m_ACH_DATA[ach]);
pElement->InsertEndChild(pListElement);
saveSlot->InsertEndChild(pElement);
saveGame->InsertEndChild(saveSlot);
}
pElement = xmlDoc.NewElement("Statistics");
for (int i = 0; i < 10; i++) {
string stat = "STAT" + std::to_string(i + 1);
const char * c = stat.c_str();
tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
pListElement->SetText(s.m_ACH_DATA[stat]);
pElement->InsertEndChild(pListElement);
saveSlot->InsertEndChild(pElement);
saveGame->InsertEndChild(saveSlot);
}
}
示例9: getMatrix
EReturn getMatrix(const tinyxml2::XMLElement & xml_matrix,
Eigen::MatrixXd & eigen_matrix)
{
int dimension = 0;
if (xml_matrix.QueryIntAttribute("dim", &dimension)
!= tinyxml2::XML_NO_ERROR)
{
INDICATE_FAILURE
;
eigen_matrix = Eigen::MatrixXd(); //!< Null matrix again
return PAR_ERR;
}
if (dimension < 1)
{
INDICATE_FAILURE
;
eigen_matrix = Eigen::MatrixXd(); //!< Null matrix again
return PAR_ERR;
}
eigen_matrix.resize(dimension, dimension);
if (!xml_matrix.GetText())
{
INDICATE_FAILURE
;
eigen_matrix = Eigen::MatrixXd(); //!< Null matrix again
return PAR_ERR;
}
std::istringstream text_parser(xml_matrix.GetText());
double temp_entry;
for (int i = 0; i < dimension; i++) //!< Note that this does not handle comments!
{
for (int j = 0; j < dimension; j++)
{
text_parser >> temp_entry;
if (text_parser.fail() || text_parser.bad()) //!< If a failure other than end of file
{
INDICATE_FAILURE
;
eigen_matrix.resize(0, 0);
return PAR_ERR;
}
else
{
eigen_matrix(i, j) = temp_entry;
}
}
}
return SUCCESS;
}
示例10: 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");
}
示例11: clearCars
void Elevator::decodeXML(tinyxml2::XMLElement & xml)
{
clearCars();
Item::decodeXML(xml);
size.y = xml.IntAttribute("height");
for (tinyxml2::XMLElement * e = xml.FirstChildElement("unserviced"); e; e = e->NextSiblingElement("unserviced")) {
unservicedFloors.insert(e->IntAttribute("floor"));
}
for (tinyxml2::XMLElement * e = xml.FirstChildElement("car"); e; e = e->NextSiblingElement("car")) {
Car * car = new Car(this);
car->decodeXML(*e);
cars.insert(car);
}
updateSprite();
}
示例12: Channel
bool GetChannelsResponseSerializer::GetChannelsResponseXmlDataDeserializer::VisitEnter(const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* attribute)
{
if (strcmp(element.Name(), "channel") == 0)
{
long channelDvbLinkId = Util::GetXmlFirstChildElementTextAsLong(&element, "channel_dvblink_id");
std::string channelId = Util::GetXmlFirstChildElementText(&element, "channel_id");
std::string channelName = Util::GetXmlFirstChildElementText(&element, "channel_name");
int channelNumber = Util::GetXmlFirstChildElementTextAsInt(&element, "channel_number");
int channelSubNumber = Util::GetXmlFirstChildElementTextAsInt(&element, "channel_subnumber");
Channel::DVBLinkChannelType channelType = (Channel::DVBLinkChannelType)Util::GetXmlFirstChildElementTextAsInt(&element, "channel_type");
std::string channelLogoUrl = Util::GetXmlFirstChildElementText(&element, "channel_logo");
Channel* channel = new Channel(channelId, channelDvbLinkId, channelName, channelType, channelLogoUrl, channelNumber, channelSubNumber);
if (m_parent.HasChildElement(*&element, "channel_child_lock"))
{
channel->ChildLock = Util::GetXmlFirstChildElementTextAsBoolean(&element, "channel_child_lock");
}
m_channelList.push_back(channel);
return false;
}
return true;
}
示例13: VisitExit
bool XmlSaxHander::VisitExit( const tinyxml2::XMLElement& element )
{
//log("VisitExit %s",element.Value());
SAXParser::endElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value());
return true;
}
示例14: ReadElement
/**
* Processes the current element within the context of the attributed object.
*/
bool XmlProcessor::ReadElement( Context & ctxt, const tinyxml2::XMLElement & elem, AccessorAdaptorBase* pAdaptor)
{
TranslatorId id = TE_END;
const char* szNodeName = elem.Name();
//Use the current translator if available to lookup appropriate
//translator for the current element. If not available,
//do a global search.
if( ctxt.pParent != NULL)
{
id = TranslatorIdFromElemName( szNodeName, ctxt.pParent->GetAllowedNodes() );
}
else //Do a global lookup.
{
for( int i = 0; i < COUNT_TRANSLATORS && id == TE_END; i++)
{
NodeEntry* pNodes = _Translators[i].translator.GetAllowedNodes();
if(pNodes == NULL) continue;
id = TranslatorIdFromElemName( szNodeName, pNodes);
}
}
//Get the translator and attempt to process the current
//element.
Translator& trans = TranslatorFromId( id);
return trans.OnRead( ctxt, elem, pAdaptor);
}
示例15: while
void Animation2D::Read(const tinyxml2::XMLElement& el_ )
{
Animation::Read(el_);
const tinyxml2::XMLElement *pElemFrame = el_.FirstChildElement("EventList")->FirstChildElement("Event");
//float totalTime = 0.0f;
while (pElemFrame != nullptr)
{
SetFrameEvent *pFrameEvent = NEW_AO SetFrameEvent();
pFrameEvent->Read(const_cast<tinyxml2::XMLElement *>(pElemFrame));
AddEvent(pFrameEvent);
pElemFrame = pElemFrame->NextSiblingElement();
/*unsigned int spriteID;
pElemFrame->QueryUnsignedAttribute("spriteID", &spriteID);
float time;
pElemFrame->QueryFloatAttribute("time", &time);
std::ostringstream str;
str << spriteID;
SetFrameEvent *pFrameEvent = NEW_AO SetFrameEvent();
pFrameEvent->FrameID(str.str().c_str());
pFrameEvent->Time(time + totalTime);
AddEvent(pFrameEvent);
pElemFrame = pElemFrame->NextSiblingElement();
totalTime += time;*/
}
}