本文整理汇总了C++中XMLDoc类的典型用法代码示例。如果您正苦于以下问题:C++ XMLDoc类的具体用法?C++ XMLDoc怎么用?C++ XMLDoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLDoc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
XMLNode* root = new XMLNode("root");
root->setAttribute("cmd","fuck");
root->setAttribute("abc","efg");
//root->setText("hello world");
XMLNode* node_1 = new XMLNode("abc");
node_1->setAttribute("bi","aaaa");
XMLNode* node_2 = new XMLNode("bcd");
node_2->setText("hello world");
root->addChild(node_1);
root->addChild(node_2);
node_1 = 0;
node_2 = 0;
XMLNode* n = root->getFirstChild();
if(n){
cout<<n->getName()<<endl;
}
XMLDoc* doc = new XMLDoc();
doc->setRoot(root);
cout<<doc->toString()<<endl;
return 0;
}
示例2: EmpireColors
const std::vector<GG::Clr>& EmpireColors() {
static std::vector<GG::Clr> colors;
if (colors.empty()) {
XMLDoc doc;
std::string file_name = "empire_colors.xml";
boost::filesystem::ifstream ifs(GetResourceDir() / file_name);
if (ifs) {
doc.ReadDoc(ifs);
ifs.close();
} else {
Logger().errorStream() << "Unable to open data file " << file_name;
return colors;
}
for (int i = 0; i < doc.root_node.NumChildren(); ++i) {
colors.push_back(XMLToClr(doc.root_node.Child(i)));
}
}
if (colors.empty()) {
colors.push_back(GG::Clr( 0, 255, 0, 255));
colors.push_back(GG::Clr( 0, 0, 255, 255));
colors.push_back(GG::Clr(255, 0, 0, 255));
colors.push_back(GG::Clr( 0, 255, 255, 255));
colors.push_back(GG::Clr(255, 255, 0, 255));
colors.push_back(GG::Clr(255, 0, 255, 255));
}
return colors;
}
示例3: OnCredits
void IntroScreen::OnCredits() {
if (m_credits_wnd) {
delete m_credits_wnd;
m_credits_wnd = 0;
return;
}
XMLDoc doc;
boost::filesystem::ifstream ifs(GetResourceDir() / "credits.xml");
doc.ReadDoc(ifs);
ifs.close();
if (!doc.root_node.ContainsChild("CREDITS"))
return;
XMLElement credits = doc.root_node.Child("CREDITS");
// only the area between the upper and lower line of the splash screen should be darkend
// if we use another splash screen we have the change the following values
GG::Y nUpperLine = ( 79 * GG::GUI::GetGUI()->AppHeight()) / 768;
GG::Y nLowerLine = (692 * GG::GUI::GetGUI()->AppHeight()) / 768;
int credit_side_pad(30);
m_credits_wnd = new CreditsWnd(GG::X0, nUpperLine, GG::GUI::GetGUI()->AppWidth(), nLowerLine-nUpperLine,
credits,
credit_side_pad, 0, Value(m_menu->UpperLeft().x) - credit_side_pad,
Value(nLowerLine-nUpperLine), Value((nLowerLine-nUpperLine))/2);
m_splash->AttachChild(m_credits_wnd);
}
示例4: load
bool MaterialResource::load(const char *data, int size)
{
if(!Resource::load(data, size)) return false;
XMLDoc doc;
doc.parseBuffer(data, size);
if(doc.hasError())
return raiseError("XML parsing error");
XMLNode rootNode = doc.getRootNode();
if(strcmp(rootNode.getName(), "Material")!=0)
return raiseError("Not a material resource file");
//Class
_class = rootNode.getAttribute("class", "");
//Link
if(strcmp(rootNode.getAttribute("link", ""), "")!=0)
{
uint32 mat = Modules::resMan().addResource(
ResourceTypes::Material, rootNode.getAttribute("link"), 0, false);
_matLink = (MaterialResource *)Modules::resMan().resolveResHandle(mat);
if(_matLink == this)
return raiseError("Illegal self link in material, causing infinite link loop");
}
//Shader Flags
XMLNode nodel = rootNode.getFirstChild("ShaderFlag");
while(!nodel.isEmpty())
{
if(nodel.getAttribute("name")==0x0) return raiseError("Missing ShaderFlag attribute 'name'");
_shaderFlags.push_back(nodel.getAttribute("name"));
nodel= nodel.getNextSibling("ShaderFlag");
}
//Shader
nodel = rootNode.getFirstChild("Shader");
if(!nodel.isEmpty())
{
if(nodel.getAttribute("source")==0x0) return raiseError("Missing Shader attribute 'source'");
uint32 shader = Modules::resMan().addResource(ResourceTypes::Shader, nodel.getAttribute("source"), 0, false);
_shaderRes = (ShaderResource *)Modules::resMan().resolveResHandle(shader);
_combMask = ShaderResource::calcCombMask(_shaderFlags);
_shaderRes->preLoadCombination(_combMask);
}
// //Texture samplers
// //Vector uniforms
return true;
}
示例5: putDataToDoc
void IsoCurveParameters::putDataToDoc(XMLDoc &doc) {
XMLNodePtr root = doc.createRoot(_T("IsoCurve"));
doc.setValue( root, _T("expr" ), m_expr );
doc.setValue( root, _T("cellsize" ), m_cellSize );
setValue(doc, root, _T("boundingbox" ), m_boundingBox );
doc.setValue( root, _T("machinecode" ), m_machineCode );
doc.setValue( root, _T("includetime" ), m_includeTime );
if (m_includeTime) {
setValue(doc, root, _T("timeinterval"), m_tInterval );
doc.setValue( root, _T("framecount" ), m_frameCount );
}
}
示例6: INFOLOG
bool Drumkit::save_file( const QString& dk_path, bool overwrite )
{
INFOLOG( QString( "Saving drumkit definition into %1" ).arg( dk_path ) );
if( Filesystem::file_exists( dk_path, true ) && !overwrite ) {
ERRORLOG( QString( "drumkit %1 already exists" ).arg( dk_path ) );
return false;
}
XMLDoc doc;
doc.set_root( "drumkit_info", "drumkit" );
XMLNode root = doc.firstChildElement( "drumkit_info" );
save_to( &root );
return doc.write( dk_path );
}
示例7: getDataFromDoc
void IsoCurveParameters::getDataFromDoc(XMLDoc &doc) {
XMLNodePtr root = doc.getRoot();
checkTag(root, _T("IsoCurve"));
doc.getValueLF(root, _T("expr" ), m_expr );
doc.getValue( root, _T("cellsize" ), m_cellSize );
getValue(doc, root, _T("boundingbox" ), m_boundingBox );
doc.getValue( root, _T("machinecode" ), m_machineCode );
doc.getValue( root, _T("includetime" ), m_includeTime );
if (m_includeTime) {
getValue(doc, root, _T("timeinterval"), m_tInterval );
doc.getValue( root, _T("framecount" ), m_frameCount );
}
}
示例8: load_file
Drumkit* Drumkit::load_file( const QString& dk_path, bool load_samples )
{
XMLDoc doc;
if( !doc.read( dk_path, Filesystem::drumkit_xsd() ) ) {
return Legacy::load_drumkit( dk_path );
}
XMLNode root = doc.firstChildElement( "drumkit_info" );
if ( root.isNull() ) {
ERRORLOG( "drumkit_info node not found" );
return NULL;
}
Drumkit* drumkit = Drumkit::load_from( &root, dk_path.left( dk_path.lastIndexOf( "/" ) ) );
if( load_samples ) drumkit->load_samples();
return drumkit;
}
示例9: INFOLOG
bool Pattern::save_file( const QString& drumkit_name, const QString& author, const QString& license, const QString& pattern_path, bool overwrite ) const
{
INFOLOG( QString( "Saving pattern into %1" ).arg( pattern_path ) );
if( !overwrite && Filesystem::file_exists( pattern_path, true ) ) {
ERRORLOG( QString( "pattern %1 already exists" ).arg( pattern_path ) );
return false;
}
XMLDoc doc;
XMLNode root = doc.set_root( "drumkit_pattern", "drumkit_pattern" );
root.write_string( "drumkit_name", drumkit_name ); // FIXME loaded with LocalFileMng::getDrumkitNameForPattern(…)
root.write_string( "author", author ); // FIXME this is never loaded back
root.write_string( "license", license ); // FIXME this is never loaded back
save_to( &root );
return doc.write( pattern_path );
}
示例10: readXMLDoc
static XMLDoc* readXMLDoc(const std::string& name,
const std::string& dtdPath)
{
std::string p = path(name);
std::string data = Reader::readString(name);
xmlDtd* dtd = getDTD(dtdPath);
if (!dtd || data.empty())
return NULL;
XMLDoc* doc = new XMLDoc;
if (!doc->init(p, data, dtd)) {
delete doc;
return NULL;
}
return doc;
}
示例11: ofs
void OptionsDB::Commit()
{
if (!m_dirty)
return;
boost::filesystem::ofstream ofs(GetConfigPath());
if (ofs) {
XMLDoc doc;
GetOptionsDB().GetXML(doc);
doc.WriteDoc(ofs);
m_dirty = false;
} else {
std::cerr << UserString("UNABLE_TO_WRITE_CONFIG_XML") << std::endl;
std::cerr << PathString(GetConfigPath()) << std::endl;
ErrorLogger() << UserString("UNABLE_TO_WRITE_CONFIG_XML");
ErrorLogger() << PathString(GetConfigPath());
}
}
示例12: SetFromFile
void OptionsDB::SetFromFile(const boost::filesystem::path& file_path,
const std::string& version)
{
XMLDoc doc;
try {
boost::filesystem::ifstream ifs(file_path);
if (ifs) {
doc.ReadDoc(ifs);
if (version.empty() || (doc.root_node.ContainsChild("version-string") &&
doc.root_node.Child("version-string").Text() == version))
{
GetOptionsDB().SetFromXML(doc);
}
}
} catch (const std::exception&) {
std::cerr << UserString("UNABLE_TO_READ_CONFIG_XML") << ": "
<< file_path << std::endl;
}
}
示例13: load
bool ParticleEffectResource::load( const char *data, int size )
{
if( !Resource::load( data, size ) ) return false;
XMLDoc doc;
doc.parseBuffer( data, size );
if( doc.hasError() )
return raiseError( "XML parsing error" );
XMLNode rootNode = doc.getRootNode();
if( strcmp( rootNode.getName(), "ParticleEffect" ) != 0 )
return raiseError( "Not a particle effect resource file" );
if( rootNode.getAttribute( "lifeMin" ) == 0x0 ) return raiseError( "Missing ParticleConfig attribute 'lifeMin'" );
if( rootNode.getAttribute( "lifeMax" ) == 0x0 ) return raiseError( "Missing ParticleConfig attribute 'lifeMax'" );
_lifeMin = (float)atof( rootNode.getAttribute( "lifeMin" ) );
_lifeMax = (float)atof( rootNode.getAttribute( "lifeMax" ) );
XMLNode node1 = rootNode.getFirstChild( "ChannelOverLife" );
while( !node1.isEmpty() )
{
if( node1.getAttribute( "channel" ) != 0x0 )
{
if( _stricmp( node1.getAttribute( "channel" ), "moveVel" ) == 0 ) _moveVel.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "rotVel" ) == 0 ) _rotVel.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "drag" ) == 0 ) _drag.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "size" ) == 0 ) _size.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "colR" ) == 0 ) _colR.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "colG" ) == 0 ) _colG.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "colB" ) == 0 ) _colB.parse( node1 );
else if( _stricmp( node1.getAttribute( "channel" ), "colA" ) == 0 ) _colA.parse( node1 );
}
else
return raiseError( "Missing ChannelOverLife attribute 'channel'" );
node1 = node1.getNextSibling( "ChannelOverLife" );
}
return true;
}
示例14: load
bool SceneGraphResource::load( const char *data, int size )
{
if( !Resource::load( data, size ) ) return false;
XMLDoc doc;
doc.parseBuffer( data, size );
if( doc.hasError() )
{
return false;
}
// Parse scene nodes and load resources
XMLNode rootNode = doc.getRootNode();
if( !rootNode.isEmpty() )
{
parseNode( rootNode, 0x0 );
}
else
{
return false;
}
return true;
}
示例15: Sprite_Create
SpriteObj* Sprite_Create(const std::string& name, bool immediate)
{
immediate = immediate || !g_supportAsynchronousResourceLoading;
SpriteResource* resource = static_cast<SpriteResource*>(Resource_Find("sprite", name));
if (resource)
Resource_IncRefCount(resource);
// Create sprite from XML
else if (!strstr(name.c_str(), "."))
{
const std::string path = name + ".sprite.xml";
XMLDoc doc;
if (!doc.Load(path))
{
Log::Error("Failed to load sprite resource from " + path);
return NULL;
}
XMLNode* spriteNode = doc.AsNode()->GetFirstNode("sprite");
if (!spriteNode)
{
Log::Error("Failed to load sprite resource from " + path + ", reason: root node 'sprite' not found.");
return NULL;
}
MaterialObj* material = NULL;
if (const char* materialName = XMLNode_GetAttributeValue(spriteNode, "material"))
{
material = Material_Create(materialName);
if (!material)
{
Log::Error("Failed to load sprite resource from " + path + ", reason: can't load material " + materialName);
return NULL;
}
}
resource = new SpriteResource();
resource->state = ResourceState_CreationInProgress;
resource->name = name;
Material_SetHandle(material, resource->material);
Resource_IncRefCount(resource);
// Load animations
std::string defaultAnimationName;
for (XMLNode* animNode = XMLNode_GetFirstNode(spriteNode, "animation"); animNode; animNode = XMLNode_GetNext(animNode, "animation"))
{
const std::string name = XMLNode_GetAttributeValue(animNode, "name");
SpriteResource::Animation& anim = map_add(resource->animations, name);
anim.name = name;
// Get frame time
XMLNode_GetAttributeValueFloat(animNode, "frameTime", anim.frameTime, 0.1f);
// Check blend mode
//XMLNode_GetAttributeValueBool(animNode, "blending", anim->blendFrames);
// Check if default
bool isDefault;
if (defaultAnimationName.empty() || (XMLNode_GetAttributeValueBool(animNode, "isDefault", isDefault) && isDefault))
defaultAnimationName = anim.name;
// Load all frames and events
float time = 0.0f;
for (XMLNode* elemNode = XMLNode_GetFirstNode(animNode); elemNode; elemNode = XMLNode_GetNext(elemNode))
{
const char* elemName = XMLNode_GetName(elemNode);
if (!strcmp(elemName, "frame"))
{
SpriteResource::Frame& frame = vector_add(anim.frames);
const char* textureName = XMLNode_GetAttributeValue(elemNode, "texture");
frame.texture.Create(textureName, immediate);
if (!frame.texture.IsValid())
{
Log::Error("Failed to load sprite resource from " + path + ", reason: failed to load texture " + textureName);
delete resource;
return NULL;
}
time += anim.frameTime;
}
else if (!strcmp(elemName, "event"))
{
SpriteResource::Event& ev = vector_add(anim.events);
ev.time = time;
ev.name = XMLNode_GetAttributeValue(elemNode, "name");
}
}
anim.totalTime = (float) anim.frames.size() * anim.frameTime;
//.........这里部分代码省略.........