Exemplo n.º 1
0
void foo() {

	MSXML::IXMLDOMDocumentPtr doc;
	HRESULT hr = doc.CreateInstance( MSXML::CLSID_DOMDocument );

	//doc->async = false;
	doc->load( "EnshutsuAuto.xml" );
}
Exemplo n.º 2
0
bool NZBFile::Parse()
{
    CoInitialize(NULL);

	HRESULT hr;

	MSXML::IXMLDOMDocumentPtr doc;
	hr = doc.CreateInstance(MSXML::CLSID_DOMDocument);
    if (FAILED(hr))
    {
        return false;
    }

    // Load the XML document file...
	doc->put_resolveExternals(VARIANT_FALSE);
	doc->put_validateOnParse(VARIANT_FALSE);
	doc->put_async(VARIANT_FALSE);

	// filename needs to be properly encoded
	char* szURL = (char*)malloc(strlen(m_szFileName)*3 + 1);
	EncodeURL(m_szFileName, szURL);
	debug("url=\"%s\"", szURL);
	_variant_t v(szURL);
	free(szURL);

	VARIANT_BOOL success = doc->load(v);
	if (success == VARIANT_FALSE)
	{
		_bstr_t r(doc->GetparseError()->reason);
		const char* szErrMsg = r;

		char szMessageText[1024];
		snprintf(szMessageText, 1024, "Error parsing nzb-file %s: %s", Util::BaseFileName(m_szFileName), szErrMsg);
		szMessageText[1024-1] = '\0';
		m_pNZBInfo->AddMessage(Message::mkError, szMessageText);

		return false;
	}

    if (!ParseNZB(doc))
	{
		return false;
	}

	if (GetNZBInfo()->GetFileList()->empty())
	{
		char szMessageText[1024];
		snprintf(szMessageText, 1024, "Error parsing nzb-file %s: file has no content", Util::BaseFileName(m_szFileName));
		szMessageText[1024-1] = '\0';
		m_pNZBInfo->AddMessage(Message::mkError, szMessageText);

		return false;
	}

	ProcessFiles();

    return true;
}
Exemplo n.º 3
0
/** @brief Load all Application settings in one shot from the XML file.
* @remarks CoInitialize() or CoInitializeEx() must have been called before using this method.
* @param _sFileName the full path name of an existing file
*/
bool MenuCommandSetCfg::_LoadFile(const std::string& _sFileName)
{
	const _bstr_t XMLDOM_OBJECT= _T("Microsoft.XMLDOM");
	const _bstr_t NODE_DART(_T("uicfg"));
	const _bstr_t NODE_COMMANDS(_T("commands"));
	const _bstr_t NODE_VERSION(_T("version"));
	const _bstr_t NODE_COMMANDLIST(_T("commandlist"));
	const _bstr_t NODE_MENULIST(_T("menulist"));

	bool bResult= false;

	try
	{
		MSXML::IXMLDOMDocumentPtr XMLDom;
		HRESULT hResult = XMLDom.CreateInstance((LPCSTR)XMLDOM_OBJECT);
		if(S_OK==hResult)
		{
			_ClearLists();

			_bstr_t FileName(_sFileName.c_str());

			if(XMLDom->load(FileName))
			{
				MSXML::IXMLDOMNodePtr Root= XMLDom->selectSingleNode(NODE_DART);
				MSXML::IXMLDOMNodePtr XMLNode;
				MSXML::IXMLDOMNodePtr XMLNode2;
				if( Root != NULL )
				{
					//load the file version
					XMLNode = Root->selectSingleNode(NODE_VERSION);
					_LoadFileVersion(XMLNode);

					//load the list of menu items
					XMLNode = Root->selectSingleNode(NODE_COMMANDS);
					if(XMLNode){
						XMLNode2= XMLNode->selectSingleNode(NODE_COMMANDLIST);
						_LoadMenuItemList(XMLNode2);

						XMLNode2= XMLNode->selectSingleNode(NODE_MENULIST);
						_LoadMenuList(XMLNode2);
					}
					bResult= true;
				}
			}
		}
		else{
			TRACE(_T("Failed to load XMLDom (%x)\n"), hResult);
		}
	}
	catch(...){
		TRACE(_T("Exception while loading config file\n"));
	}
	return bResult;
}
Exemplo n.º 4
0
Result FileToXML(MSXML::IXMLDOMDocumentPtr& p, const string& fileName)
{
	Result r;

	try
	{
		HRESULT hr;
		if(FAILED(hr = p.CreateInstance("msxml.domdocument")))
		{
			r.Fail(Format("Failed to create instance of msxml.domdocument.  Error code: %").ul(hr).Str());
		}
		else
		{
      VARIANT_BOOL b = p->load(fileName.c_str());
			if(b == VARIANT_FALSE)
			{
				MSXML::IXMLDOMParseErrorPtr pErr = p->GetparseError();
				if(pErr == NULL)
				{
					r.Fail(_T("Failed to load XML into msxml.domdocument.  Could not get IXMLDOMParseErrorPtr for details."));
				}
				else
				{
					r.Fail(Format("Failed to parse xml.  %").s(pErr->reason).Str());
				}
			}
			else
			{
				r.Succeed();
			}
		}
	}
	catch(_com_error& e)
	{
		r.Fail(Format("Error loading XML into msxml.domdocument. % %").s(e.ErrorMessage()).s(e.Description()).Str());
	}

	return r;
}