本文整理汇总了C++中TiXmlElement::Value方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlElement::Value方法的具体用法?C++ TiXmlElement::Value怎么用?C++ TiXmlElement::Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlElement
的用法示例。
在下文中一共展示了TiXmlElement::Value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadNode
void LoadNode(Node *parent, TiXmlElement *element, int level)
{
Node *node = new Node;
parent->AppendChild(node);
// name
const char* name = element->Attribute("name");
node->SetName(name);
PrintIndent(level);
printf("object [");
if ( name ) printf("%s",name);
printf("]");
// type
const char* type = element->Attribute("type");
if ( type ) {
if ( COMPARE(type,"sphere") ) {
node->SetObject( &theSphere );
printf(" - Sphere");
} else if ( COMPARE(type,"plane") ) {
node->SetObject( &thePlane );
printf(" - Plane");
} else if ( COMPARE(type,"obj") ) {
printf(" - OBJ");
Object *obj = objList.Find(name);
if ( obj == NULL ) { // object is not on the list, so we should load it now
TriObj *tobj = new TriObj;
if ( ! tobj->Load( name ) ) {
printf(" -- ERROR: Cannot load file \"%s.\"", name);
delete tobj;
} else {
objList.Append(tobj,name); // add to the list
obj = tobj;
}
}
node->SetObject( obj );
} else {
printf(" - UNKNOWN TYPE");
}
}
// type
const char* mtlName = element->Attribute("material");
if ( mtlName ) {
printf(" <%s>", mtlName);
NodeMtl nm;
nm.node = node;
nm.mtlName = mtlName;
nodeMtlList.push_back(nm);
}
printf("\n");
for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
if ( COMPARE( child->Value(), "object" ) ) {
LoadNode(node,child,level+1);
}
}
LoadTransform( node, element, level );
}
示例2: ParseSettingsFile
void CAdvancedSettings::ParseSettingsFile(const CStdString &file)
{
CXBMCTinyXML advancedXML;
if (!CFile::Exists(file))
{
CLog::Log(LOGNOTICE, "No settings file to load (%s)", file.c_str());
return;
}
if (!advancedXML.LoadFile(file))
{
CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", file.c_str(), advancedXML.ErrorRow(), advancedXML.ErrorDesc());
return;
}
TiXmlElement *pRootElement = advancedXML.RootElement();
if (!pRootElement || strcmpi(pRootElement->Value(),"advancedsettings") != 0)
{
CLog::Log(LOGERROR, "Error loading %s, no <advancedsettings> node", file.c_str());
return;
}
// succeeded - tell the user it worked
CLog::Log(LOGNOTICE, "Loaded settings file from %s", file.c_str());
// Dump contents of AS.xml to debug log
TiXmlPrinter printer;
printer.SetLineBreak("\n");
printer.SetIndent(" ");
advancedXML.Accept(&printer);
CLog::Log(LOGNOTICE, "Contents of %s are...\n%s", file.c_str(), printer.CStr());
TiXmlElement *pElement = pRootElement->FirstChildElement("audio");
if (pElement)
{
XMLUtils::GetFloat(pElement, "ac3downmixgain", m_ac3Gain, -96.0f, 96.0f);
XMLUtils::GetInt(pElement, "headroom", m_audioHeadRoom, 0, 12);
XMLUtils::GetString(pElement, "defaultplayer", m_audioDefaultPlayer);
// 101 on purpose - can be used to never automark as watched
XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_audioPlayCountMinimumPercent, 0.0f, 101.0f);
XMLUtils::GetBoolean(pElement, "usetimeseeking", m_musicUseTimeSeeking);
XMLUtils::GetInt(pElement, "timeseekforward", m_musicTimeSeekForward, 0, 6000);
XMLUtils::GetInt(pElement, "timeseekbackward", m_musicTimeSeekBackward, -6000, 0);
XMLUtils::GetInt(pElement, "timeseekforwardbig", m_musicTimeSeekForwardBig, 0, 6000);
XMLUtils::GetInt(pElement, "timeseekbackwardbig", m_musicTimeSeekBackwardBig, -6000, 0);
XMLUtils::GetInt(pElement, "percentseekforward", m_musicPercentSeekForward, 0, 100);
XMLUtils::GetInt(pElement, "percentseekbackward", m_musicPercentSeekBackward, -100, 0);
XMLUtils::GetInt(pElement, "percentseekforwardbig", m_musicPercentSeekForwardBig, 0, 100);
XMLUtils::GetInt(pElement, "percentseekbackwardbig", m_musicPercentSeekBackwardBig, -100, 0);
XMLUtils::GetInt(pElement, "resample", m_audioResample, 0, 192000);
XMLUtils::GetBoolean(pElement, "allowtranscode44100", m_allowTranscode44100);
XMLUtils::GetBoolean(pElement, "forceDirectSound", m_audioForceDirectSound);
XMLUtils::GetBoolean(pElement, "audiophile", m_audioAudiophile);
XMLUtils::GetBoolean(pElement, "allchannelstereo", m_allChannelStereo);
XMLUtils::GetString(pElement, "transcodeto", m_audioTranscodeTo);
XMLUtils::GetInt(pElement, "audiosinkbufferdurationmsec", m_audioSinkBufferDurationMsec);
TiXmlElement* pAudioExcludes = pElement->FirstChildElement("excludefromlisting");
if (pAudioExcludes)
GetCustomRegexps(pAudioExcludes, m_audioExcludeFromListingRegExps);
pAudioExcludes = pElement->FirstChildElement("excludefromscan");
if (pAudioExcludes)
GetCustomRegexps(pAudioExcludes, m_audioExcludeFromScanRegExps);
XMLUtils::GetString(pElement, "audiohost", m_audioHost);
XMLUtils::GetBoolean(pElement, "applydrc", m_audioApplyDrc);
XMLUtils::GetBoolean(pElement, "dvdplayerignoredtsinwav", m_dvdplayerIgnoreDTSinWAV);
XMLUtils::GetFloat(pElement, "limiterhold", m_limiterHold, 0.0f, 100.0f);
XMLUtils::GetFloat(pElement, "limiterrelease", m_limiterRelease, 0.001f, 100.0f);
}
pElement = pRootElement->FirstChildElement("karaoke");
if (pElement)
{
XMLUtils::GetFloat(pElement, "syncdelaycdg", m_karaokeSyncDelayCDG, -3.0f, 3.0f); // keep the old name for comp
XMLUtils::GetFloat(pElement, "syncdelaylrc", m_karaokeSyncDelayLRC, -3.0f, 3.0f);
XMLUtils::GetBoolean(pElement, "alwaysreplacegenre", m_karaokeChangeGenreForKaraokeSongs );
XMLUtils::GetBoolean(pElement, "storedelay", m_karaokeKeepDelay );
XMLUtils::GetInt(pElement, "autoassignstartfrom", m_karaokeStartIndex, 1, 2000000000);
XMLUtils::GetBoolean(pElement, "nocdgbackground", m_karaokeAlwaysEmptyOnCdgs );
XMLUtils::GetBoolean(pElement, "lookupsongbackground", m_karaokeUseSongSpecificBackground );
TiXmlElement* pKaraokeBackground = pElement->FirstChildElement("defaultbackground");
if (pKaraokeBackground)
{
const char* attr = pKaraokeBackground->Attribute("type");
if ( attr )
m_karaokeDefaultBackgroundType = attr;
attr = pKaraokeBackground->Attribute("path");
if ( attr )
m_karaokeDefaultBackgroundFilePath = attr;
}
}
//.........这里部分代码省略.........
示例3: SaveConfig
bool CConfigManager::SaveConfig()
{
TiXmlDocument doc;
doc.LoadFile(m_strConfigFile.c_str());
TiXmlElement* pRoot = doc.RootElement();
const char* szRoot = pRoot->Value();
if(strcmp("system", szRoot) != 0)
return false;
for (TiXmlElement* pChiled = pRoot->FirstChildElement(); pChiled != NULL; pChiled = pChiled->NextSiblingElement())
{
const char* szValue = pChiled->Value();
if(strcmp(Software, szValue) == 0)
{
pChiled->SetAttribute(Ver, m_strAppVer.c_str());
}
else if(strcmp(Configur, szValue) == 0)
{
pChiled->SetAttribute(Ver, m_strConfigVer.c_str());
}
// else if(strcmp(Globle, szValue) == 0)
// {
// m_strHeight = pChiled->Attribute(Height);
// m_strWidth = pChiled->Attribute(Width);
// string strAdverCount = pChiled->Attribute(AdverCount);
// m_nAdverCount = atoi(strAdverCount.c_str());
// }
else if(strcmp(Sever, szValue) == 0)
{
pChiled->SetAttribute(IP, m_strIp.c_str());
pChiled->SetAttribute(Port, m_strPort.c_str());
}
else if(strcmp(Notice, szValue) == 0)
{
pChiled->SetAttribute(Dir, m_strNoticeDir.c_str());
}
else if(strcmp(Template, szValue) == 0)
{
pChiled->SetAttribute(Ver, m_strTempVer.c_str());
pChiled->SetAttribute(Dir, m_strTemplatePath.c_str());
}
else if(strcmp(Adver, szValue) == 0)
{
m_Adver.SaveAdver(pChiled);
}
else if(strcmp(BusStop, szValue) == 0)
{
m_Busstop.SaveBusStop(pChiled);
}
else if(strcmp(Picture, szValue) == 0)
{
pChiled->SetAttribute(Dir, m_strPictrueDir.c_str());
}
else if(strcmp(Default, szValue) == 0)
{
pChiled->SetAttribute(Dir, m_strDefaultPath.c_str());
}
}
doc.SaveFile();
return true;
}
示例4: ConvertFromOldConfig
TiXmlElement* wxsVersionConverter::ConvertFromOldConfig(TiXmlElement* ConfigNode,TiXmlDocument* Doc,wxsProject* Project) const
{
if ( cbMessageBox(_("This project uses old wxSmith configuration format\n"
"Would you like me to convert to new one?\n"),
_("wxSmith: Converting from old format"),
wxYES_NO) != wxID_YES ) return 0;
TiXmlElement* NewConfig = Doc->InsertEndChild(TiXmlElement("wxSmith"))->ToElement();
TiXmlElement* Resources = NewConfig->InsertEndChild(TiXmlElement("resources"))->ToElement();
NewConfig->SetAttribute("version",CurrentVersionStr);
for ( TiXmlElement* Node = ConfigNode->FirstChildElement(); Node; Node = Node->NextSiblingElement() )
{
wxString NodeName = cbC2U(Node->Value());
if ( NodeName == _T("configuration") )
{
const char* AppSrc = Node->Attribute("app_src_file");
const char* Main = Node->Attribute("main_resource");
const char* InitAll = Node->Attribute("init_all_handlers");
if ( AppSrc )
{
TiXmlElement* GUINode = NewConfig->InsertEndChild(TiXmlElement("gui"))->ToElement();
GUINode->SetAttribute("name","wxWidgets");
GUINode->SetAttribute("src",AppSrc);
GUINode->SetAttribute("main",Main?Main:"");
GUINode->SetAttribute("init_handlers",InitAll?InitAll:"necessary");
GUINode->SetAttribute("language","CPP");
}
}
else
{
if ( NodeName == _T("dialog") ||
NodeName == _T("frame") ||
NodeName == _T("panel") )
{
const char* Wxs = Node->Attribute("wxs_file");
const char* Class = Node->Attribute("class");
const char* Src = Node->Attribute("src_file");
const char* Hdr = Node->Attribute("header_file");
const char* Xrc = Node->Attribute("xrc_file");
const char* Mode = Node->Attribute("edit_mode");
if ( Wxs && Class && Src && Hdr && Mode )
{
if ( cbC2U(Mode) == _T("Source") ) Xrc = 0;
TiXmlElement* Res = Resources->InsertEndChild(TiXmlElement(
NodeName == _T("dialog") ? "wxDialog" :
NodeName == _T("frame") ? "wxFrame" :
"wxPanel" ))->ToElement();
Res->SetAttribute("wxs",cbU2C(_T("wxsmith/")+cbC2U(Wxs)));
Res->SetAttribute("src",Src);
Res->SetAttribute("hdr",Hdr);
if ( Xrc ) Res->SetAttribute("xrc",Xrc);
Res->SetAttribute("name",Class);
Res->SetAttribute("language","CPP");
ConvertOldWxsFile(Project->GetProjectPath()+_T("wxsmith/")+cbC2U(Wxs),Xrc!=0);
AdoptOldSourceFile(Project->GetProjectPath()+cbC2U(Src),cbC2U(Class));
}
}
}
}
return NewConfig;
}
示例5: Load
bool CGUIWindow::Load(TiXmlElement *pRootElement)
{
if (!pRootElement)
return false;
// set the scaling resolution so that any control creation or initialisation can
// be done with respect to the correct aspect ratio
CServiceBroker::GetWinSystem()->GetGfxContext().SetScalingResolution(m_coordsRes, m_needsScaling);
// now load in the skin file
SetDefaults();
CGUIControlFactory::GetInfoColor(pRootElement, "backgroundcolor", m_clearBackground, GetID());
CGUIControlFactory::GetActions(pRootElement, "onload", m_loadActions);
CGUIControlFactory::GetActions(pRootElement, "onunload", m_unloadActions);
CRect parentRect(0, 0, static_cast<float>(m_coordsRes.iWidth), static_cast<float>(m_coordsRes.iHeight));
CGUIControlFactory::GetHitRect(pRootElement, m_hitRect, parentRect);
TiXmlElement *pChild = pRootElement->FirstChildElement();
while (pChild)
{
std::string strValue = pChild->Value();
if (strValue == "previouswindow" && pChild->FirstChild())
{
m_previousWindow = CWindowTranslator::TranslateWindow(pChild->FirstChild()->Value());
}
else if (strValue == "defaultcontrol" && pChild->FirstChild())
{
const char *always = pChild->Attribute("always");
if (always && StringUtils::EqualsNoCase(always, "true"))
m_defaultAlways = true;
m_defaultControl = atoi(pChild->FirstChild()->Value());
}
else if(strValue == "menucontrol" && pChild->FirstChild())
{
m_menuControlID = atoi(pChild->FirstChild()->Value());
}
else if (strValue == "visible" && pChild->FirstChild())
{
std::string condition;
CGUIControlFactory::GetConditionalVisibility(pRootElement, condition);
m_visibleCondition = CServiceBroker::GetGUI()->GetInfoManager().Register(condition, GetID());
}
else if (strValue == "animation" && pChild->FirstChild())
{
CRect rect(0, 0, static_cast<float>(m_coordsRes.iWidth), static_cast<float>(m_coordsRes.iHeight));
CAnimation anim;
anim.Create(pChild, rect, GetID());
m_animations.push_back(anim);
}
else if (strValue == "zorder" && pChild->FirstChild())
{
m_renderOrder = atoi(pChild->FirstChild()->Value());
}
else if (strValue == "coordinates")
{
XMLUtils::GetFloat(pChild, "posx", m_posX);
XMLUtils::GetFloat(pChild, "posy", m_posY);
XMLUtils::GetFloat(pChild, "left", m_posX);
XMLUtils::GetFloat(pChild, "top", m_posY);
TiXmlElement *originElement = pChild->FirstChildElement("origin");
while (originElement)
{
COrigin origin;
origin.x = CGUIControlFactory::ParsePosition(originElement->Attribute("x"), static_cast<float>(m_coordsRes.iWidth));
origin.y = CGUIControlFactory::ParsePosition(originElement->Attribute("y"), static_cast<float>(m_coordsRes.iHeight));
if (originElement->FirstChild())
origin.condition = CServiceBroker::GetGUI()->GetInfoManager().Register(originElement->FirstChild()->Value(), GetID());
m_origins.push_back(origin);
originElement = originElement->NextSiblingElement("origin");
}
}
else if (strValue == "camera")
{ // z is fixed
m_camera.x = CGUIControlFactory::ParsePosition(pChild->Attribute("x"), static_cast<float>(m_coordsRes.iWidth));
m_camera.y = CGUIControlFactory::ParsePosition(pChild->Attribute("y"), static_cast<float>(m_coordsRes.iHeight));
m_hasCamera = true;
}
else if (strValue == "depth" && pChild->FirstChild())
{
float stereo = static_cast<float>(atof(pChild->FirstChild()->Value()));
m_stereo = std::max(-1.f, std::min(1.f, stereo));
}
else if (strValue == "controls")
{
TiXmlElement *pControl = pChild->FirstChildElement();
while (pControl)
{
if (StringUtils::EqualsNoCase(pControl->Value(), "control"))
{
LoadControl(pControl, nullptr, CRect(0, 0, static_cast<float>(m_coordsRes.iWidth), static_cast<float>(m_coordsRes.iHeight)));
}
pControl = pControl->NextSiblingElement();
}
}
pChild = pChild->NextSiblingElement();
}
//.........这里部分代码省略.........
示例6: AddBookmark
bool CSiteManager::AddBookmark(wxString sitePath, const wxString& name, const wxString &local_dir, const CServerPath &remote_dir, bool sync)
{
if (local_dir.empty() && remote_dir.IsEmpty())
return false;
if (sitePath[0] != '0')
return false;
sitePath = sitePath.Mid(1);
// We have to synchronize access to sitemanager.xml so that multiple processed don't write
// to the same file or one is reading while the other one writes.
CInterProcessMutex mutex(MUTEX_SITEMANAGER);
CXmlFile file;
TiXmlElement* pDocument = 0;
pDocument = file.Load(_T("sitemanager"));
if (!pDocument)
{
wxString msg = file.GetError() + _T("\n") + _("The bookmark could not be added.");
wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);
return false;
}
TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
if (!pElement)
return false;
std::list<wxString> segments;
if (!UnescapeSitePath(sitePath, segments))
{
wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
return 0;
}
TiXmlElement* pChild = GetElementByPath(pElement, segments);
if (!pChild || strcmp(pChild->Value(), "Server"))
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
// Bookmarks
TiXmlElement *pInsertBefore = 0;
TiXmlElement* pBookmark;
for (pBookmark = pChild->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark"))
{
TiXmlHandle handle(pBookmark);
wxString old_name = GetTextElement_Trimmed(pBookmark, "Name");
if (old_name.empty())
continue;
if (name == old_name)
{
wxMessageBox(_("Name of bookmark already exists."), _("New bookmark"), wxICON_EXCLAMATION);
return false;
}
if (name < old_name && !pInsertBefore)
pInsertBefore = pBookmark;
}
if (pInsertBefore)
pBookmark = pChild->InsertBeforeChild(pInsertBefore, TiXmlElement("Bookmark"))->ToElement();
else
pBookmark = pChild->LinkEndChild(new TiXmlElement("Bookmark"))->ToElement();
AddTextElement(pBookmark, "Name", name);
if (!local_dir.empty())
AddTextElement(pBookmark, "LocalDir", local_dir);
if (!remote_dir.IsEmpty())
AddTextElement(pBookmark, "RemoteDir", remote_dir.GetSafePath());
if (sync)
AddTextElementRaw(pBookmark, "SyncBrowsing", "1");
wxString error;
if (!file.Save(&error))
{
if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2)
return true;
wxString msg = wxString::Format(_("Could not write \"%s\", the selected sites could not be exported: %s"), file.GetFileName().GetFullPath().c_str(), error.c_str());
wxMessageBox(msg, _("Error writing xml file"), wxICON_ERROR);
}
return true;
}
示例7: OpenXML
bool InternetRetrievalDialog::OpenXML(wxString filename)
{
ClearInternetRetrieval();
m_lServers->Clear();
TiXmlDocument doc;
wxString error;
wxProgressDialog *progressdialog = NULL;
wxDateTime start = wxDateTime::UNow();
if(!doc.LoadFile(filename.mb_str()))
FAIL(_("Failed to load file: ") + filename);
else {
TiXmlElement *root = doc.RootElement();
if(strcmp(root->Value(), "OCPNWeatherFaxInternetRetrieval"))
FAIL(_("Invalid xml file"));
int count = 0;
for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement())
count++;
int i=0;
for(TiXmlElement* e = root->FirstChildElement(); e; e = e->NextSiblingElement(), i++) {
if(progressdialog) {
if(!progressdialog->Update(i))
return true;
} else {
wxDateTime now = wxDateTime::UNow();
if((now-start).GetMilliseconds() > 500 && i < count/3) {
progressdialog = new wxProgressDialog(
_("WeatherFax Internet Retrieval"), _("Loading"), count, this,
wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME);
}
}
if(!strcmp(e->Value(), "Server")) {
FaxServer server;
server.Name = wxString::FromUTF8(e->Attribute("Name"));
m_Servers.push_back(server);
wxString server_url = wxString::FromUTF8(e->Attribute("Url"));
m_lServers->Append(server.Name);
for(TiXmlElement* f = e->FirstChildElement(); f; f = f->NextSiblingElement()) {
if(!strcmp(f->Value(), "Region")) {
FaxRegion region;
region.Name = wxString::FromUTF8(f->Attribute("Name"));
region.Server = server.Name;
for(std::list<FaxRegion>::iterator it = m_Regions.begin();
it != m_Regions.end(); it++)
if(it->Name == region.Name && it->Server == region.Server)
goto duplicate_region;
m_Regions.push_back(region);
duplicate_region:
wxString region_url = server_url + wxString::FromUTF8(f->Attribute("Url"));
std::list<FaxUrl> urls;
std::list<FaxArea> Areas;
for(TiXmlElement* g = f->FirstChildElement(); g; g = g->NextSiblingElement()) {
if(!strcmp(g->Value(), "Iterator")) {
wxString s_start = wxString::FromUTF8(g->Attribute("From"));
wxString s_to = wxString::FromUTF8(g->Attribute("To"));
wxString s_by = wxString::FromUTF8(g->Attribute("By"));
if(s_start.size() == 0 || s_to.size() == 0 || s_by.size() == 0)
FAIL(_("Invalid iterator: ") + wxString::FromUTF8(g->Value()));
long start, to, by;
s_start.ToLong(&start);
s_to.ToLong(&to);
s_by.ToLong(&by);
for(TiXmlElement* h = g->FirstChildElement(); h; h = h->NextSiblingElement()) {
if(!strcmp(h->Value(), "Map")) {
FaxUrl url;
url.Scheduled = false;
url.Server = server.Name;
url.Region = region.Name;
for(int index = start; index <= to; index += by) {
wxString iurl = wxString::FromUTF8(h->Attribute("Url"));
url.Url = region_url + wxString::Format
(iurl, index);
url.Contents = wxString::Format
(wxString::FromUTF8(h->Attribute("Contents")), index);
url.area_name = wxString::FromUTF8(h->Attribute("Area"));
urls.push_back(url);
}
} else
FAIL(_("Unrecognized xml node: ") + wxString::FromUTF8(g->Value()));
}
} else if(!strcmp(g->Value(), "Map")) {
FaxUrl url;
//.........这里部分代码省略.........
示例8: Init
void StyleManager::Init( wxString fromPath )
{
TiXmlDocument doc;
if( !wxDir::Exists( fromPath ) ) {
wxString msg = _T("No styles found at: ");
msg << fromPath;
wxLogMessage( msg );
return;
}
wxDir dir( fromPath );
if( !dir.IsOpened() ) return;
wxString filename;
// We allow any number of styles to load from files called style<something>.xml
bool more = dir.GetFirst( &filename, _T("style*.xml"), wxDIR_FILES );
if( !more ) {
wxString msg = _T("No styles found at: ");
msg << fromPath;
wxLogMessage( msg );
return;
}
bool firstFile = true;
while( more ) {
wxString name, extension;
if( !firstFile ) more = dir.GetNext( &filename );
if( !more ) break;
firstFile = false;
wxString fullFilePath = fromPath + filename;
if( !doc.LoadFile( (const char*) fullFilePath.mb_str() ) ) {
wxString msg( _T("Attempt to load styles from this file failed: ") );
msg += fullFilePath;
wxLogMessage( msg );
continue;
}
wxString msg( _T("Styles loading from ") );
msg += fullFilePath;
wxLogMessage( msg );
TiXmlHandle hRoot( doc.RootElement() );
wxString root = wxString( doc.RootElement()->Value(), wxConvUTF8 );
if( root != _T("styles" ) ) {
wxLogMessage( _T(" StyleManager: Expected XML Root <styles> not found.") );
continue;
}
TiXmlElement* styleElem = hRoot.FirstChild().Element();
for( ; styleElem; styleElem = styleElem->NextSiblingElement() ) {
if( wxString( styleElem->Value(), wxConvUTF8 ) == _T("style") ) {
Style* style = new Style();
styles.Add( style );
style->name = wxString( styleElem->Attribute( "name" ), wxConvUTF8 );
style->myConfigFileDir = fromPath;
TiXmlElement* subNode = styleElem->FirstChild()->ToElement();
for( ; subNode; subNode = subNode->NextSiblingElement() ) {
wxString nodeType( subNode->Value(), wxConvUTF8 );
if( nodeType == _T("description") ) {
style->description = wxString( subNode->GetText(), wxConvUTF8 );
continue;
}
if( nodeType == _T("chart-status-icon") ) {
int w = 0;
subNode->QueryIntAttribute( "width", &w );
style->chartStatusIconWidth = w;
continue;
}
if( nodeType == _T("chart-status-window") ) {
style->chartStatusWindowTransparent = wxString(
subNode->Attribute( "transparent" ), wxConvUTF8 ).Lower().IsSameAs(
_T("true") );
continue;
}
if( nodeType == _T("embossed-indicators") ) {
style->embossFont = wxString( subNode->Attribute( "font" ), wxConvUTF8 );
subNode->QueryIntAttribute( "size", &(style->embossHeight) );
continue;
}
if( nodeType == _T("graphics-file") ) {
style->graphicsFile = wxString( subNode->Attribute( "name" ), wxConvUTF8 );
isOK = true; // If we got this far we are at least partially OK...
continue;
}
if( nodeType == _T("active-route") ) {
//.........这里部分代码省略.........
示例9: parsXml
Module* XmlModLoader::parsXml(const char* szFile)
{
module.clear();
ErrorLogger* logger = ErrorLogger::Instance();
TiXmlDocument doc(szFile);
if(!doc.LoadFile())
{
OSTRINGSTREAM err;
err<<"Syntax error while loading "<<szFile<<" at line "\
<<doc.ErrorRow()<<": ";
err<<doc.ErrorDesc();
logger->addError(err);
return NULL;
}
/* retrieving root module */
TiXmlElement *root = doc.RootElement();
if(!root)
{
OSTRINGSTREAM err;
err<<"Syntax error while loading "<<szFile<<" . ";
err<<"No root element.";
logger->addError(err);
return NULL;
}
if(!compareString(root->Value(), "module"))
{
/*
OSTRINGSTREAM msg;
msg<<szFile<<" is not a module descriptor file.";
logger->addWarning(msg);
*/
return NULL;
}
/* retrieving name */
TiXmlElement* name = (TiXmlElement*) root->FirstChild("name");
if(!name || !name->GetText())
{
OSTRINGSTREAM err;
err<<"Module from "<<szFile<<" has no name.";
logger->addError(err);
//return NULL;
}
module.setXmlFile(szFile);
if(name)
module.setName(name->GetText());
/* retrieving description */
TiXmlElement* desc;
if((desc = (TiXmlElement*) root->FirstChild("description")))
module.setDescription(desc->GetText());
/* retrieving version */
TiXmlElement* ver;
if((ver = (TiXmlElement*) root->FirstChild("version")))
module.setVersion(ver->GetText());
/* retrieving parameter */
TiXmlElement* arguments;
if((arguments = (TiXmlElement*) root->FirstChild("arguments")))
for(TiXmlElement* param = arguments->FirstChildElement(); param;
param = param->NextSiblingElement())
{
if(compareString(param->Value(), "param"))
{
if(param->GetText())
{
bool brequired = false;
if(compareString(param->Attribute("required"), "yes"))
brequired = true;
Argument arg(param->GetText(),
brequired,
param->Attribute("desc"));
arg.setDefault(param->Attribute("default"));
module.addArgument(arg);
}
}
else
if(compareString(param->Value(), "switch"))
{
if(param->GetText())
{
bool brequired = false;
if(compareString(param->Attribute("required"), "yes"))
brequired = true;
Argument arg(param->GetText(),
brequired,
param->Attribute("desc"), true);
arg.setDefault(param->Attribute("default"));
module.addArgument(arg);
}
}
else
{
//.........这里部分代码省略.........
示例10: LoadPrefs
bool LoadPrefs()
{
if (prefLoaded) // already attempted loading
return true;
char filepath[MAXPATHLEN];
sprintf(filepath, "%s/%s", MPLAYER_DATADIR, PREF_FILE_NAME);
TiXmlDocument doc;
bool loadOkay = doc.LoadFile(filepath);
if (loadOkay) {
FixInvalidSettings();
TiXmlHandle docu(&doc);
TiXmlElement* settings = docu.FirstChildElement().Element();
if (settings == NULL) {
goto noheader;
}
TiXmlHandle handle(0);
TiXmlElement* elem;
handle = TiXmlHandle(settings);
elem = handle.FirstChild("global").FirstChild().Element();
for (elem; elem; elem = elem->NextSiblingElement()) {
const char* elemName = elem->Value();
if (strcmp(elemName, "exit") == 0) {
XMPlayerCfg.exit_action = atoi(elem->Attribute("value"));
} else if (strcmp(elemName, "language") == 0) {
XMPlayerCfg.language = atoi(elem->Attribute("value"));
}
}
elem = handle.FirstChild("filebrowser").FirstChild().Element();
for (elem; elem; elem = elem->NextSiblingElement()) {
const char* elemName = elem->Value();
if (strcmp(elemName, "sort") == 0) {
XMPlayerCfg.sort_order = atoi(elem->Attribute("value"));
}
}
elem = handle.FirstChild("audio").FirstChild().Element();
for (elem; elem; elem = elem->NextSiblingElement()) {
const char* elemName = elem->Value();
if (strcmp(elemName, "language") == 0) {
sprintf(XMPlayerCfg.alang, elem->Attribute("value"));
sprintf(XMPlayerCfg.alang_desc, elem->Attribute("desc"));
} else if (strcmp(elemName, "volume") == 0) {
XMPlayerCfg.volume = atoi(elem->Attribute("value"));
} else if (strcmp(elemName, "softvol") == 0) {
XMPlayerCfg.softvol = atoi(elem->Attribute("value"));
}
}
elem = handle.FirstChild("video").FirstChild().Element();
for (elem; elem; elem = elem->NextSiblingElement()) {
const char* elemName = elem->Value();
if (strcmp(elemName, "framedrop") == 0) {
XMPlayerCfg.framedrop = atoi(elem->Attribute("value"));
} else if (strcmp(elemName, "vsync") == 0) {
XMPlayerCfg.vsync = atoi(elem->Attribute("value"));
}
}
elem = handle.FirstChild("subtitles").FirstChild().Element();
for (elem; elem; elem = elem->NextSiblingElement()) {
const char* elemName = elem->Value();
if (strcmp(elemName, "sub_color") == 0) {
elem->Attribute("value", &XMPlayerCfg.subcolor);
} else if (strcmp(elemName, "border_color") == 0) {
elem->Attribute("value", &XMPlayerCfg.border_color);
} else if (strcmp(elemName, "codepage") == 0) {
sprintf(XMPlayerCfg.subcp, elem->Attribute("value"));
sprintf(XMPlayerCfg.subcp_desc, elem->Attribute("desc"));
} else if (strcmp(elemName, "language") == 0) {
sprintf(XMPlayerCfg.sublang, elem->Attribute("value"));
sprintf(XMPlayerCfg.sublang_desc, elem->Attribute("desc"));
}
}
doc.Clear();
prefLoaded = true;
printf("[Preferences] Sucessfully loaded xmplayer.xml \n");
return true;
} else {
noheader:
DefaultSettings();
printf("[Preferences] Failed to load xmplayer.xml - Loading default settings \n");
return false;
}
}
示例11: readSchoolXml
void readSchoolXml()
{
using namespace std;
const char *xmlFile = "conf/school.xml";
TiXmlDocument doc;
if (!doc.LoadFile(xmlFile))
{
cout << "Load xml file failed.\t" << xmlFile << endl;
return;
}
cout << "Load xml file OK." << endl;
TiXmlDeclaration *decl = doc.FirstChild()->ToDeclaration();
if (!decl)
{
cout << "decl is null.\n" << endl;
return;
}
cout << decl->Encoding();
cout << decl->Version();
cout << decl->Standalone() << endl;
TiXmlHandle docHandle(&doc);
TiXmlElement *child
= docHandle.FirstChild("School").FirstChild("Class").Child("Student", 0).ToElement();
for ( ; child != NULL; child = child->NextSiblingElement())
{
TiXmlAttribute *attr = child->FirstAttribute();
for (; attr != NULL; attr = attr->Next())
{
cout << attr->Name() << " : " << attr->Value() << endl;
}
TiXmlElement *ct = child->FirstChildElement();
for (; ct != NULL; ct = ct->NextSiblingElement())
{
char buf[1024] = {0};
u2g(ct->GetText(), strlen(ct->GetText()), buf, sizeof(buf));
cout << ct->Value() << " : " << buf << endl;
}
cout << "=====================================" << endl;
}
TiXmlElement *schl = doc.RootElement();
const char *value_t =schl->Attribute("name");
char buf[1024] = {0};
if ( u2g(value_t, strlen(value_t), buf, sizeof(buf)) == -1) {
return;
}
cout << "Root Element value: " << buf << endl;
schl->RemoveAttribute("name");
schl->SetValue("NewSchool");
cout << "Save file: " << (doc.SaveFile("conf/new.xml") ? "Ok" : "Failed") << endl;
return ;
TiXmlElement *rootElement = doc.RootElement();
TiXmlElement *classElement = rootElement->FirstChildElement();
TiXmlElement *studentElement = classElement->FirstChildElement();
// N 个 Student 节点
for ( ; studentElement!= NULL; studentElement = studentElement->NextSiblingElement())
{
// 获得student
TiXmlAttribute *stuAttribute = studentElement->FirstAttribute();
for (; stuAttribute != NULL; stuAttribute = stuAttribute->Next())
{
cout << stuAttribute->Name() << " : " << stuAttribute->Value() << endl;
}
// 获得student的第一个联系方式
TiXmlElement *contact = studentElement->FirstChildElement();
for (; contact != NULL; contact = contact->NextSiblingElement())
{
const char *text = contact->GetText();
char buf[1024] = {0};
if ( u2g(text, strlen(text), buf, sizeof(buf)) == -1) {
continue;
}
cout << contact->Value() << " : " << buf << endl;
}
}
}
示例12: LoadScene
int LoadScene(const char *filename)
{
TiXmlDocument doc(filename);
if ( ! doc.LoadFile() ) {
printf("Failed to load the file \"%s\"\n", filename);
return 0;
}
TiXmlElement *xml = doc.FirstChildElement("xml");
if ( ! xml ) {
printf("No \"xml\" tag found.\n");
return 0;
}
TiXmlElement *scene = xml->FirstChildElement("scene");
if ( ! scene ) {
printf("No \"scene\" tag found.\n");
return 0;
}
TiXmlElement *cam = xml->FirstChildElement("camera");
if ( ! cam ) {
printf("No \"camera\" tag found.\n");
return 0;
}
nodeMtlList.clear();
rootNode.Init();
materials.DeleteAll();
lights.DeleteAll();
objList.Clear();
textureList.Clear();
LoadScene( scene );
rootNode.ComputeChildBoundBox();
// Assign materials
int numNodes = nodeMtlList.size();
for ( int i=0; i<numNodes; i++ ) {
Material *mtl = materials.Find( nodeMtlList[i].mtlName );
if ( mtl ) nodeMtlList[i].node->SetMaterial(mtl);
}
nodeMtlList.clear();
// Load Camera
camera.Init();
camera.dir += camera.pos;
TiXmlElement *camChild = cam->FirstChildElement();
while ( camChild ) {
if ( COMPARE( camChild->Value(), "position" ) ) ReadVector(camChild,camera.pos);
else if ( COMPARE( camChild->Value(), "target" ) ) ReadVector(camChild,camera.dir);
else if ( COMPARE( camChild->Value(), "up" ) ) ReadVector(camChild,camera.up);
else if ( COMPARE( camChild->Value(), "fov" ) ) ReadFloat (camChild,camera.fov);
else if ( COMPARE( camChild->Value(), "width" ) ) camChild->QueryIntAttribute("value", &camera.imgWidth);
else if ( COMPARE( camChild->Value(), "height" ) ) camChild->QueryIntAttribute("value", &camera.imgHeight);
camChild = camChild->NextSiblingElement();
}
camera.dir -= camera.pos;
camera.dir.Normalize();
Point3 x = camera.dir ^ camera.up;
camera.up = (x ^ camera.dir).GetNormalized();
renderImage.Init( camera.imgWidth, camera.imgHeight );
return 1;
}
示例13: LoadLight
void LoadLight(TiXmlElement *element)
{
Light *light = NULL;
// name
const char* name = element->Attribute("name");
printf("Light [");
if ( name ) printf("%s",name);
printf("]");
// type
const char* type = element->Attribute("type");
if ( type ) {
if ( COMPARE(type,"ambient") ) {
printf(" - Ambient\n");
AmbientLight *l = new AmbientLight();
light = l;
for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
if ( COMPARE( child->Value(), "intensity" ) ) {
Color c(1,1,1);
ReadColor( child, c );
l->SetIntensity(c);
printf(" intensity %f %f %f\n",c.r,c.g,c.b);
}
}
} else if ( COMPARE(type,"direct") ) {
printf(" - Direct\n");
DirectLight *l = new DirectLight();
light = l;
for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
if ( COMPARE( child->Value(), "intensity" ) ) {
Color c(1,1,1);
ReadColor( child, c );
l->SetIntensity(c);
printf(" intensity %f %f %f\n",c.r,c.g,c.b);
} else if ( COMPARE( child->Value(), "direction" ) ) {
Point3 v(1,1,1);
ReadVector( child, v );
l->SetDirection(v);
printf(" direction %f %f %f\n",v.x,v.y,v.z);
}
}
} else if ( COMPARE(type,"point") ) {
printf(" - Point\n");
PointLight *l = new PointLight();
light = l;
for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
if ( COMPARE( child->Value(), "intensity" ) ) {
Color c(1,1,1);
ReadColor( child, c );
l->SetIntensity(c);
printf(" intensity %f %f %f\n",c.r,c.g,c.b);
} else if ( COMPARE( child->Value(), "position" ) ) {
Point3 v(0,0,0);
ReadVector( child, v );
l->SetPosition(v);
printf(" position %f %f %f\n",v.x,v.y,v.z);
}
}
} else {
printf(" - UNKNOWN\n");
}
}
if ( light ) {
light->SetName(name);
lights.push_back(light);
}
}
示例14: LoadMaterial
void LoadMaterial(TiXmlElement *element)
{
Material *mtl = NULL;
// name
const char* name = element->Attribute("name");
printf("Material [");
if ( name ) printf("%s",name);
printf("]");
// type
const char* type = element->Attribute("type");
if ( type ) {
if ( COMPARE(type,"blinn") ) {
printf(" - Blinn\n");
MtlBlinn *m = new MtlBlinn();
mtl = m;
for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
Color c(1,1,1);
float f=1;
if ( COMPARE( child->Value(), "diffuse" ) ) {
ReadColor( child, c );
m->SetDiffuse(c);
printf(" diffuse %f %f %f\n",c.r,c.g,c.b);
m->SetDiffuseTexture( ReadTexture(child) );
} else if ( COMPARE( child->Value(), "specular" ) ) {
ReadColor( child, c );
m->SetSpecular(c);
printf(" specular %f %f %f\n",c.r,c.g,c.b);
m->SetSpecularTexture( ReadTexture(child) );
} else if ( COMPARE( child->Value(), "glossiness" ) ) {
ReadFloat( child, f );
m->SetGlossiness(f);
printf(" glossiness %f\n",f);
} else if ( COMPARE( child->Value(), "reflection" ) ) {
ReadColor( child, c );
m->SetReflection(c);
printf(" reflection %f %f %f\n",c.r,c.g,c.b);
m->SetReflectionTexture( ReadTexture(child) );
} else if ( COMPARE( child->Value(), "refraction" ) ) {
ReadColor( child, c );
m->SetRefraction(c);
ReadFloat( child, f, "index" );
m->SetRefractionIndex(f);
printf(" refraction %f %f %f (index %f)\n",c.r,c.g,c.b,f);
m->SetRefractionTexture( ReadTexture(child) );
} else if ( COMPARE( child->Value(), "absorption" ) ) {
ReadColor( child, c );
m->SetAbsorption(c);
printf(" absorption %f %f %f\n",c.r,c.g,c.b);
}
}
} else {
printf(" - UNKNOWN\n");
}
}
if ( mtl ) {
mtl->SetName(name);
materials.push_back(mtl);
}
}
示例15: GetSiteByPath
CSiteManagerItemData_Site* CSiteManager::GetSiteByPath(wxString sitePath)
{
wxChar c = sitePath[0];
if (c != '0' && c != '1')
{
wxMessageBox(_("Site path has to begin with 0 or 1."), _("Invalid site path"));
return 0;
}
sitePath = sitePath.Mid(1);
// We have to synchronize access to sitemanager.xml so that multiple processed don't write
// to the same file or one is reading while the other one writes.
CInterProcessMutex mutex(MUTEX_SITEMANAGER);
CXmlFile file;
TiXmlElement* pDocument = 0;
if (c == '0')
pDocument = file.Load(_T("sitemanager"));
else
{
const wxString& defaultsDir = wxGetApp().GetDefaultsDir();
if (defaultsDir == _T(""))
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
wxFileName name(defaultsDir, _T("fzdefaults.xml"));
pDocument = file.Load(name);
}
if (!pDocument)
{
wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR);
return 0;
}
TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
if (!pElement)
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
std::list<wxString> segments;
if (!UnescapeSitePath(sitePath, segments))
{
wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
return 0;
}
TiXmlElement* pChild = GetElementByPath(pElement, segments);
if (!pChild)
{
wxMessageBox(_("Site does not exist."), _("Invalid site path"));
return 0;
}
TiXmlElement* pBookmark;
if (!strcmp(pChild->Value(), "Bookmark"))
{
pBookmark = pChild;
pChild = pChild->Parent()->ToElement();
}
else
pBookmark = 0;
CSiteManagerItemData_Site* data = ReadServerElement(pChild);
if (!data)
{
wxMessageBox(_("Could not read server item."), _("Invalid site path"));
return 0;
}
if (pBookmark)
{
TiXmlHandle handle(pBookmark);
wxString localPath;
CServerPath remotePath;
TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text();
if (localDir)
localPath = ConvLocal(localDir->Value());
TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text();
if (remoteDir)
remotePath.SetSafePath(ConvLocal(remoteDir->Value()));
if (!localPath.empty() && !remotePath.IsEmpty())
{
data->m_sync = GetTextElementBool(pBookmark, "SyncBrowsing", false);
}
else
data->m_sync = false;
data->m_localDir = localPath;
data->m_remoteDir = remotePath;
}
//.........这里部分代码省略.........