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 LoadXMLDoc(LPCWSTR file, BDADEVICES& d) { IXMLDOMDocumentPtr Document; HRESULT hr; d.reset(); hr = Document.CreateInstance(CLSID_DOMDocument30); if(hr==S_OK) { VARIANT_BOOL success; hr = Document->load(_variant_t(file),&success); if(hr==S_OK&&success==VARIANT_TRUE) { IXMLDOMElementPtr root; IXMLDOMElementPtr bda_source; IXMLDOMElementPtr bda_reciever; IXMLDOMNodePtr bda_source_node; IXMLDOMNodePtr bda_reciever_node; hr = Document->get_documentElement(&root); hr = root->selectSingleNode(_bstr_t(L"kscategory_bda_network_tuner"),&bda_source_node); hr = root->selectSingleNode(_bstr_t(L"kscategory_bda_receiver_component"),&bda_reciever_node); bda_source = bda_source_node; bda_reciever = bda_reciever_node; GetDeviceList(bda_source,d.bda_source); GetDeviceList(bda_reciever,d.bda_reciever); } else { return false; } } else { return false; } return false; }
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 GetXmlValue( const IXMLDOMDocumentPtr& pXMLDOMDocument, const CComBSTR& bstrTagName, const CComBSTR& bstrAttributeName, std::vector<CComBSTR>& rvbstrValue ) { // アウトプットの初期化 rvbstrValue.clear(); // インプットのチェック if( 0 == bstrTagName.Length() ) { return false; } HRESULT hResult; // タグ名のノードリストの取得 IXMLDOMNodeListPtr pXMLDOMNodeList = NULL; hResult = pXMLDOMDocument->getElementsByTagName( bstrTagName, &pXMLDOMNodeList ); if( FAILED(hResult) || NULL == pXMLDOMNodeList ) { assert( !"タグ名のノードリストの取得に失敗" ); return false; } // ノードリストのノードの数の取得 long lCountNode = 0; hResult = pXMLDOMNodeList->get_length( &lCountNode ); if( FAILED(hResult) ) { assert( !"ノードリストのノードの数の取得に失敗" ); return false; } // ノードリストのノード一つずつ処理 for( int i = 0; i < lCountNode; ++i ) { // ノードリストのうちの一つのノードの取得 IXMLDOMNodePtr pXMLDOMNode = NULL; hResult = pXMLDOMNodeList->get_item( i, &pXMLDOMNode ); if( FAILED(hResult) ) { assert( !"ノードリストのうちの一つのノードの取得に失敗" ); return false; } // ノードタイプの取得 DOMNodeType eNodeType; hResult = pXMLDOMNode->get_nodeType( &eNodeType ); if( FAILED(hResult) ) { assert( !"ノードタイプの取得に失敗" ); return false; } if( NODE_ELEMENT != eNodeType ) { assert( !"ノードタイプがエレメントでないのはおかしい" ); return false; } // エレメント型への変換 IXMLDOMElementPtr pXMLDOMElement = NULL; hResult = pXMLDOMNode->QueryInterface( IID_IXMLDOMElement, (void**)&pXMLDOMElement ); // スマートポインタ型を利用しているので、pXMLDOMElement = pXMLDOMNode; でも良い。 if( FAILED(hResult) || NULL == pXMLDOMElement ) { assert( !"エレメント型への変換に失敗" ); return false; } // 属性値の取得か、データ値の取得か if( bstrAttributeName.Length() ) { // 属性値の取得 IXMLDOMAttribute* pAttributeNode = NULL; CComVariant varValue; hResult = pXMLDOMElement->getAttribute( bstrAttributeName, &varValue ); if( SUCCEEDED(hResult) && VT_BSTR == varValue.vt ) { rvbstrValue.push_back( varValue.bstrVal ); } } else { // データ値の取得 CComBSTR bstrText; hResult = pXMLDOMElement->get_text( &bstrText ); if( SUCCEEDED(hResult) ) { rvbstrValue.push_back( bstrText ); } } } 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; }
int main(int argc, char* argv[]) { CoInitialize(NULL); try{ IXMLDOMDocumentPtr pXMLDoc; HRESULT hr = pXMLDoc.CreateInstance(__uuidof(DOMDocument)); pXMLDoc->async = false; // default - true, hr = pXMLDoc->load("stock.xml"); if(hr!=VARIANT_TRUE) { IXMLDOMParseErrorPtr pError; pError = pXMLDoc->parseError; _bstr_t parseError =_bstr_t("At line ")+ _bstr_t(pError->Getline()) + _bstr_t("\n")+ _bstr_t(pError->Getreason()); MessageBox(NULL,parseError, "Parse Error",MB_OK); return 0; } CComPtr<IStream> pStream; hr = CreateStreamOnHGlobal(NULL, true, &pStream); hr = pXMLDoc->save(pStream.p); LARGE_INTEGER pos; pos.QuadPart = 0; //the key is to reset the seek pointer pStream->Seek((LARGE_INTEGER)pos, STREAM_SEEK_SET, NULL); IXMLDOMDocumentPtr pXMLDocNew; hr = pXMLDocNew.CreateInstance(__uuidof(DOMDocument)); pXMLDocNew->async = false; hr = pXMLDocNew->load(pStream.p); if(hr!=VARIANT_TRUE) { IXMLDOMParseErrorPtr pError; pError = pXMLDocNew->parseError; _bstr_t parseError =_bstr_t("At line ")+ _bstr_t(pError->Getline()) + _bstr_t("\n")+ _bstr_t(pError->Getreason()); MessageBox(NULL,parseError, "Parse Error",MB_OK); return 0; } MessageBox(NULL,(LPTSTR)pXMLDocNew->xml, "XML content",MB_OK); } catch(_com_error &e) { dump_com_error(e); } CoUninitialize(); return 0; }
BOOL BitmapPropertiesRecordHandler::HandleRecord( CXaraFileRecord* pCXaraFileRecord ) { ERROR2IF(pCXaraFileRecord == NULL,FALSE,"BitmapPropertiesRecordHandler::HandleRecord pCXaraFileRecord is NULL"); BOOL ok = TRUE; UINT32 tag = pCXaraFileRecord->GetTag(); // read in the record --------------------------------------------------------- // read bitmap reference INT32 BmpRef = 0; INT32 MasterRef = 0; String_256 BitmapName; ok = pCXaraFileRecord->ReadINT32(&BmpRef); // read flags BYTE Flags; if (ok) ok = pCXaraFileRecord->ReadBYTE(&Flags); // read other stuff BYTE Temp; for( INT32 i=0; i<7; i++ ) { if (ok) ok = pCXaraFileRecord->ReadBYTE(&Temp); } // Read XPE master ref and XML edits list // _bstr_t bstrXML; StringVar strXML; if (ok && tag==TAG_XPE_BITMAP_PROPERTIES) { ok = pCXaraFileRecord->ReadINT32(&MasterRef); if (ok) ok = pCXaraFileRecord->ReadUnicode(&BitmapName); // if (ok) ok = pCXaraFileRecord->ReadBSTR(&bstrXML, pCXaraFileRecord->GetSize()); if (ok) ok = pCXaraFileRecord->ReadUTF16STR(&strXML, pCXaraFileRecord->GetSize()); } // process the record --------------------------------------------------------- // look up the bitmap from BmpRef if (BmpRef == 0) { // no such bitmap ok = FALSE; } else { KernelBitmap *pBitmap = NULL; pBitmap = GetReadBitmapReference(BmpRef); if (pBitmap == NULL) { // no such bitmap ok = FALSE; } else { // process the flags BOOL bSmoothWhenScaledUp = Flags & 0x01; pBitmap->SetInterpolation(bSmoothWhenScaledUp); // Setup XPE info // (If we don't have it, it's not important - this bitmap will just lose // it's XPE edit info and will become its own master) PORTNOTETRACE("other","BitmapPropertiesRecordHandler::HandleRecord - remove XML code"); #ifndef EXCLUDE_FROM_XARALX if (tag==TAG_XPE_BITMAP_PROPERTIES && MasterRef!=0) { KernelBitmap* pMasterBitmap = NULL; pMasterBitmap = GetReadBitmapReference(MasterRef); VARIANT_BOOL varResult; IXMLDOMDocumentPtr pxmlDoc = CXMLUtils::NewDocument(); HRESULT hr = pxmlDoc->loadXML(bstrXML, &varResult); if (pMasterBitmap && SUCCEEDED(hr) && VARIANT_TRUE == varResult) { // We now know that this master bitmap will be used // so add it to the document's bitmap list... // Get the bitmap list from the current document Document* pDoc = Document::GetCurrent(); BitmapList* pBmpList = pDoc->GetBitmapList(); if (!pBmpList->FindDuplicateBitmap(pMasterBitmap->ActualBitmap)) // and then attach the bitmap pMasterBitmap->Attach(pBmpList); // See whether we need to regenerate this bitmap from the // Master and the Edits... if (pBitmap->IsDefaultBitmap()) { XPEEditOp::DoProcessBitmap(pBitmap, pMasterBitmap, pxmlDoc); } pBitmap->SetXPEInfo(pMasterBitmap, pxmlDoc); // Can only do this after DoProcessBitmap... } pBitmap->SetName(BitmapName); // ...and this, because process may create new OILBitmap } #endif } } return ok; }