本文整理汇总了C++中xml::Document类的典型用法代码示例。如果您正苦于以下问题:C++ Document类的具体用法?C++ Document怎么用?C++ Document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Save
//--------------------------------------------------------------
//--------------------------------------------------------------
void AppDataStore::Save()
{
std::unique_lock<std::mutex> lock(m_mutex);
if(m_needsSynchonised == true)
{
// Convert to XML
XML::Document doc;
XML::Node* rootNode = doc.allocate_node(rapidxml::node_type::node_element);
doc.append_node(rootNode);
ParamDictionarySerialiser::ToXml(m_dictionary, rootNode);
// Encrypt
std::string strDocToBeEncrypted = XMLUtils::ToString(&doc);
AESEncrypt::Data encryptedData = AESEncrypt::EncryptString(strDocToBeEncrypted, k_privateKey);
// Write to disk
FileSystem* pFileSystem = Application::Get()->GetFileSystem();
FileStreamSPtr pFileStream = pFileSystem->CreateFileStream(StorageLocation::k_saveData, k_filename, FileMode::k_writeBinary);
if(pFileStream != nullptr)
{
pFileStream->Write(reinterpret_cast<const s8*>(encryptedData.m_data.get()), encryptedData.m_size);
pFileStream.reset();
}
m_needsSynchonised = false;
}
}
示例2: loadInfo
void MapDB::loadInfo(const std::string &fileName,
const SkipError skipError)
{
XML::Document *doc = new XML::Document(fileName,
UseResman_true,
skipError);
const XmlNodePtrConst root = doc->rootNode();
if (!root)
{
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "map"))
{
readMap(node);
}
else if (xmlNameEqual(node, "atlas"))
{
readAtlas(node);
}
else if (xmlNameEqual(node, "include"))
{
const std::string name = XML::getProperty(node, "name", "");
if (!name.empty())
loadInfo(name, skipError);
continue;
}
}
delete doc;
}
示例3: _analyzeXML
//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
void LNFXManager::_analyzeXML( const char* xml, size_t size )
{
XML::Document xmlDoc;
xmlDoc.Parse( xml, size );
// まずは Technique → Pass と作成して、コンパイルする。この中で Variable も作る
XML::Element* xmlElement = xmlDoc.FirstChildElement();
while ( xmlElement != NULL )
{
// <Technique>
if ( strcmp( xmlElement->Name(), TechniqueElementName ) == 0 ) {
_analyzeXMLTechniqueElement( xmlElement );
}
xmlElement = xmlElement->NextSiblingElement();
}
// 次に、作成済みの Variable にアノテーションを割り振る
xmlElement = xmlDoc.FirstChildElement();
while ( xmlElement != NULL )
{
// <Variable>
if ( strcmp( xmlElement->Name(), VariableElementName ) == 0 ) {
_analyzeXMLVariableElement( xmlElement );
}
xmlElement = xmlElement->NextSiblingElement();
}
}
示例4: LoadAtlasFromFile
void TextureAtlasHandler::LoadAtlasFromFile(const String& Name, const String& Group)
{
/// @todo Update after we have refactored the resource system if needed.
Resource::DataStreamPtr AtlasStream = Resource::ResourceManager::GetSingletonPtr()->OpenAssetStream(Name,Group);
AtlasStream->SetStreamPosition(0);
XML::Document AtlasDoc;
AtlasDoc.Load( *AtlasStream.Get() );
XML::Node RootNode = AtlasDoc.GetChild("Atlases");
if( !RootNode.Empty() )
{
for( XML::NodeIterator AtlasIt = RootNode.begin() ; AtlasIt != RootNode.end() ; ++AtlasIt )
{
// Parse the Atlas
TextureAtlas* NewAtlas = new TextureAtlas( (*AtlasIt) );
// Verify we don't already have one of the same name
AtlasIterator AtIt = this->Atlases.find( NewAtlas->GetName() );
if( AtIt != Atlases.end() )
{
MEZZ_EXCEPTION(ExceptionBase::II_DUPLICATE_IDENTITY_EXCEPTION,"Texture Atlas with the name \"" + NewAtlas->GetName() + "\" already exists.");
}
// Add the unique Atlas
this->Atlases[NewAtlas->GetName()] = NewAtlas;
}
}else{
MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"Mezzanine Texture Atlas file \"" + Name + "\"does not contain expected \"Atlases\" root node. File is not valid and cannot be parsed.");
}
}
示例5: Validate
void CardSet::Validate(XML::Document& D)
{
string name=(*D.Base())["name"];
string abbrev=(*D.Base())["abbrev"];
string dir=(*D.Base())["dir"];
age[abbrev]=sets.size();
if((*D.Base())["age"]!="")
{
age[abbrev]=atoi((*D.Base())["age"].c_str());
for(list<string>::iterator i=sets.begin(); i!=sets.end(); i++)
if(age[*i]>=age[abbrev])
age[*i]++;
}
sets.push_back(abbrev);
set_name[abbrev]=name;
directory[abbrev]=dir;
list<XML::Element*>::iterator i;
list<XML::Element*> cards=D("cards","card");
first_card[abbrev]=nextcard;
for(i=cards.begin(); i!=cards.end(); i++)
{
(**i).AddAttribute("set",abbrev);
numbers[(**i)["name"]].push_back(nextcard);
nextcard++;
}
last_card[abbrev]=nextcard-1;
}
示例6: loadXmlFile
void SoundDB::loadXmlFile(const std::string &fileName)
{
XML::Document *doc = new XML::Document(fileName);
const XmlNodePtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "sounds"))
{
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "include"))
{
const std::string name = XML::getProperty(node, "name", "");
if (!name.empty())
loadXmlFile(name);
continue;
}
else if (xmlNameEqual(node, "sound"))
{
const std::string name = XML::getProperty(node, "name", "");
const int id = NotifyManager::getIndexBySound(name);
if (id)
{
const std::string value = XML::getProperty(node, "value", "");
mSounds[id] = value;
}
}
}
delete doc;
}
示例7: save_xml
//
// XML 保存
//
void Linkfilter_Manager::save_xml()
{
XML::Document document;
XML::Dom* root = document.appendChild( XML::NODE_TYPE_ELEMENT, std::string( ROOT_NODE_NAME_LINKFILTER ) );
if( ! root ) return;
std::vector< LinkFilterItem >::iterator it = m_list_cmd.begin();
while( it != m_list_cmd.end() ){
const std::string url = ( *it ).url;
const std::string cmd = ( *it ).cmd;
if( ! url.empty() && ! cmd.empty() ){
XML::Dom* node = root->appendChild( XML::NODE_TYPE_ELEMENT, XML::get_name( TYPE_LINKFILTER ) );
node->setAttribute( "url", url );
node->setAttribute( "data", cmd );
}
++it;
}
#ifdef _DEBUG
std::cout << "Linkfilter_Manager::save_xml\n";
std::cout << document.get_xml() << std::endl;
#endif
CACHE::save_rawdata( CACHE::path_linkfilter(), document.get_xml() );
}
示例8: load
void EffectDB::load()
{
if (!mLoaded)
return;
const XML::Document doc("effects.xml");
const xmlNodePtr root = doc.rootNode();
if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
{
logger->log("Error loading being effects file: effects.xml");
return;
}
else
logger->log("Effects are now loading");
for_each_xml_child_node(node, root)
{
if (xmlStrEqual(node->name, BAD_CAST "effect"))
{
EffectDescription ed;
ed.id = XML::getProperty(node, "id", -1);
ed.GFX = XML::getProperty(node, "particle", "");
ed.SFX = XML::getProperty(node, "audio", "");
mEffects.push_back(ed);
}
}
mLoaded = true;
}
示例9: load
void EmoteDB::load()
{
if (mLoaded)
return;
mLastEmote = 0;
logger->log("Initializing emote database...");
const XML::Document doc("emotes.xml");
const xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes"))
{
logger->log("Emote Database: Error while loading emotes.xml!");
return;
}
//iterate <emote>s
for_each_xml_child_node(emoteNode, rootNode)
{
if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote"))
continue;
const int id = XML::getProperty(emoteNode, "id", -1);
if (id == -1)
{
logger->log("Emote Database: Emote with missing ID in emotes.xml!");
continue;
}
EmoteInfo *currentInfo = new EmoteInfo();
for_each_xml_child_node(spriteNode, emoteNode)
{
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
EmoteSprite *currentSprite = new EmoteSprite();
std::string file = "graphics/sprites/" + (std::string)
(const char*) spriteNode->xmlChildrenNode->content;
currentSprite->sprite = AnimatedSprite::load(file,
XML::getProperty(spriteNode, "variant", 0));
currentInfo->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
std::string particlefx = (const char*) spriteNode->xmlChildrenNode->content;
currentInfo->particles.push_back(particlefx);
}
}
mEmoteInfos[id] = currentInfo;
if (id > mLastEmote)
mLastEmote = id;
}
mLoaded = true;
}
示例10: load
void CharDB::load()
{
if (mLoaded)
unload();
XML::Document *doc = new XML::Document(
paths.getStringValue("charCreationFile"),
true,
false);
const XmlNodePtrConst root = doc->rootNode();
if (!root || !xmlNameEqual(root, "chars"))
{
logger->log("CharDB: Failed to parse %s.",
paths.getStringValue("charCreationFile").c_str());
delete doc;
return;
}
for_each_xml_child_node(node, root)
{
if (xmlNameEqual(node, "haircolor"))
{
loadMinMax(node, &mMinHairColor, &mMaxHairColor);
}
else if (xmlNameEqual(node, "hairstyle"))
{
loadMinMax(node, &mMinHairStyle, &mMaxHairStyle);
}
else if (xmlNameEqual(node, "look"))
{
loadMinMax(node, &mMinLook, &mMaxLook);
}
else if (xmlNameEqual(node, "stat"))
{
loadMinMax(node, &mMinStat, &mMaxStat);
mSumStat = XML::getProperty(node, "sum", 0);
}
else if (xmlNameEqual(node, "item"))
{
const int id = XML::getProperty(node, "id", 0);
if (id > 0)
mDefaultItems.push_back(id);
}
else if (xmlNameEqual(node, "race"))
{
loadMinMax(node, &mMinRace, &mMaxRace);
}
}
delete doc;
mLoaded = true;
}
示例11: AddCards
void CardSet::AddCards(const string& filename)
{
int old_nextcard=nextcard;
if(db.Base()==0)
{
db.ReadFile(Localization::File(filename));
Validate(db);
db.Base()->DelAttribute("name");
}
else
{
XML::Document add;
add.ReadFile(Localization::File(filename));
Validate(add);
db("cards").front()->AddSubelements(add("cards","card"));
}
list<XML::Element*>::const_iterator i;
card=vector<XML::Element*>(nextcard);
list<XML::Element*>& C=db("cards").front()->Subs();
i=C.begin();
for(int j=0; j<nextcard; j++)
card[j]=*i++;
for(int j=old_nextcard; j<nextcard; j++)
{
string rarity=AttrValue(j,"rarity");
while(rarity!="")
{
size_t k;
for(k=0; k<rarity.length(); k++)
if((rarity[k]>='0' && rarity[k]<='9') || (rarity[k]=='+' && (k+1<rarity.length())))
break;
rarities.insert(rarity.substr(0,k));
while(k<rarity.length() && rarity[k]!='+')
k++;
if(k+1<rarity.length())
rarity=rarity.substr(k+1,rarity.length());
else
rarity="";
}
list<string> att=Attributes(j);
for(list<string>::iterator n=att.begin(); n!=att.end(); n++)
attributes.insert(*n);
}
}
示例12: load
void ColorDB::load()
{
if (mLoaded)
return;
XML::Document *doc = new XML::Document(HAIR_COLOR_FILE);
xmlNodePtr root = doc->rootNode();
bool TMWHair = false;
if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
{
logger->log("Trying TMW's color file, %s.", TMW_COLOR_FILE);
TMWHair = true;
delete doc;
doc = new XML::Document(TMW_COLOR_FILE);
root = doc->rootNode();
if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
{
logger->log("ColorDB: Failed");
mColors[0] = mFail;
mLoaded = true;
delete doc;
return;
}
}
for_each_xml_child_node(node, root)
{
if (xmlStrEqual(node->name, BAD_CAST "color"))
{
int id = XML::getProperty(node, "id", 0);
if (mColors.find(id) != mColors.end())
logger->log("ColorDB: Redefinition of dye ID %d", id);
mColors[id] = TMWHair ? XML::getProperty(node, "value", mFail) :
XML::getProperty(node, "dye", mFail);
}
}
delete doc;
mLoaded = true;
}
示例13: onAction
ActionResponse Service::onAction(const std::string& action, const xml::Document& doc)
{
try
{
ActionResponse response(action, ServiceType::ConnectionManager);
auto request = doc.getFirstChild();
switch (actionFromString(action))
{
case Action::GetProtocolInfo:
response.addArgument("Source", getVariable(Variable::SourceProtocolInfo).getValue());
response.addArgument("Sink", getVariable(Variable::SinkProtocolInfo).getValue());
break;
case Action::PrepareForConnection:
{
ConnectionInfo connInfo;
connInfo.peerConnectionManager = request.getChildNodeValue("PeerConnectionManager");
connInfo.peerConnectionId = std::stoi(request.getChildNodeValue("PeerConnectionID"));
connInfo.direction = directionFromString(request.getChildNodeValue("Direction"));
ProtocolInfo protoInfo(request.getChildNodeValue("RemoteProtocolInfo"));;
m_connectionManager.prepareForConnection(protoInfo, connInfo);
response.addArgument("ConnectionID", std::to_string(connInfo.connectionId));
response.addArgument("AVTransportID", std::to_string(connInfo.avTransportId));
response.addArgument("RcsID", std::to_string(connInfo.renderingControlServiceId));
break;
}
case Action::ConnectionComplete:
m_connectionManager.connectionComplete(std::stoi(request.getChildNodeValue("ConnectionID")));
break;
case Action::GetCurrentConnectionIDs:
response.addArgument("ConnectionIDs", getVariable(Variable::CurrentConnectionIds).getValue());
break;
case Action::GetCurrentConnectionInfo:
{
auto connInfo = m_connectionManager.getCurrentConnectionInfo(std::stoi(request.getChildNodeValue("ConnectionID")));
response.addArgument("RcsID", std::to_string(connInfo.renderingControlServiceId));
response.addArgument("AVTransportID", std::to_string(connInfo.avTransportId));
response.addArgument("ProtocolInfo", connInfo.protocolInfo.toString());
response.addArgument("PeerConnectionManager", connInfo.peerConnectionManager);
response.addArgument("PeerConnectionID", std::to_string(connInfo.peerConnectionId));
response.addArgument("Direction", toString(connInfo.direction));
response.addArgument("Status", toString(connInfo.connectionStatus));
break;
}
default:
throw InvalidActionException();
}
return response;
}
catch (std::exception& e)
{
log::error("Error processing ConnectionManager request: %s", e.what());
throw InvalidActionException();
}
}
示例14: SaveShapesToXMLFile
void CollisionShapeManager::SaveShapesToXMLFile(const String& FileName, ShapeVector& ShapesToSave)
{
XML::Document ShapesDoc;
XML::Node DeclNode = ShapesDoc.AppendChild(XML::NodeDeclaration);
XML::Attribute VerAttrib = DeclNode.AppendAttribute("version");
if( DeclNode.SetName("xml") && VerAttrib.SetValue("1.0") ) {
XML::Node ShapesRoot = ShapesDoc.AppendChild( "ShapesRoot" );
for( ShapeVectorIterator ShapeIt = ShapesToSave.begin() ; ShapeIt != ShapesToSave.end() ; ++ShapeIt )
{
(*ShapeIt)->ProtoSerialize( ShapesRoot );
}
/// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready.
Resource::FileStream SettingsStream(FileName,".",Resource::SF_Truncate | Resource::SF_Write);
ShapesDoc.Save(SettingsStream,"\t",XML::FormatIndent);
}else{
MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"Failed to create XML document declaration for file \"" + FileName + "\".");
}
}
示例15: LoadAllShapesFromXMLFile
void CollisionShapeManager::LoadAllShapesFromXMLFile(const String& FileName, const String& Group)
{
/// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready.
Resource::FileStream ShapesStream( FileName, Resource::ResourceManager::GetSingletonPtr()->GetAssetPath(FileName,Group) );
XML::Document ShapesDoc;
XML::ParseResult DocResult = ShapesDoc.Load(ShapesStream);
if( DocResult.Status != XML::StatusOk ) {
MEZZ_EXCEPTION(ExceptionBase::SYNTAX_ERROR_EXCEPTION_XML,"Failed to parse XML file \"" + FileName + "\".");
}
XML::Node ShapesRoot = ShapesDoc.GetChild("InitializerRoot");
if( ShapesRoot.Empty() ) {
MEZZ_EXCEPTION(ExceptionBase::SYNTAX_ERROR_EXCEPTION_XML,"Failed to find expected Root node in \"" + FileName + "\".");
}
for( XML::NodeIterator ShapeIt = ShapesRoot.begin() ; ShapeIt != ShapesRoot.end() ; ++ShapeIt )
{
CollisionShape* DeSerializedShape = Physics::CreateShape( (*ShapeIt) );
this->CollisionShapes.insert( std::pair<String,CollisionShape*>(DeSerializedShape->GetName(),DeSerializedShape) );
}
}