bool loadXMLFile (TiXmlDocument &pXMLDoc, std::string XMLFilename, std::map<int, std::string> * pMapXmlStrings, bool isSourceFile) { if (!pXMLDoc.LoadFile(XMLFilename.c_str())) { printf ("%s %s\n", pXMLDoc.ErrorDesc(), XMLFilename.c_str()); return false; } if (isSourceFile) GetEncoding(&pXMLDoc, sourceXMLEncoding); else GetEncoding(&pXMLDoc, foreignXMLEncoding); TiXmlElement* pRootElement = pXMLDoc.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="strings") { printf ("error: No root element called: \"strings\" or no child found in input XML file: %s\n", XMLFilename.c_str()); return false; } if (isSourceFile) GetComment(pRootElement->FirstChild(), -1); const TiXmlElement *pChildElement = pRootElement->FirstChildElement("string"); const char* pAttrId = NULL; const char* pValue = NULL; std::string valueString; int id; while (pChildElement) { pAttrId=pChildElement->Attribute("id"); if (pAttrId && !pChildElement->NoChildren()) { id = atoi(pAttrId); if (pMapXmlStrings->find(id) == pMapXmlStrings->end()) { pValue = pChildElement->FirstChild()->Value(); valueString = EscapeLF(pValue); if (isSourceFile) multimapSourceXmlStrings.insert(std::pair<std::string,int>( valueString,id)); (*pMapXmlStrings)[id] = valueString; if (pChildElement && isSourceFile) GetComment(pChildElement->NextSibling(), id); } } pChildElement = pChildElement->NextSiblingElement("string"); } // Free up the allocated memory for the XML file pXMLDoc.Clear(); return true; }
bool loadAddonXMLFile (std::string AddonXMLFilename) { TiXmlDocument xmlAddonXML; if (!xmlAddonXML.LoadFile(AddonXMLFilename.c_str())) { printf ("%s %s\n", xmlAddonXML.ErrorDesc(), (WorkingDir + "addon.xml").c_str()); return false; } GetEncoding(&xmlAddonXML, addonXMLEncoding); TiXmlElement* pRootElement = xmlAddonXML.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="addon") { printf ("error: No root element called: \"addon\" or no child found in AddonXML file: %s\n", AddonXMLFilename.c_str()); return false; } const char* pMainAttrId = NULL; pMainAttrId=pRootElement->Attribute("id"); if (!pMainAttrId) { printf ("warning: No addon name was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjName = "xbmc-unnamed"; } else ProjName = EscapeLF(pMainAttrId); pMainAttrId=pRootElement->Attribute("version"); if (!pMainAttrId) { printf ("warning: No version name was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjVersion = "rev_unknown"; } else ProjVersion = EscapeLF(pMainAttrId); pMainAttrId=pRootElement->Attribute("name"); if (!pMainAttrId) { printf ("warning: No addon name was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjTextName = "unknown"; } else ProjTextName = EscapeLF(pMainAttrId); pMainAttrId=pRootElement->Attribute("provider-name"); if (!pMainAttrId) { printf ("warning: No addon provider was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjProvider = "unknown"; } else ProjProvider = EscapeLF(pMainAttrId); std::string strAttrToSearch = "xbmc.addon.metadata"; const TiXmlElement *pChildElement = pRootElement->FirstChildElement("extension"); while (pChildElement && strcmp(pChildElement->Attribute("point"), "xbmc.addon.metadata") != 0) pChildElement = pChildElement->NextSiblingElement("extension"); const TiXmlElement *pChildSummElement = pChildElement->FirstChildElement("summary"); while (pChildSummElement && pChildSummElement->FirstChild()) { std::string strLang = pChildSummElement->Attribute("lang"); if (pChildSummElement->FirstChild()) { std::string strValue = EscapeLF(pChildSummElement->FirstChild()->Value()); mapAddonXMLData[strLang].strSummary = strValue; } pChildSummElement = pChildSummElement->NextSiblingElement("summary"); } const TiXmlElement *pChildDescElement = pChildElement->FirstChildElement("description"); while (pChildDescElement && pChildDescElement->FirstChild()) { std::string strLang = pChildDescElement->Attribute("lang"); if (pChildDescElement->FirstChild()) { std::string strValue = EscapeLF(pChildDescElement->FirstChild()->Value()); mapAddonXMLData[strLang].strDescription = strValue; } pChildDescElement = pChildDescElement->NextSiblingElement("description"); } const TiXmlElement *pChildDisclElement = pChildElement->FirstChildElement("disclaimer"); while (pChildDisclElement && pChildDisclElement->FirstChild()) { std::string strLang = pChildDisclElement->Attribute("lang"); if (pChildDisclElement->FirstChild()) { std::string strValue = EscapeLF(pChildDisclElement->FirstChild()->Value()); mapAddonXMLData[strLang].strDisclaimer = strValue; } pChildDisclElement = pChildDisclElement->NextSiblingElement("disclaimer"); } return true; }