Example #1
0
bool CLastFMDirectory::ParseUserList(CStdString url, CFileItemList &items)
{
  if (!RetrieveList(url))
    return false;

  TiXmlElement* pRootElement = m_xmlDoc.RootElement();

  TiXmlElement* pEntry = pRootElement->FirstChildElement("user");

  while(pEntry)
  {
    const char *name = pEntry->Attribute("username");

    TiXmlNode* count;
    count = pEntry->FirstChild("weight");
    if (!count) count = pEntry->FirstChild("match");

    if (name)
    {
      AddListEntry(name, NULL, (count && count->FirstChild()) ? count->FirstChild()->Value() : NULL, NULL, NULL,
          "lastfm://xbmc/user/" + (CStdString)name + "/", items);
    }

    pEntry = pEntry->NextSiblingElement("user");
  }

  m_xmlDoc.Clear();
  return true;
}
Example #2
0
void CGUIMediaWindow::LoadAdditionalTags(TiXmlElement *root)
{
  CGUIWindow::LoadAdditionalTags(root);
  // configure our view control
  m_viewControl.Reset();
  m_viewControl.SetParentWindow(GetID());
  TiXmlElement *element = root->FirstChildElement("views");
  if (element && element->FirstChild())
  { // format is <views>50,29,51,95</views>
    CStdString allViews = element->FirstChild()->Value();
    CStdStringArray views;
    StringUtils::SplitString(allViews, ",", views);
    for (unsigned int i = 0; i < views.size(); i++)
    {
      int controlID = atol(views[i].c_str());
      CGUIControl *control = (CGUIControl *)GetControl(controlID);
      if (control && control->IsContainer())
        m_viewControl.AddView(control);
    }
  }
  else
  { // backward compatibility
    vector<CGUIControl *> controls;
    GetContainers(controls);
    for (ciControls it = controls.begin(); it != controls.end(); it++)
    {
      CGUIControl *control = *it;
      if (control->GetID() >= CONTROL_VIEW_START && control->GetID() <= CONTROL_VIEW_END)
        m_viewControl.AddView(control);
    }
  }
  m_viewControl.SetViewControlID(CONTROL_BTNVIEWASICONS);
}
Example #3
0
//-----------------------------------------------------
bool ReadXmlFile_unattend(string& szFileName)
{   //读取Xml文件,并遍历
    try
    {
        string fullPath = "D:\\"+szFileName;

        //创建一个XML的文档对象。
        TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str());
        myDocument->LoadFile();
        //获得根元素,即Persons。
        TiXmlElement *RootElement = myDocument->RootElement();
        //输出根元素名称,即输出Persons。
        cout << RootElement->Value() << endl;
        //获得第一个Person节点。
        TiXmlElement *FirstSettings = RootElement->FirstChildElement();
        //获得第一个Person的name节点和age节点和ID属性。
        TiXmlElement *Component = FirstSettings->FirstChildElement();
        TiXmlElement *ComputerName = Component->FirstChildElement();
        //输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。
        cout << Component->FirstChild()->Value() << endl;
        cout << ComputerName->FirstChild()->Value() << endl;

        ComputerName->FirstChild()->SetValue("asdf");

        myDocument->SaveFile(fullPath.c_str());//保存到文件

        cout << ComputerName->FirstChild()->Value() << endl;
    }
    catch (string& e)
    {
        return false;
    }
    return true;
}
Example #4
0
bool ReadXmlFile(std::string& szFileName)
{//读取Xml文件,并遍历
	try
	{
		std::string fullPath = GetAppPath();
		fullPath += "\\";
		fullPath += szFileName;
		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str());
		myDocument->LoadFile();
		//获得根元素,即Persons。
		TiXmlElement *RootElement = myDocument->RootElement();
		//输出根元素名称,即输出Persons。
		std::cout << RootElement->Value() << std::endl;
		//获得第一个Person节点。
		TiXmlElement *FirstPerson = RootElement->FirstChildElement();
		//获得第一个Person的name节点和age节点和ID属性。
		TiXmlElement *NameElement = FirstPerson->FirstChildElement();
		TiXmlElement *AgeElement = NameElement->NextSiblingElement();
		TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
		//输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。
		std::cout << NameElement->FirstChild()->Value() << std::endl;
		std::cout << AgeElement->FirstChild()->Value() << std::endl;
		std::cout << IDAttribute->Value()<< std::endl;
	}
	catch (std::string& e)
	{
		return false;
	}
	return true;
}
Example #5
0
// XML format is of strUrls is:
// <TAG><url>...</url>...</TAG> (parsed by ParseElement) or <url>...</url> (ditto)
bool CScraperUrl::ParseEpisodeGuide(CStdString strUrls)
{
  if (strUrls.IsEmpty())
    return false;

  // ok, now parse the xml file
  if (!XMLUtils::HasUTF8Declaration(strUrls))
    g_charsetConverter.unknownToUTF8(strUrls);

  TiXmlDocument doc;
  doc.Parse(strUrls.c_str(),0,TIXML_ENCODING_UTF8);
  if (doc.RootElement())
  {
    TiXmlHandle docHandle( &doc );
    TiXmlElement *link = docHandle.FirstChild("episodeguide").Element();
    if (link->FirstChildElement("url"))
    {
      for (link = link->FirstChildElement("url"); link; link = link->NextSiblingElement("url"))
        ParseElement(link);
    }
    else if (link->FirstChild() && link->FirstChild()->Value())
      ParseElement(link);
  }
  else
    return false;

  return true;
}
Example #6
0
// XML format is of strUrls is:
// <TAG><url>...</url>...</TAG> (parsed by ParseElement) or <url>...</url> (ditto)
bool CScraperUrl::ParseEpisodeGuide(CStdString strUrls)
{
  if (strUrls.empty())
    return false;

  // ok, now parse the xml file
  CXBMCTinyXML doc;
  /* strUrls is coming from internal sources so strUrls is always in UTF-8 */
  doc.Parse(strUrls, TIXML_ENCODING_UTF8);
  if (doc.RootElement())
  {
    TiXmlHandle docHandle( &doc );
    TiXmlElement *link = docHandle.FirstChild("episodeguide").Element();
    if (link->FirstChildElement("url"))
    {
      for (link = link->FirstChildElement("url"); link; link = link->NextSiblingElement("url"))
        ParseElement(link);
    }
    else if (link->FirstChild() && link->FirstChild()->Value())
      ParseElement(link);
  }
  else
    return false;

  return true;
}
Example #7
0
void CIRTranslator::MapRemote(TiXmlNode *pRemote, const std::string &szDevice)
{
  CLog::Log(LOGINFO, "* Adding remote mapping for device '%s'", szDevice.c_str());

  std::vector<std::string> remoteNames;

  auto it = m_irRemotesMap.find(szDevice);
  if (it == m_irRemotesMap.end())
    m_irRemotesMap[szDevice].reset(new IRButtonMap);

  std::shared_ptr<IRButtonMap>& buttons = m_irRemotesMap[szDevice];

  TiXmlElement *pButton = pRemote->FirstChildElement();
  while (pButton != nullptr)
  {
    if (!pButton->NoChildren())
    {
      if (pButton->ValueStr() == "altname")
        remoteNames.push_back(pButton->FirstChild()->ValueStr());
      else
        (*buttons)[pButton->FirstChild()->ValueStr()] = pButton->ValueStr();
    }
    pButton = pButton->NextSiblingElement();
  }

  for (const auto& remoteName : remoteNames)
  {
    CLog::Log(LOGINFO, "* Linking remote mapping for '%s' to '%s'", szDevice.c_str(), remoteName.c_str());
    m_irRemotesMap[remoteName] = buttons;
  }
}
void HelloWorld::parseTinyXmlFile()
{
	try
	{
		char filePath[1024]= {'\0'};
		memset(filePath,0,sizeof(filePath));
		strcat(filePath,CCFileUtils::sharedFileUtils()->getWriteablePath().c_str());
		strcat(filePath,"CreatedTinyXml.xml");

		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument(filePath);
		myDocument->LoadFile();
		//获得根元素,即Persons。
		TiXmlElement *RootElement = myDocument->RootElement();
		//输出根元素名称,即输出Persons。
		CCLOG(RootElement->Value());
		//获得第一个Person节点。
		TiXmlElement *FirstPerson = RootElement->FirstChildElement();
		//获得第一个Person的name节点和age节点和ID属性。
		TiXmlElement *NameElement = FirstPerson->FirstChildElement();
		TiXmlElement *AgeElement = NameElement->NextSiblingElement();
		TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
		//输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。

		CCLOG(NameElement->FirstChild()->Value());
		CCLOG(AgeElement->FirstChild()->Value());
		CCLOG(IDAttribute->Value());
	}
	catch (string& e)
	{
		return ;
	}
	return ;
}
void ComponentOptionMust::setComponents(TiXmlHandle docMUSTHandle, string nameOption, string tradeId)
{

	TiXmlElement *Component;
	TiXmlElement *elem;

	TiXmlElement *Trade = docMUSTHandle.FirstChild("BODY").FirstChild("TRADELIST").FirstChild("MUST_TR").ToElement();

	while (Trade)
	{
		if (strcmp(Trade->FirstChild("TradeId")->ToElement()->GetText(), tradeId.c_str()) == 0)
		{
			Component = Trade->FirstChild("MPTradeData")->FirstChild("MPTRDATA")->FirstChild("MPTrDataXML")->FirstChild("MPTRDATAXML")->FirstChild("STRUCTURED_INSTRUMENT")->
				FirstChild("COMPONENT_LIST")->FirstChild("COMPONENT_OPTION")->ToElement();
			while (Component)
			{
				if (strcmp(Component->Value(), "COMPONENT_OPTION") == 0)
				{

					if (strcmp(Component->FirstChild("NAME")->ToElement()->GetText(), nameOption.c_str()) == 0)
					{
						payOrSell = Component->FirstChild("PORS")->ToElement()->GetText();
						freqString = Component->FirstChild("EXPIRY_SCHED")->FirstChild("BASIC_SCHED")->FirstChild("SCHED_DEF")->FirstChild("FREQ")->ToElement()->GetText();
						settlementType = Component->FirstChild("EXPIRY_SCHED")->FirstChild("ACTUAL_SETTLE_MODE")->ToElement()->GetText();

						//firstExpiry = Component->FirstChild("EXPIRY_SCHED")->FirstChild("BASIC_SCHED")->FirstChild("START_DATE")->FirstChild("DATE_FORMULA")->FirstChild("TARGET")->FirstChild("ATTRIBUTE")->ToElement()->GetText();
						//lastExpiry = Component->FirstChild("EXPIRY_SCHED")->FirstChild("BASIC_SCHED")->FirstChild("END_DATE")->FirstChild("DATE_FORMULA")->FirstChild("TARGET")->FirstChild("ATTRIBUTE")->ToElement()->GetText();

					}
				}
				break;
				Component = Component->NextSiblingElement();
			}

			//****** recherche du type de l'option

			elem = Trade->FirstChild("MPTradeData")->FirstChild("MPTRDATA")->FirstChild("MPTrDataXML")->FirstChild("MPTRDATAXML")->FirstChild("STRUCTURED_INSTRUMENT")->
				FirstChild("VARIABLE_LIST")->FirstChild("VARIABLE")->ToElement();

			while (elem)
			{
				if (strcmp(elem->Value(), "VARIABLE") == 0)
				{

					if (strcmp(elem->FirstChild("NAME")->ToElement()->GetText(), "OptionStyle") == 0)
					{
						typeOption = elem->FirstChild("FORMULA")->FirstChild("FORMULA_STRING")->ToElement()->GetText();
					}
					break;
				}
				elem = elem->NextSiblingElement();
			}

			break;
		}
		Trade = Trade->NextSiblingElement();
	}

}
Example #10
0
bool GetTextElementBool(TiXmlElement* node, const char* name, bool defValue /*=false*/)
{
	wxASSERT(node);

	TiXmlElement* element = node->FirstChildElement(name);
	if (!element)
		return defValue;

	TiXmlNode* textNode = element->FirstChild();
	if (!textNode || !textNode->ToText())
		return defValue;

	const char* str = textNode->Value();
	if (!str)
		return defValue;
	
	switch (str[0])
	{
	case '0':
		return false;
	case '1':
		return true;
	default:
		return defValue;
	}
}
Example #11
0
wxLongLong GetTextElementLongLong(TiXmlElement* node, const char* name, int defValue /*=0*/)
{
	wxASSERT(node);

	TiXmlElement* element = node->FirstChildElement(name);
	if (!element)
		return defValue;

	TiXmlNode* textNode = element->FirstChild();
	if (!textNode || !textNode->ToText())
		return defValue;

	const char* str = textNode->Value();
	const char* p = str;

	wxLongLong value = 0;
	bool negative = false;
	if (*p == '-')
	{
		negative = true;
		p++;
	}
	while (*p)
	{
		if (*p < '0' || *p > '9')
			return defValue;

		value *= 10;
		value += *p - '0';

		p++;
	}

	return negative ? -value : value;
}
Example #12
0
  const char *getDefaultImage(char* cControlType, char* cTextureType)
  {
    // create an xml block so that we can resolve our defaults
    // <control type="type">
    //   <description />
    // </control>
    TiXmlElement control("control");
    control.SetAttribute("type", cControlType);
    TiXmlElement filler("description");
    control.InsertEndChild(filler);
    g_SkinInfo->ResolveIncludes(&control);

    // ok, now check for our texture type
    TiXmlElement *pTexture = control.FirstChildElement(cTextureType);
    if (pTexture)
    {
      // found our textureType
      TiXmlNode *pNode = pTexture->FirstChild();
      if (pNode && pNode->Value()[0] != '-')
      {
        strncpy(defaultImage, pNode->Value(), sizeof(defaultImage));
        defaultImage[sizeof(defaultImage) - 1] = '\0';
        return defaultImage;
      }
    }
    return "";
  }
Example #13
0
bool ETHScene::ReadFromXMLFile(TiXmlElement *pRoot)
{
	m_sceneProps.ReadFromXMLFile(pRoot);
	TiXmlNode *pNode = pRoot->FirstChild(GS_L("EntitiesInScene"));
	if (pNode)
	{
		TiXmlElement *pEntities = pNode->ToElement();
		if (pEntities)
		{
			pNode = pEntities->FirstChild(GS_L("Entity"));
			if (pNode)
			{
				TiXmlElement *pEntityIter = pNode->ToElement();
				if (pEntityIter)
				{
					do
					{
						ETHRenderEntity* entity = new ETHRenderEntity(pEntityIter, m_provider);
						AddEntity(entity);
						pEntityIter = pEntityIter->NextSiblingElement();
					} while (pEntityIter);
				}
			}
		}
	}
	m_provider->GetShaderManager()->SetParallaxIntensity(m_sceneProps.parallaxIntensity);
	return true;
}
Example #14
0
std::string CInitializer::GetSettingFromFile(std::string file, const std::string& name)
{
	TiXmlDocument xmldoc;
	if (!xmldoc.LoadFile(file.c_str()))
		return "";

	TiXmlElement* main = xmldoc.FirstChildElement("FileZilla3");
	if (!main)
		return "";

	TiXmlElement* settings = main->FirstChildElement("Settings");
	if (!settings)
		return "";

	for (TiXmlElement* setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting"))
	{
		const char* nodeVal = setting->Attribute("name");
		if (!nodeVal || strcmp(nodeVal, name.c_str()))
			continue;

		TiXmlNode* textNode = setting->FirstChild();
		if (!textNode || !textNode->ToText())
			continue;

		return mkstr(textNode->Value());
	}

	return "";
}
bool CNfoFile::DoScrape(ScraperPtr& scraper)
{
    vector<CStdString> extras;
    extras.push_back(m_doc);

    CScraperUrl url;
    CFileCurl http;
    vector<CStdString> xml;
    if (scraper->GetParser().HasFunction("NfoUrl"))
        xml = scraper->Run("NfoUrl",url,http,&extras);

    for (vector<CStdString>::iterator it  = xml.begin();
            it != xml.end(); ++it)
    {
        TiXmlDocument doc;
        doc.Parse(it->c_str());

        if (doc.RootElement())
        {
            if (stricmp(doc.RootElement()->Value(),"error")==0)
            {
                CIMDB::ShowErrorDialog(doc.RootElement());
                return false;
            }

            TiXmlElement* pId = doc.FirstChildElement("id");
            if (pId && pId->FirstChild())
                m_strImDbNr = pId->FirstChild()->Value();

            TiXmlElement* url = doc.FirstChildElement("url");
            if (url)
            {
                stringstream str;
                str << *url;
                m_strImDbUrl = str.str();
                SetScraperInfo(scraper);
            }
            else if (strcmp(doc.RootElement()->Value(),"url")==0)
            {
                SetScraperInfo(scraper);
                m_strImDbUrl = *it;
            }
        }
    }
    return true;
}
Example #16
0
void  ModRulesCards::parse(TiXmlElement* element)
{
    TiXmlNode* node = element->FirstChild("general");
    if (node) {
        TiXmlElement* generalElement = node->ToElement();
        TiXmlNode* nodeActivation = generalElement->FirstChild("activate");
        if (nodeActivation) {
            TiXmlElement* activateElement = nodeActivation->ToElement();
            TiXmlNode* nodeUIEvent = activateElement->FirstChild("uiEvent");
            if (nodeUIEvent) {
                const char* event = nodeUIEvent->ToElement()->GetText();
                SAFE_DELETE(activateEffect);
                activateEffect = parseEffect(event);
            }
        }
    }

}
Example #17
0
void CSkinInfo::SettingOptionsSkinFontsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current)
{
  std::string strPath = g_SkinInfo->GetSkinPath("Font.xml");

  CXBMCTinyXML xmlDoc;
  if (!xmlDoc.LoadFile(strPath))
  {
    CLog::Log(LOGERROR, "FillInSkinFonts: Couldn't load %s", strPath.c_str());
    return;
  }

  TiXmlElement* pRootElement = xmlDoc.RootElement();

  std::string strValue = pRootElement->ValueStr();
  if (strValue != "fonts")
  {
    CLog::Log(LOGERROR, "FillInSkinFonts: file %s doesn't start with <fonts>", strPath.c_str());
    return;
  }

  const TiXmlNode *pChild = pRootElement->FirstChild();
  strValue = pChild->ValueStr();
  if (strValue == "fontset")
  {
    while (pChild)
    {
      strValue = pChild->ValueStr();
      if (strValue == "fontset")
      {
        const char* idAttr = ((TiXmlElement*) pChild)->Attribute("id");
        const char* idLocAttr = ((TiXmlElement*) pChild)->Attribute("idloc");
        const char* unicodeAttr = ((TiXmlElement*) pChild)->Attribute("unicode");

        bool isUnicode = (unicodeAttr && stricmp(unicodeAttr, "true") == 0);

        bool isAllowed = true;
        if (g_langInfo.ForceUnicodeFont() && !isUnicode)
          isAllowed = false;

        if (idAttr != NULL && isAllowed)
        {
          if (idLocAttr)
            list.push_back(make_pair(g_localizeStrings.Get(atoi(idLocAttr)), idAttr));
          else
            list.push_back(make_pair(idAttr, idAttr));
        }
      }

      pChild = pChild->NextSibling();
    }
  }
  else
  {
    // Since no fontset is defined, there is no selection of a fontset, so disable the component
    list.push_back(make_pair(g_localizeStrings.Get(13278), ""));
  }
}
Example #18
0
static bool LoadFromFile(const std::string& strPath, CFileItemList& items)
{
  CXBMCTinyXML doc;
  if (!doc.LoadFile(strPath))
  {
    CLog::Log(LOGERROR, "Unable to load %s (row %i column %i)", strPath.c_str(), doc.Row(), doc.Column());
    return false;
  }
  TiXmlElement *root = doc.RootElement();
  if (!root || strcmp(root->Value(), "favourites"))
  {
    CLog::Log(LOGERROR, "Favourites.xml doesn't contain the <favourites> root element");
    return false;
  }

  TiXmlElement *favourite = root->FirstChildElement("favourite");
  while (favourite)
  {
    // format:
    // <favourite name="Cool Video" thumb="foo.jpg">PlayMedia(c:\videos\cool_video.avi)</favourite>
    // <favourite name="My Album" thumb="bar.tbn">ActivateWindow(MyMusic,c:\music\my album)</favourite>
    // <favourite name="Apple Movie Trailers" thumb="path_to_thumb.png">RunScript(special://xbmc/scripts/apple movie trailers/default.py)</favourite>
    const char *name = favourite->Attribute("name");
    const char *thumb = favourite->Attribute("thumb");
    if (name && favourite->FirstChild())
    {
      CURL url;
      url.SetProtocol("favourites");
      url.SetHostName(CURL::Encode(favourite->FirstChild()->Value()));
      const std::string favURL(url.Get());
      if (!items.Contains(favURL))
      {
        const CFileItemPtr item(std::make_shared<CFileItem>(name));
        item->SetPath(favURL);
        if (thumb)
          item->SetArt("thumb", thumb);
        items.Add(item);
      }
    }
    favourite = favourite->NextSiblingElement("favourite");
  }
  return true;
}
//Initialize
void ExampleObject::initialize(TiXmlElement* element)
{
	Object::initialize(element);

	int value;
	TiXmlElement* valueElement = element->FirstChildElement("value");
	if(valueElement) value = Utils::convertStringToInt(valueElement->FirstChild()->Value());

	this->initialize(value);
}
Example #20
0
bool CRssReader::Parse(int iFeed)
{
    TiXmlElement* rootXmlNode = m_xml.RootElement();

    if (!rootXmlNode)
        return false;

    TiXmlElement* rssXmlNode = NULL;

    std::string strValue = rootXmlNode->ValueStr();
    if (strValue.find("rss") != std::string::npos ||
            strValue.find("rdf") != std::string::npos)
        rssXmlNode = rootXmlNode;
    else
    {
        // Unable to find root <rss> or <rdf> node
        return false;
    }

    TiXmlElement* channelXmlNode = rssXmlNode->FirstChildElement("channel");
    if (channelXmlNode)
    {
        TiXmlElement* titleNode = channelXmlNode->FirstChildElement("title");
        if (titleNode && !titleNode->NoChildren())
        {
            std::string strChannel = titleNode->FirstChild()->Value();
            std::wstring strChannelUnicode;
            g_charsetConverter.utf8ToW(strChannel, strChannelUnicode, m_rtlText);
            AddString(strChannelUnicode, RSS_COLOR_CHANNEL, iFeed);

            AddString(L":", RSS_COLOR_CHANNEL, iFeed);
            AddString(L" ", RSS_COLOR_CHANNEL, iFeed);
        }

        GetNewsItems(channelXmlNode,iFeed);
    }

    GetNewsItems(rssXmlNode,iFeed);

    // avoid trailing ' - '
    if (m_strFeed[iFeed].size() > 3 && m_strFeed[iFeed].substr(m_strFeed[iFeed].size() - 3) == L" - ")
    {
        if (m_rtlText)
        {
            m_strFeed[iFeed].erase(0, 3);
            m_strColors[iFeed].erase(0, 3);
        }
        else
        {
            m_strFeed[iFeed].erase(m_strFeed[iFeed].length() - 3);
            m_strColors[iFeed].erase(m_strColors[iFeed].length() - 3);
        }
    }
    return true;
}
Example #21
0
const char* SimXMLDocument::readComment( S32 index )
{
   // Clear the current attribute pointer
   m_CurrentAttribute = 0;

   // Push the first element found under the current element of the given name
   if(!m_paNode.empty())
   {
      const int iLastElement = m_paNode.size() - 1;
      TiXmlElement* pNode = m_paNode[iLastElement];
      if(!pNode)
      {
         return "";
      }
      TiXmlNode* node = pNode->FirstChild();
      for( S32 i = 0; i < index; i++ )
      {
         if( !node )
            return "";

         node = node->NextSiblingElement();
      }

      if( node )
      {
         TiXmlComment* comment = node->ToComment();
         if( comment )
            return comment->Value();
      }
   }
   else
   {
      if(!m_qDocument)
      {
         return "";
      }
      TiXmlNode* node = m_qDocument->FirstChild();
      for( S32 i = 0; i < index; i++ )
      {
         if( !node )
            return "";

         node = node->NextSibling();
      }

      if( node )
      {
         TiXmlComment* comment = node->ToComment();
         if( comment )
            return comment->Value();
      }
   }
   return "";
}
Example #22
0
bool CLastFMDirectory::ParseTagList(CStdString url, CFileItemList &items)
{
  if (!RetrieveList(url))
    return false;

  TiXmlElement* pRootElement = m_xmlDoc.RootElement();

  TiXmlElement* pEntry = pRootElement->FirstChildElement("tag");

  while(pEntry)
  {
    TiXmlNode* name = pEntry->FirstChild("name");
    TiXmlNode* count;
    const char *countstr = NULL;
    const char *namestr = NULL;

    count = pEntry->FirstChild("count");
    if (!count) count = pEntry->FirstChild("playcount");
    if (!count) count = pEntry->FirstChild("match");
    if (!count && pEntry->Attribute("count"))
      countstr = pEntry->Attribute("count");
    else if (count && count->FirstChild())
      countstr = count->FirstChild()->Value();

    if (name && name->FirstChild())
      namestr = name->FirstChild()->Value();
    else
      namestr = pEntry->Attribute("name");

    if (namestr && countstr)
    {
      AddListEntry(namestr, NULL, countstr, NULL, NULL,
          "lastfm://xbmc/tag/" + (CStdString)namestr + "/", items);
    }

    pEntry = pEntry->NextSiblingElement("tag");
  }

  m_xmlDoc.Clear();
  return true;
}
Example #23
0
static bool ReadDeviceCertificate(const CStdString& deviceCertificate, AppInfo* appInfo)
{
  TiXmlDocument xmlDoc;

  if(!xmlDoc.LoadFile(deviceCertificate))
  {
    CLog::Log(LOGERROR, "CAppSecurity::%s - Failed to load %s", __func__, deviceCertificate.c_str());
    return false;
  }

  TiXmlElement* root = xmlDoc.RootElement();
  if(!root)
  {
    CLog::Log(LOGERROR,"CAppSecurity::%s - Failed to get root from BXXMLDocument of %s", __func__, deviceCertificate.c_str());
    return false;
  }

  CStdString type, serial, mac;
  while (root)
  {
    if(strcmp(root->Value(),"device") == 0)
    {
      type = root->Attribute("type");
      serial = root->Attribute("sn");
      mac = root->Attribute("mac");

      root = root->FirstChildElement();
      continue;
    }
    else if(strcmp(root->Value(),"signature") == 0)
    {
      appInfo->signature = root->FirstChild()->Value();
    }

    root = root->NextSiblingElement();
  }  

  bool bVerified = false;
  do
  {
     if(appInfo->signature.IsEmpty())
     {
       CLog::Log(LOGERROR,"CAppSecurity::%s - Device signature is empty", __func__);
       break;
     }

    bVerified = true;

  } while(false);

  return bVerified;
}
Example #24
0
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;
}
Example #25
0
wxString GetTextElement(TiXmlElement* node, const char* name)
{
	wxASSERT(node);

	TiXmlElement* element = node->FirstChildElement(name);
	if (!element)
		return _T("");

	TiXmlNode* textNode = element->FirstChild();
	if (!textNode || !textNode->ToText())
		return _T("");

	return ConvLocal(textNode->Value());
}
Example #26
0
void CXRandR::LoadCustomModeLinesToAllOutputs(void)
{
    Query();
    TiXmlDocument xmlDoc;

    if (!xmlDoc.LoadFile("special://xbmc/userdata/ModeLines.xml"))
    {
        return;
    }

    TiXmlElement *pRootElement = xmlDoc.RootElement();
    if (strcasecmp(pRootElement->Value(), "modelines") != 0)
    {
        // TODO ERROR
        return;
    }

    char cmd[255];
    CStdString name;
    CStdString strModeLine;

    for (TiXmlElement* modeline = pRootElement->FirstChildElement("modeline"); modeline; modeline = modeline->NextSiblingElement("modeline"))
    {
        name = modeline->Attribute("label");
        name.TrimLeft(" \n\t\r");
        name.TrimRight(" \n\t\r");
        strModeLine = modeline->FirstChild()->Value();
        strModeLine.TrimLeft(" \n\t\r");
        strModeLine.TrimRight(" \n\t\r");
        if (getenv("XBMC_BIN_HOME"))
        {
            snprintf(cmd, sizeof(cmd), "%s/xbmc-xrandr --newmode \"%s\" %s > /dev/null 2>&1", getenv("XBMC_BIN_HOME"),
                     name.c_str(), strModeLine.c_str());
            if (system(cmd) != 0)
                CLog::Log(LOGERROR, "Unable to create modeline \"%s\"", name.c_str());
        }

        for (unsigned int i = 0; i < m_outputs.size(); i++)
        {
            if (getenv("XBMC_BIN_HOME"))
            {
                snprintf(cmd, sizeof(cmd), "%s/xbmc-xrandr --addmode %s \"%s\"  > /dev/null 2>&1", getenv("XBMC_BIN_HOME"),
                         m_outputs[i].name.c_str(), name.c_str());
                if (system(cmd) != 0)
                    CLog::Log(LOGERROR, "Unable to add modeline \"%s\"", name.c_str());
            }
        }
    }
}
Example #27
0
bool CMediaManager::LoadSources()
{
    // clear our location list
    m_locations.clear();

    // load xml file...
    CXBMCTinyXML xmlDoc;
    if ( !xmlDoc.LoadFile( MEDIA_SOURCES_XML ) )
        return false;

    TiXmlElement* pRootElement = xmlDoc.RootElement();
    if ( !pRootElement || strcmpi(pRootElement->Value(), "mediasources") != 0)
    {
        CLog::Log(LOGERROR, "Error loading %s, Line %d (%s)", MEDIA_SOURCES_XML, xmlDoc.ErrorRow(), xmlDoc.ErrorDesc());
        return false;
    }

    // load the <network> block
    TiXmlNode *pNetwork = pRootElement->FirstChild("network");
    if (pNetwork)
    {
        TiXmlElement *pLocation = pNetwork->FirstChildElement("location");
        while (pLocation)
        {
            CNetworkLocation location;
            pLocation->Attribute("id", &location.id);
            if (pLocation->FirstChild())
            {
                location.path = pLocation->FirstChild()->Value();
                m_locations.push_back(location);
            }
            pLocation = pLocation->NextSiblingElement("location");
        }
    }
    return true;
}
void NewGameDialog::showCampaign(const std::string& file)
{
	TiXmlDocument xmldata;
	if (xmldata.PHYSFS_LoadFile(file))
			if (xmldata.RootElement()->ValueStr() == "mission")
			{
				TiXmlElement* element = xmldata.RootElement()->FirstChildElement("info");
				if (element)
				{
					element = element->FirstChildElement("description");
					if (element)
						m_missionViewer->setText(element->FirstChild()->ValueStr());
				}
			}
}
Example #29
0
void SimXMLDocument::removeText()
{
   if(m_paNode.empty())
      return;

   const int iFinalElement = m_paNode.size() - 1;
   TiXmlElement* pNode = m_paNode[iFinalElement];
   if(!pNode)
      return;

   TiXmlText* text = pNode->FirstChild()->ToText();
   if( !text )
      return;

   pNode->RemoveChild(text);
}
Example #30
0
void File::parse(){

	// Make sure we can parse the file
	TiXmlDocument doc(simFile);
	if(!doc.LoadFile()){
		string exp_str = "Invalid simulation file: ";
		exp_str += simFile;

		throw(Exception(exp_str));
	}

	// Get root node and check
	TiXmlHandle hDoc = TiXmlHandle(&doc);
	TiXmlElement *pParent = hDoc.FirstChild("simulation").ToElement();
	if(!pParent) throw(Exception("Invalid root"));
	pParent->QueryIntAttribute("runs",&numRuns);
	pParent->QueryIntAttribute("seed",&seed);

	TiXmlNode* pChild;
	for(pChild = pParent->FirstChild(); pChild!=NULL; pChild = pChild->NextSibling()){

		// Ignore comments
		if(pChild->Type() == TiXmlNode::TINYXML_COMMENT){
			continue;
		}

		// Devicelist
		if(strcmp(pChild->Value(),"devicelist") == 0){
			parseDevices(pChild);
		}

		// Strategylist
		else if(strcmp(pChild->Value(),"strategylist") == 0){
			parseStrategies(pChild);
		}

		// Targetlist
		else if(strcmp(pChild->Value(),"targetlist") == 0){
			parseTargets(pChild);
		}

		// Outputlist
		else if(strcmp(pChild->Value(),"outputlist") == 0){
			parseOutputs(pChild);
		}
	}
}