BOOL vmsMetalinkFile::Parse(LPCSTR pszFile) { USES_CONVERSION; IXMLDOMDocumentPtr spXML; IXMLDOMNodePtr spNode; spXML.CreateInstance (__uuidof (DOMDocument)); if (spXML == NULL) return FALSE; spXML->put_async (FALSE); VARIANT_BOOL bRes; spXML->load (COleVariant (pszFile), &bRes); if (bRes == FALSE) return FALSE; spXML->selectSingleNode (L"metalink", &spNode); if (spNode == NULL) return FALSE; IXMLDOMNodeListPtr spNodeList; spNode->get_childNodes (&spNodeList); if (spNodeList == NULL) return FALSE; IXMLDOMNodePtr spItem; BOOL bHasOkFilesNode = FALSE; while (SUCCEEDED (spNodeList->nextNode (&spItem)) && spItem != NULL) { CComBSTR bstrName; spItem->get_nodeName (&bstrName); if (bstrName == L"description") { CComBSTR bstrText; spItem->get_text (&bstrText); m_strDescription = W2A (bstrText); } else if (bstrName == L"files") { if (ReadFilesNode (spItem)) bHasOkFilesNode = TRUE; } spItem = NULL; } return bHasOkFilesNode; }
BOOL CDlgExportDownloads::ExportDownloads_ToDLInfoListFile(LPCSTR pszFile, DLDS_LIST* pvpDlds, BOOL bAppend) { IXMLDOMDocumentPtr spXML; IXMLDOMNodePtr spNode, spNode2; spXML.CreateInstance (__uuidof (DOMDocument)); if (spXML == NULL) return FALSE; spXML->put_async (FALSE); VARIANT_BOOL bRes = FALSE; if (bAppend) { spXML->load (COleVariant (pszFile), &bRes); if (bRes) { spXML->selectSingleNode (L"FDM_Downloads_Info_List", &spNode); if (spNode == NULL) bRes = FALSE; } } if (bRes == FALSE) { spXML->createNode (COleVariant ((long)NODE_ELEMENT), L"FDM_Downloads_Info_List", NULL, &spNode); spXML->appendChild (spNode, &spNode2); } for (size_t i = 0; i < pvpDlds->size (); i++) { ExportDownload_ToXML (spXML, spNode, pvpDlds->at (i)); } CComBSTR bstr; spXML->get_xml (&bstr); CString str = bstr; str.Replace ("><", ">\n<"); bstr = str; spXML->loadXML (bstr, &bRes); spXML->save (COleVariant (pszFile)); return TRUE; }
bool SaveXMLDoc(LPCWSTR file, BDADEVICES& d) { IXMLDOMDocumentPtr Document; IXMLDOMElementPtr root; IXMLDOMElementPtr bda_source; IXMLDOMElementPtr bda_reciever; HRESULT hr; hr = Document.CreateInstance(CLSID_DOMDocument30); if(hr==S_OK) { // these methods should not fail so don't inspect result Document->put_async(VARIANT_FALSE); Document->put_validateOnParse(VARIANT_FALSE); Document->put_resolveExternals(VARIANT_FALSE); CreatePI(Document); CreateElement(Document,L"bdainf",&root); CreateElement(Document,L"kscategory_bda_network_tuner",&bda_source); CreateElement(Document,L"kscategory_bda_receiver_component",&bda_reciever); CreateDeviceList(Document,bda_source,d.bda_source); CreateDeviceList(Document,bda_reciever,d.bda_reciever); AppendChild(bda_source,root); AppendChild(bda_reciever,root); AppendChild(root,Document); hr = Document->save(_variant_t(file)); if(hr==S_OK) { return true; } else { //notify error return false; } } else { //notify error return false; } }
BOOL vmsVideoSiteHtmlCodeParser::Parse_Further_MySpace(LPCSTR pszHtml) { USES_CONVERSION; IXMLDOMDocumentPtr spXML; IXMLDOMNodePtr spNode, spNode2; while (*pszHtml && *pszHtml != '<') pszHtml++; spXML.CreateInstance (__uuidof (DOMDocument)); if (spXML == NULL) return FALSE; spXML->put_async (FALSE); VARIANT_BOOL bRes; spXML->loadXML (A2W (pszHtml), &bRes); if (bRes == FALSE) return FALSE; spXML->selectSingleNode (L"rss", &spNode); if (spNode == NULL) return FALSE; spNode->selectSingleNode (L"channel", &spNode2); if (spNode2 == NULL) return FALSE; spNode = NULL; spNode2->selectSingleNode (L"item", &spNode); if (spNode == NULL) return FALSE; spNode2 = NULL; spNode->selectSingleNode (L"title", &spNode2); if (spNode2 == NULL) return FALSE; CComBSTR bstrTitle; spNode2->get_text (&bstrTitle); spNode2 = NULL; spNode->selectSingleNode (L"media:content", &spNode2); if (spNode2 == NULL) return FALSE; IXMLDOMNamedNodeMapPtr spAttrs; spNode2->get_attributes (&spAttrs); if (spAttrs == NULL) return FALSE; IXMLDOMNodePtr spUrlValue; spAttrs->getNamedItem (L"url", &spUrlValue); if (spUrlValue == NULL) return FALSE; COleVariant vtUrl; spUrlValue->get_nodeValue (&vtUrl); ASSERT (vtUrl.vt == VT_BSTR); if (vtUrl.vt != VT_BSTR) return FALSE; m_strVideoTitle = W2A (bstrTitle); fsDecodeHtmlText (m_strVideoTitle); m_strVideoUrl = W2A (vtUrl.bstrVal); m_strVideoType = (LPCSTR)m_strVideoUrl + m_strVideoUrl.GetLength () - 3; m_bDirectLink = TRUE; return TRUE; }
bool ParseXmlFile( TCHAR* pszFileName ) { if( NULL == pszFileName ) { return false; } HRESULT hResult; // DOMドキュメントの作成 IXMLDOMDocumentPtr pXMLDOMDocument; hResult = pXMLDOMDocument.CreateInstance(CLSID_DOMDocument); if( FAILED(hResult) ) { assert( !"DOMドキュメントの作成に失敗" ); return false; } // XMLファイル読み込み pXMLDOMDocument->put_async( VARIANT_FALSE ); // load関数がロードを完了するまで待つようにする。 VARIANT_BOOL varbResult; hResult = pXMLDOMDocument->load( CComVariant(pszFileName), &varbResult ); if( FAILED(hResult) || !varbResult) { assert( !"XMLファイル読み込みに失敗" ); return false; } // std::vector<CComBSTR> vbstrValue; std::vector<CComBSTR> vbstrValueName; std::vector<CComBSTR> vbstrValueScreenName; std::vector<CComBSTR> vbstrValueText; std::vector<CComBSTR> vbstrValueDate; /* // author要素の値の取得 if( !GetXmlValue( pXMLDOMDocument, _T("author"), _T(""), vbstrValue ) ) { assert( !"author要素の値の取得に失敗" ); return false; } std::cout << "author要素の値" << std::endl; for( unsigned int ui = 0; ui < vbstrValue.size(); ++ui ) { std::cout << "\t" << _com_util::ConvertBSTRToString(vbstrValue[ui]) << std::endl; } */ /* // book要素のid属性の値の取得 if( !GetXmlValue( pXMLDOMDocument, _T("book"), _T("id"), vbstrValue ) ) { assert( !"book要素のid属性の値の取得に失敗" ); return false; } std::cout << "book要素のid属性の値" << std::endl; for( unsigned int ui = 0; ui < vbstrValue.size(); ++ui ) { std::cout << "\t" << _com_util::ConvertBSTRToString((TCHAR*)vbstrValue[ui]) << std::endl; } */ // name要素の値の取得 if( !GetXmlValue( pXMLDOMDocument, _T("name"), _T(""), vbstrValueName ) ) { assert( !"name要素の値の取得に失敗" ); return false; } // screen_name要素の値の取得 if( !GetXmlValue( pXMLDOMDocument, _T("screen_name"), _T(""), vbstrValueScreenName ) ) { assert( !"screen_name要素の値の取得に失敗" ); return false; } // created_at要素の値の取得 if( !GetXmlValue( pXMLDOMDocument, _T("created_at"), _T(""), vbstrValueDate ) ) { assert( !"created_at要素の値の取得に失敗" ); return false; } // text要素の値の取得 if( !GetXmlValue( pXMLDOMDocument, _T("text"), _T(""), vbstrValueText ) ) { assert( !"text要素の値の取得に失敗" ); return false; } std::cout << "つぶやきの表示テスト\n" << std::endl; for( unsigned int ui = 0; ui < vbstrValueName.size(); ++ui ) { std::cout << ui+1 << ")" << _com_util::ConvertBSTRToString(vbstrValueName[ui]) << " " << _com_util::ConvertBSTRToString(vbstrValueScreenName[ui]) << std::endl; std::cout << " " << _com_util::ConvertBSTRToString(vbstrValueText[ui]) << std::endl; std::cout << " " << _com_util::ConvertBSTRToString(vbstrValueDate[ui]) << "\n" << std::endl; } return true; }