TiXmlAttribute* TiXmlAttributeSet::FindOrCreate( const char* _name ) { TiXmlAttribute* attrib = Find( _name ); if ( !attrib ) { attrib = new TiXmlAttribute(); Add( attrib ); attrib->SetName( _name ); } return attrib; }
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; }