//------------------------------------------------------------------------------------- void Config::writeAccountName(const char* name) { if(!useLastAccountName_) return; TiXmlNode* rootNode = NULL; XmlPlus* xml = new XmlPlus(Resmgr::getSingleton().matchRes(fileName_).c_str()); if(!xml->isGood()) { ERROR_MSG(boost::format("Config::writeAccountName: load %1% is failed!\n") % fileName_.c_str()); SAFE_RELEASE(xml); return; } rootNode = xml->getRootNode("accountName"); if(rootNode != NULL) { rootNode->SetValue(name); } xml->getTxdoc()->SaveFile(fileName_.c_str()); SAFE_RELEASE(xml); }
void GD_EXTENSION_API SetText(const std::string &refName, const std::string &text, RuntimeScene &scene) { TiXmlNode *refNode = RefManager::Get(&scene)->GetRef(refName); if(refNode) { refNode->SetValue(text.c_str()); } }
bool writeconf(int hconf,char *option,char *field,char *value ) { TiXmlNode *node = 0; TiXmlElement *rootElement = 0; TiXmlElement *settingElement = 0; TiXmlElement *fieldElement = 0; TiXmlElement *newldElement = 0; TiXmlDocument *pdoc = 0; TiXmlText *pTextValue = 0; TiXmlNode *pTextNode = 0; if(hconf){ pdoc = (TiXmlDocument*)hconf; } else { return false; } node = pdoc->RootElement(); if(!node){ //here we need create a new node node = new TiXmlElement(ROOT_NAME); pdoc->LinkEndChild(node); //root element no exist,the create a new element } if(strcmp(ROOT_NAME,node->Value())){ //delete and create a new one return false; } rootElement = node->ToElement(); //we come to <SNWTool> </SNWTool> element settingElement = rootElement->FirstChildElement(option); if( settingElement) { fieldElement = settingElement->FirstChildElement(field); if(fieldElement){ pTextNode = fieldElement->FirstChild(); if(pTextNode) { pTextNode->SetValue(value); } else { pTextValue = new TiXmlText(value); fieldElement->LinkEndChild(pTextValue); } } else { pTextValue = new TiXmlText(value); fieldElement = new TiXmlElement(field); fieldElement->LinkEndChild(pTextValue); settingElement->LinkEndChild( fieldElement ); } } else { pTextValue = new TiXmlText(value); fieldElement = new TiXmlElement(field); fieldElement->LinkEndChild(pTextValue); settingElement = new TiXmlElement(option); settingElement->LinkEndChild( fieldElement ); rootElement->LinkEndChild( settingElement ); } return true; }
void CGUIIncludes::ResolveParametersForNode(TiXmlElement *node, const Params& params) { if (!node) return; std::string newValue; // run through this element's attributes, resolving any parameters TiXmlAttribute *attribute = node->FirstAttribute(); while (attribute) { ResolveParamsResult result = ResolveParameters(attribute->ValueStr(), newValue, params); if (result == SINGLE_UNDEFINED_PARAM_RESOLVED && strcmp(node->Value(), "param") == 0 && strcmp(attribute->Name(), "value") == 0 && node->Parent() && strcmp(node->Parent()->Value(), "include") == 0) { // special case: passing <param name="someName" value="$PARAM[undefinedParam]" /> to the nested include // this usually happens when trying to forward a missing parameter from the enclosing include to the nested include // problem: since 'undefinedParam' is not defined, it expands to <param name="someName" value="" /> and overrides any default value set with <param name="someName" default="someValue" /> in the nested include // to prevent this, we'll completely remove this parameter from the nested include call so that the default value can be correctly picked up later node->Parent()->RemoveChild(node); return; } else if (result != NO_PARAMS_FOUND) attribute->SetValue(newValue); attribute = attribute->Next(); } // run through this element's value and children, resolving any parameters TiXmlNode *child = node->FirstChild(); if (child) { if (child->Type() == TiXmlNode::TINYXML_TEXT) { ResolveParamsResult result = ResolveParameters(child->ValueStr(), newValue, params); if (result == SINGLE_UNDEFINED_PARAM_RESOLVED && strcmp(node->Value(), "param") == 0 && node->Parent() && strcmp(node->Parent()->Value(), "include") == 0) { // special case: passing <param name="someName">$PARAM[undefinedParam]</param> to the nested include // we'll remove the offending param tag same as above node->Parent()->RemoveChild(node); } else if (result != NO_PARAMS_FOUND) child->SetValue(newValue); } else if (child->Type() == TiXmlNode::TINYXML_ELEMENT) { do { TiXmlElement *next = child->NextSiblingElement(); // save next as current child might be removed from the tree ResolveParametersForNode(static_cast<TiXmlElement *>(child), params); child = next; } while (child); } } }
int tixmldocument_write(lua_State *L) { TiXmlDocument *xmldoc; TiXmlDocument_ud* xmldoc_userdata = (TiXmlDocument_ud *) luaL_checkudata(L, 1, "TiXmlDocument"); xmldoc = xmldoc_userdata->xmldoc; const char *path = luaL_checkstring(L, 2); // path const char *value = luaL_checkstring(L, 3); // new value lua_pop(L, 3); char *attr_name; TiXmlNode *node = find_node(path, xmldoc->RootElement(), &attr_name); if (node) { if (attr_name) { if (node->Type() == TiXmlNode::ELEMENT) { TiXmlElement *elt_node = dynamic_cast<TiXmlElement *>(node); if (elt_node->Attribute(attr_name)) { elt_node->SetAttribute(attr_name, value); delete attr_name; lua_pushboolean(L, 1); return 1; } } luaL_error(L, "invalid attribute: %s", attr_name); delete attr_name; return 0; } else { TiXmlNode *n = node->FirstChild(); if (n) { if (n->Type()==TiXmlNode::TEXT) { n->SetValue(value); } else { return luaL_error(L, "%s does not point to a text node", path); } } else { // create the text child TiXmlText *new_text_node = new TiXmlText(value); // and add it node->LinkEndChild(new_text_node); } } lua_pushboolean(L, 1); return 1; } else { return luaL_error(L, "path not found: %s", path); } }
void CGUIIncludes::ResolveExpressions(TiXmlElement *node) { if (!node) return; TiXmlNode *child = node->FirstChild(); if (child && child->Type() == TiXmlNode::TINYXML_TEXT && m_expressionNodes.count(node->ValueStr())) { child->SetValue(ResolveExpressions(child->ValueStr())); } else { TiXmlAttribute *attribute = node->FirstAttribute(); while (attribute) { if (m_expressionAttributes.count(attribute->Name())) attribute->SetValue(ResolveExpressions(attribute->ValueStr())); attribute = attribute->Next(); } } }
bool CPlayListASX::LoadData(istream& stream) { CLog::Log(LOGNOTICE, "Parsing ASX"); if(stream.peek() == '[') { return LoadAsxIniInfo(stream); } else { CXBMCTinyXML xmlDoc; stream >> xmlDoc; if (xmlDoc.Error()) { CLog::Log(LOGERROR, "Unable to parse ASX info Error: %s", xmlDoc.ErrorDesc()); return false; } TiXmlElement *pRootElement = xmlDoc.RootElement(); // lowercase every element TiXmlNode *pNode = pRootElement; TiXmlNode *pChild = NULL; CStdString value; value = pNode->Value(); value.ToLower(); pNode->SetValue(value); while(pNode) { pChild = pNode->IterateChildren(pChild); if(pChild) { if (pChild->Type() == TiXmlNode::TINYXML_ELEMENT) { value = pChild->Value(); value.ToLower(); pChild->SetValue(value); TiXmlAttribute* pAttr = pChild->ToElement()->FirstAttribute(); while(pAttr) { value = pAttr->Name(); value.ToLower(); pAttr->SetName(value); pAttr = pAttr->Next(); } } pNode = pChild; pChild = NULL; continue; } pChild = pNode; pNode = pNode->Parent(); } CStdString roottitle = ""; TiXmlElement *pElement = pRootElement->FirstChildElement(); while (pElement) { value = pElement->Value(); if (value == "title") { roottitle = pElement->GetText(); } else if (value == "entry") { CStdString title(roottitle); TiXmlElement *pRef = pElement->FirstChildElement("ref"); TiXmlElement *pTitle = pElement->FirstChildElement("title"); if(pTitle) title = pTitle->GetText(); while (pRef) { // multiple references may apear for one entry // duration may exist on this level too value = pRef->Attribute("href"); if (value != "") { if(title.IsEmpty()) title = value; CLog::Log(LOGINFO, "Adding element %s, %s", title.c_str(), value.c_str()); CFileItemPtr newItem(new CFileItem(title)); newItem->SetPath(value); Add(newItem); } pRef = pRef->NextSiblingElement("ref"); } } else if (value == "entryref") { value = pElement->Attribute("href"); if (value != "") { // found an entryref, let's try loading that url auto_ptr<CPlayList> playlist(CPlayListFactory::Create(value)); if (NULL != playlist.get()) if (playlist->Load(value)) Add(*playlist); } } pElement = pElement->NextSiblingElement(); } } return true; }
//修改结点struNote。或返回结点struNode的值 bool CSimpleXml::AccessXmlNode( XMLNODEINFO &struNote, int nType) { int nEnd = 0; if(m_pDoc == NULL || m_pRoot == NULL) { return false; } TiXmlText* pText = NULL; // 一个指向Text的指针 pText = new TiXmlText(struNote.strData.c_str()) ; string strNodeName = struNote.strNodeName; nEnd = strNodeName.find("/"); string strNode = strNodeName.substr(0, nEnd); strNodeName = strNodeName.substr(nEnd + 1, strNodeName.length() - nEnd); TiXmlNode *node = m_pRoot; TiXmlNode *destnode = NULL; while(node) { string strchildnode = node->Value(); if(strNode != strchildnode) { node = node->NextSibling(); continue;//此子结点非我们要的子结点,跳到下一个子结点 } if((strNode == strNodeName) && (strNode == node->Value()))//Node就是我们访问的结点。 { destnode = node->FirstChild(); if(destnode && destnode->Type() == TiXmlNode::TEXT)//是叶子结点,修改为我们的值 { if(nType == QUERY) { struNote.strData = destnode->Value();//查询结点的值 } else { destnode->SetValue(struNote.strData.c_str());//修改为我们的值 } } else if(destnode && destnode->Type() == TiXmlNode::ELEMENT)//不是叶子结点,加上我们的值 { node->InsertBeforeChild(destnode, *pText); } else if(!destnode)//要写的结点原值为空,加上我们的值 { node->InsertEndChild(*pText); } return true; } node = node->FirstChild();//Node不是我们访问的结点,开始遍历Node的子结点 nEnd = strNodeName.find("/"); strNode = strNodeName.substr(0, nEnd); strNodeName = strNodeName.substr(nEnd + 1, strNodeName.length() - nEnd); if(node && (strNode == strNodeName) && (strNode == node->Value()))//Node就是我们访问的结点 { destnode = node->FirstChild(); if(destnode && destnode->Type() == TiXmlNode::TEXT)//是叶子结点,加上我们的值 { if(nType == QUERY) { struNote.strData = destnode->Value();//查询结点的值 } else { destnode->SetValue(struNote.strData.c_str());//修改为我们的值 } } else if(destnode && destnode->Type() == TiXmlNode::ELEMENT)//不是叶子结点,加上我们的值 { node->InsertBeforeChild(destnode, *pText); } else if(!destnode)//要写的结点原值为空,加上我们的值 { node->InsertEndChild(*pText); } return true; } } return false; }