// 加载杂项配置 BOOL LoadMiscConfig(LPCTSTR lpszFileName) { CXmlDocument xmlDoc; CXmlNode xmlNode; BOOL bRet = xmlDoc.Load(lpszFileName); if (!bRet) return FALSE; bRet = xmlDoc.SelectSingleNode(_T("/Misc/FontInfo"), xmlNode); if (bRet) { g_fontInfo.m_strName = xmlNode.GetAttribute(_T("Name")); g_fontInfo.m_nSize = xmlNode.GetAttributeInt(_T("Size")); tstring strColor = xmlNode.GetAttribute(_T("Color")); g_fontInfo.m_clrText = HexStrToRGB(strColor.c_str()); g_fontInfo.m_bBold = xmlNode.GetAttributeInt(_T("Bold")); g_fontInfo.m_bItalic = xmlNode.GetAttributeInt(_T("Italic")); g_fontInfo.m_bUnderLine = xmlNode.GetAttributeInt(_T("UnderLine")); } bRet = xmlDoc.SelectSingleNode(_T("/Misc/HotKey"), xmlNode); if (bRet) { tstring strHotKey = xmlNode.GetText(); g_cHotKey = toupper(strHotKey.at(0)); } xmlNode.Release(); xmlDoc.Release(); return TRUE; }
XmlNode CXmlNode::Append(const CString &strXml) { CXmlDocument doc; if(doc.LoadXml(strXml)) { return Append(doc.GetRoot()); } else return NULL; }
LPSTR CPicture::GetContentXML() { LPSTR pszXML = NULL; CXmlDocument xmlDoc; CXmlElement* pBody = xmlDoc.AddElement(L"body"); CXmlElement* pContent = pBody->AddElement(L"content"); pContent->AddAttribute(L"id", m_contentID); pContent->AddAttribute(L"title", m_pwszFile); CXmlElement* pImage = pContent->AddElement(L"img"); pImage->AddAttribute(L"align", L"c"); pImage->AddAttribute(L"fit", L"screen"); pImage->AddAttribute(L"alt", m_pwszFile); // // The Image ID is the CONTENT_ID of the raw image bytes; // that is the same as this content ID, offset by // (CID_RAWIMAGE_FIRST - CID_XMLIMAGE_FIRST) // pImage->AddAttribute(L"id", m_contentID + (CID_RAWIMAGE_FIRST - CID_XMLIMAGE_FIRST)); CXmlElement* pLeftBtn = pContent->AddElement(L"btn"); pLeftBtn->AddAttribute(L"key", L"left"); pLeftBtn->AddAttribute(L"target", m_prevId); CXmlElement* pRightBtn = pContent->AddElement(L"btn"); pRightBtn->AddAttribute(L"key", L"right"); pRightBtn->AddAttribute(L"target", m_nextId); BSTR bstrXml; xmlDoc.GetXml(&bstrXml); // // The device handles UTF8 encoded strings, so the XML // needs to be converted from unicode to UTF8. // pszXML = AllocTaskUtf8String(bstrXml); ::SysFreeString(bstrXml); delete pBody; delete pContent; delete pImage; delete pLeftBtn; delete pRightBtn; return pszXML; }
//从Xml中读取表情配置 BOOL CFaceList::LoadConfigFile(LPCTSTR lpszFileName) { CXmlDocument xmlDoc; CXmlNode xmlNode, xmlSubNode; Reset(); BOOL bRet = xmlDoc.Load(lpszFileName); if (!bRet) return FALSE; bRet = xmlDoc.SelectSingleNode(_T("/faceconfig"), xmlNode); if (bRet) { m_nItemWidth = xmlNode.GetAttributeInt(_T("item_width")); m_nItemHeight = xmlNode.GetAttributeInt(_T("item_height")); m_nZoomWidth = xmlNode.GetAttributeInt(_T("zoom_width")); m_nZoomHeight = xmlNode.GetAttributeInt(_T("zoom_height")); m_nRow = xmlNode.GetAttributeInt(_T("row")); m_nCol = xmlNode.GetAttributeInt(_T("col")); bRet = xmlNode.GetFirstChildNode(_T("face"), xmlSubNode); while (bRet) { CFaceInfo * lpFaceInfo = new CFaceInfo; if (lpFaceInfo != NULL) { lpFaceInfo->m_nId = xmlSubNode.GetAttributeInt(_T("id")); lpFaceInfo->m_strTip = xmlSubNode.GetAttribute(_T("tip")); lpFaceInfo->m_strFileName = ZYM::CPath::GetCurDir() + xmlSubNode.GetAttribute(_T("file")); tString strIndex = ZYM::CPath::GetFileNameWithoutExtension(lpFaceInfo->m_strFileName.c_str()); if (IsDigit(strIndex.c_str())) lpFaceInfo->m_nIndex = _tcstol(strIndex.c_str(), NULL, 10); m_arrFaceInfo.push_back(lpFaceInfo); } bRet = xmlSubNode.GetNextSiblingNode(_T("face"), xmlSubNode); } } xmlSubNode.Release(); xmlNode.Release(); xmlDoc.Release(); return TRUE; }
int UpdateMonitorApp::start() { CXmlDocument setting; DOMElement * xmlElem = NULL; DOMElement * xmlRoot = NULL; if( setting.load( SETTING_FILE ) != 0 || ( xmlRoot = setting.getRoot() ) == NULL ) { printf( "[Error] Load ServerSetting.xml Failed.\n" ); return -1; } xmlElem = setting.getFirstChild( xmlRoot, "MonitorInterval" ); if( xmlElem == NULL ) { printf( "[Error] Get Monitor Time Interval Failed.\n" ); return -1; } m_nInterval = atoi( setting.getAttribute( xmlElem, "Description" ).c_str() ); xmlElem = setting.getFirstChild( xmlRoot, "LogPath" ); if( xmlElem == NULL ) { printf( "[Error] Get Log Path Failed.\n" ); return -1; } setting.getAttribute( xmlElem, "Description", m_strLogPath ); return 0; }
void CQuotes::Init(const CString& strXml) { try { CXmlDocument doc; doc.LoadXml(strXml); CXmlNodeList secList = doc.Select(_T("/buddy/s")); for (int i = 0; i < secList.GetLength(); i++) { CXmlNode ndSec = secList.GetItem(i); m_strId = ndSec.GetAttribute(_T("code")); m_eMarket = (MarketType)ndSec.GetAttributeLong(_T("market")); QuoteType eType = (QuoteType)ndSec.GetAttributeLong(_T("type")); CXmlNodeList quoteList = ndSec.Select(_T("q")); for (int j = 0; j < quoteList.GetLength(); j++) { Quote quote; CXmlNode ndQuote = quoteList.GetItem(i); CString strDate = ndQuote.GetAttribute(_T("t")); quote.dtTime.ParseDateTime((LPCTSTR)strDate.GetBuffer()); quote.eQuote = eType; quote.dOpen = ndQuote.GetAttributeDouble(_T("o")); quote.dHigh = ndQuote.GetAttributeDouble(_T("h")); quote.dLow = ndQuote.GetAttributeDouble(_T("l")); quote.dClose = ndQuote.GetAttributeDouble(_T("c")); quote.dVolumn = ndQuote.GetAttributeDouble(_T("v")); quote.dAmount = ndQuote.GetAttributeDouble(_T("a")); m_vecQuote.push_back(quote); } } } catch( ... ) { OutputDebugString(_T("parse quote failed.")); } return; }
void CXmlNode::SetAttribute(const CString& attributeName, const _variant_t value) { CXmlNode node; node=m_pNode->attributes->_getNamedItem(_bstr_t(attributeName)); if(node.IsValid()) { node.SetData(value); } else { CXmlDocument myDoc = this->GetOwnerDocument(); if(myDoc.IsValid()) { CXmlNode attr = myDoc.CreateNode(attributeName,nodeAttribute); attr.SetValue(value); XmlNode attrNode; m_pNode->attributes->setNamedItem(attr.GetNode(),&attrNode); } } }
LPSTR CTask::GetContentXML() { LPSTR pszXML = NULL; CXmlDocument xmlDoc; CXmlElement* pBody = xmlDoc.AddElement(L"body"); CXmlElement* pContent = pBody->AddElement(L"content"); pContent->AddAttribute(L"id", GetID()); pContent->AddAttribute(L"title", GetName()); CXmlElement* pCategory = pContent->AddElement(L"txt"); pCategory->AddText(m_wszCategory); CXmlElement* pDetails = pContent->AddElement(L"txt"); pDetails->AddText(m_wszDetails); CXmlElement* pDueTime = pContent->AddElement(L"txt"); pDueTime->AddText(m_wszTimeDue); CXmlElement* pLeftBtn = pContent->AddElement(L"btn"); pLeftBtn->AddAttribute(L"key", L"left"); pLeftBtn->AddAttribute(L"target", m_prevId); CXmlElement* pRightBtn = pContent->AddElement(L"btn"); pRightBtn->AddAttribute(L"key", L"right"); pRightBtn->AddAttribute(L"target", m_nextId); BSTR bstrXml; xmlDoc.GetXml(&bstrXml); printf("Sending Content: \n%ws\n\n", bstrXml); // // The device handles UTF8 encoded strings, so the XML // needs to be converted from unicode to UTF8. // pszXML = AllocTaskUtf8String(bstrXml); ::SysFreeString(bstrXml); return pszXML; }
//-- LoadSettings ------------------------------------------------------------- // //----------------------------------------------------------------------------- void ShadeWorm_c::LoadSettings(const char* name) { XmlNode node; CXmlDocument doc; int colId; int index; int col; // Set up the defaults m_numWorms = 16; m_drawTime = 8; m_numColMaps = 0; m_randomColMap = false; char szXMLFile[1024]; strcpy(szXMLFile, "Q:\\screensavers\\"); strcat(szXMLFile, name); strcat(szXMLFile, ".xml"); // Load the config file if (doc.Load(szXMLFile) >= 0) { node = doc.GetNextNode(XML_ROOT_NODE); while(node > 0) { if (!strcmpi(doc.GetNodeTag(node),"NumWorms")) { m_numWorms = atoi(doc.GetNodeText(node)); Clamp(1, 32, m_numWorms); } else if (!strcmpi(doc.GetNodeTag(node),"DrawTime")) { m_drawTime = atoi(doc.GetNodeText(node)); Clamp(1, 10, m_drawTime); } else if (!strcmpi(doc.GetNodeTag(node),"RandomColMap")) { m_randomColMap = !strcmpi(doc.GetNodeText(node),"true"); } else if (!strcmpi(doc.GetNodeTag(node),"Map")) { node = doc.GetNextNode(node); if (m_numColMaps < MAX_COLMAPS) { colId = 0; m_colMaps[m_numColMaps].m_numCols = 0; m_colMaps[m_numColMaps].m_colMap = new ColMapEntry_t[256]; while (node>0) { if (!strcmpi(doc.GetNodeTag(node),"Col")) { if (colId < 256) { char* txt = doc.GetNodeText(node); sscanf(txt, "%d %x\n", &index, &col); if (index > 255) index = 255; if (index < 0) index = 0; m_colMaps[m_numColMaps].m_colMap[colId].m_index = index; m_colMaps[m_numColMaps].m_colMap[colId].m_col = col; colId++; } } else if (!strcmpi(doc.GetNodeTag(node),"/Map")) { m_colMaps[m_numColMaps].m_numCols = colId; m_numColMaps++; break; } node = doc.GetNextNode(node); } } } node = doc.GetNextNode(node); } doc.Close(); } } // LoadSettings
//-- LoadSettings ------------------------------------------------------------- // //----------------------------------------------------------------------------- void ShadeWorm_c::LoadSettings(const char* name) { int colId; int index; int col; // Set up the defaults m_numWorms = 16; m_drawTime = 8; m_numColMaps = 0; m_randomColMap = false; XmlNode node; CXmlDocument doc; char contentPath[MAX_PATH]; getDreamContentPath((char*)&contentPath); char szXMLFile[MAX_PATH]; sprintf((char*)&szXMLFile, "%s\\%s", contentPath, "Resources\\Config.xml"); // Load the config file if (doc.Load(szXMLFile) >= 0) { node = doc.GetNextNode(XML_ROOT_NODE); while(node > 0) { if (!_strcmpi(doc.GetNodeTag(node),"NumWorms")) { m_numWorms = atoi(doc.GetNodeText(node)); Clamp(1, 32, m_numWorms); } else if (!_strcmpi(doc.GetNodeTag(node),"DrawTime")) { m_drawTime = atoi(doc.GetNodeText(node)); Clamp(1, 10, m_drawTime); } else if (!_strcmpi(doc.GetNodeTag(node),"RandomColMap")) { m_randomColMap = !_strcmpi(doc.GetNodeText(node),"true"); } else if (!_strcmpi(doc.GetNodeTag(node),"Map")) { node = doc.GetNextNode(node); if (m_numColMaps < MAX_COLMAPS) { colId = 0; m_colMaps[m_numColMaps].m_numCols = 0; m_colMaps[m_numColMaps].m_colMap = new ColMapEntry_t[256]; while (node>0) { if (!_strcmpi(doc.GetNodeTag(node),"Col")) { if (colId < 256) { char* txt = doc.GetNodeText(node); sscanf(txt, "%d %x\n", &index, &col); if (index > 255) index = 255; if (index < 0) index = 0; m_colMaps[m_numColMaps].m_colMap[colId].m_index = index; m_colMaps[m_numColMaps].m_colMap[colId].m_col = col; colId++; } } else if (!_strcmpi(doc.GetNodeTag(node),"/Map")) { m_colMaps[m_numColMaps].m_numCols = colId; m_numColMaps++; break; } node = doc.GetNextNode(node); } } } node = doc.GetNextNode(node); } doc.Close(); } } // LoadSettings
CXmlNode::CXmlNode(const CXmlDocument & doc) { m_pNode = doc.GetRoot(); }
// // Name : CGrModelXp::LoadFile() // Description : Load the model from an XML file. // Parameters : filename - Name of the file to load from // Returns : true if successful // If false, an error message is stored in mErrorMessage // bool CGrModelXp::LoadFile(const wchar_t *filename) { // Make a path to where this file is located wstring path(filename); int i; for(i=path.length() - 1; i>=0; i--) { if(path[i] == L'\\' || path[i] == '/') { path = path.substr(0, i + 1); break; } } if(i < 0) path = L""; CXmlDocument xml; if(!xml.OpenXmlDocument(filename, L"model")) return Error(xml.GetErrorMessage()); if(!XmlTestVersion(&xml, xml.GetRootNode())) return Error(L"XMODL file is not the correct version. Version 2.0 required"); Clear(); XmlLoad(&xml, xml.GetRootNode()); // Once we have loaded all of the meshes, we find all of the // necessary textures and load them as well. // Loop over the meshes for(vector<Mesh *>::iterator m=mMeshes.begin(); m!=mMeshes.end(); m++) { Mesh *mesh = *m; // Loop over the effects for(vector<Effect>::iterator e=mEffects.begin(); e!=mEffects.end(); e++) { Effect *effect = &(*e); // Does this effect use a texture? if(!effect->mTextureFile.empty()) { // Do we know it already? std::map<wstring, CGrTexture>::iterator t=mTextures.find(effect->mTextureFile); if(t == mTextures.end()) { // Load the texture mTextures[effect->mTextureFile] = CGrTexture(); effect->mTexture = &mTextures[effect->mTextureFile]; wstring filepath = path + effect->mTextureFile; effect->mTexture->LoadFile(filepath.c_str()); } else { // We have already loaded it effect->mTexture = &t->second; } } } } return true; }
// Load settings from the [screensavername].xml configuration file // the name of the screensaver (filename) is used as the name of // the xml file - this is sent to us by XBMC when the Init func // is called. void LoadSettings() { XmlNode node, childNode; CXmlDocument doc; char szXMLFile[1024]; strcpy(szXMLFile, "Q:\\screensavers\\"); strcat(szXMLFile, m_szScrName); strcat(szXMLFile, ".xml"); OutputDebugString("Loading XML: "); OutputDebugString(szXMLFile); float xmin = -10.0f, xmax = 10.0f, ymin = -10.0f, ymax = 10.0f, height = 0.0f, elasticity = 0.5f, viscosity = 0.05f, tension = 1.0f, blendability = 0.04f; int xdivs = 50; int ydivs = 50; int divs = 50; SetDefaults(); g_lightDir = D3DXVECTOR3(0.0f,0.6f,-0.8f); // Load the config file if (doc.Load(szXMLFile) >= 0) { node = doc.GetNextNode(XML_ROOT_NODE); while(node > 0) { if (strcmpi(doc.GetNodeTag(node),"screensaver")) { node = doc.GetNextNode(node); continue; } if (childNode = doc.GetChildNode(node,"wireframe")) { world.isWireframe = strcmp(doc.GetNodeText(childNode),"true") == 0; } if (childNode = doc.GetChildNode(node,"elasticity")) { elasticity = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"viscosity")) { viscosity = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"tension")) { tension = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"blendability")) { tension = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"xmin")) { xmin = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"xmax")) { xmax = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"ymin")) { ymin = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"ymax")) { ymax = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"lightx")) { g_lightDir.x = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"lighty")) { g_lightDir.y = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"lightz")) { g_lightDir.z = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"shininess")) { g_shininess = (float)atof(doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"texturefolder")) { strcpy(world.szTextureSearchPath, doc.GetNodeText(childNode)); } if (childNode = doc.GetChildNode(node,"texturemode")) { world.isTextureMode = strcmp(doc.GetNodeText(childNode),"true") == 0; } if (childNode = doc.GetChildNode(node,"nexttexture")) { world.nextTextureTime = (int)(30*(float)atof(doc.GetNodeText(childNode))); } if (childNode = doc.GetChildNode(node,"quality")) { divs = atoi(doc.GetNodeText(childNode)); } node = doc.GetNextNode(node); } doc.Close(); } float scaleRatio = (xmax-xmin)/(ymax-ymin); int totalPoints = (int)(divs * divs * scaleRatio); //world.scaleX = 0.5f; xdivs = (int)sqrt(totalPoints * scaleRatio / world.scaleX); ydivs = totalPoints / xdivs; //xdivs = 144; ydivs= 90; world.waterField = new WaterField(xmin, xmax, ymin, ymax, xdivs, ydivs, height, elasticity, viscosity, tension, blendability, world.isTextureMode); }
//////////////////////////////////////////////////////////////////////////// // Load settings from the [screensavername].xml configuration file // the name of the screensaver (filename) is used as the name of // the xml file - this is sent to us by XBMC when the Init func is called. // void CConfig::LoadSettings() { XmlNode node, childNode; //, grandChild; CXmlDocument doc; char szXMLFile[1024]; #ifdef _TEST strcpy(szXMLFile, "MatrixTrails.xml"); #else strcpy(szXMLFile, "Q:\\screensavers\\"); strcat(szXMLFile, gScrName); strcat(szXMLFile, ".xml"); #endif // Load the config file if (doc.Load(szXMLFile) >= 0) { node = doc.GetNextNode(XML_ROOT_NODE); while(node > 0) { if (strcmpi(doc.GetNodeTag(node),"screensaver")) { node = doc.GetNextNode(node); continue; } if (childNode = doc.GetChildNode(node,"CharDelayMin")) m_CharDelayMin = (f32)atof(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"CharDelayMax")) m_CharDelayMax = (f32)atof(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"FadeSpeedMin")) m_FadeSpeedMin = (f32)atof(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"FadeSpeedMax")) m_FadeSpeedMax = (f32)atof(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"NumColumns")) m_NumColumns = atoi(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"NumRows")) m_NumRows = atoi(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"CharCol")) sscanf(doc.GetNodeText(childNode), "%f %f %f", &m_CharCol.r, &m_CharCol.g, &m_CharCol.b); if (childNode = doc.GetChildNode(node,"NumChars")) m_NumChars = atoi(doc.GetNodeText(childNode)); if (childNode = doc.GetChildNode(node,"CharSizeTexX")) m_CharSizeTex.x = (f32)atof(doc.GetNodeText(childNode))/TEXTURESIZE; if (childNode = doc.GetChildNode(node,"CharSizeTexY")) m_CharSizeTex.y = (f32)atof(doc.GetNodeText(childNode))/TEXTURESIZE; node = doc.GetNextNode(node); } doc.Close(); } }