示例#1
0
CString GetXmlValue(MSXML::IXMLDOMNodeListPtr pNodeList, char* key, int pos)
{
	try{
		if(pNodeList==NULL)
			return "";
		MSXML::IXMLDOMNodePtr pSubNode;
		pSubNode = pNodeList->item[pos]->selectSingleNode(key);
		if(pSubNode==NULL)
			return "";
		_bstr_t strRequestType = pSubNode->Gettext();
		CString res;
		res.Format("%s",(char*)strRequestType);
		pSubNode.Release();
		return res;
	}
	catch(_com_error &e){
#ifdef _DEBUG
		AfxMessageBox(e.ErrorMessage());
#endif
		return "";
	}
}
示例#2
0
bool NZBFile::ParseNZB(IUnknown* nzb)
{
	MSXML::IXMLDOMDocumentPtr doc = nzb;
	MSXML::IXMLDOMNodePtr root = doc->documentElement;

	MSXML::IXMLDOMNodePtr node = root->selectSingleNode("/nzb/head/meta[@type='password']");
	if (node)
	{
		_bstr_t password(node->Gettext());
		m_szPassword = strdup(password);
	}

	MSXML::IXMLDOMNodeListPtr fileList = root->selectNodes("/nzb/file");
	for (int i = 0; i < fileList->Getlength(); i++)
	{
		node = fileList->Getitem(i);
		MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("subject");
		if (!attribute) return false;
		_bstr_t subject(attribute->Gettext());
        FileInfo* pFileInfo = new FileInfo();
		pFileInfo->SetSubject(subject);

		attribute = node->Getattributes()->getNamedItem("date");
		if (attribute)
		{
			_bstr_t date(attribute->Gettext());
			pFileInfo->SetTime(atoi(date));
		}

		MSXML::IXMLDOMNodeListPtr groupList = node->selectNodes("groups/group");
		for (int g = 0; g < groupList->Getlength(); g++)
		{
			MSXML::IXMLDOMNodePtr node = groupList->Getitem(g);
			_bstr_t group = node->Gettext();
			pFileInfo->GetGroups()->push_back(strdup((const char*)group));
		}

		MSXML::IXMLDOMNodeListPtr segmentList = node->selectNodes("segments/segment");
		for (int g = 0; g < segmentList->Getlength(); g++)
		{
			MSXML::IXMLDOMNodePtr node = segmentList->Getitem(g);
			_bstr_t id = node->Gettext();
            char szId[2048];
            snprintf(szId, 2048, "<%s>", (const char*)id);

			MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("number");
			if (!attribute) return false;
			_bstr_t number(attribute->Gettext());

			attribute = node->Getattributes()->getNamedItem("bytes");
			if (!attribute) return false;
			_bstr_t bytes(attribute->Gettext());

			int partNumber = atoi(number);
			int lsize = atoi(bytes);

			if (partNumber > 0)
			{
				ArticleInfo* pArticle = new ArticleInfo();
				pArticle->SetPartNumber(partNumber);
				pArticle->SetMessageID(szId);
				pArticle->SetSize(lsize);
				AddArticle(pFileInfo, pArticle);
			}
		}

		AddFileInfo(pFileInfo);
	}
	return true;
}