Help: how to get link addres in the RSS XML file in MFC/C++?
-
I have to parse RSS channel definition XML file. I have appended one sample at the end of this topic. I have installed MSXML parser 6 and uses it successfully. Please refer to function XmlRSSRead. There are a lot of information about the channel and item of this channel. For example, one channel has title, link, description information. One channel may have a lot of item too. Each item also hase title, link, description information. I have to extract title, link, description information in my application. I can not find one quick start guide from microsoft doucments. Could anyone be kind to tell me what I should do next? The following is the function I have now and the xml file I want to parse. void XmlRSSRead( void ) { //¡ä¡ä?¡§DOMDocument???¨® MSXML2::IXMLDOMDocumentPtr pDoc; HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30)); if(!SUCCEEDED(hr)) { AfxMessageBox( _T("?T¡¤¡§¡ä¡ä?¡§DOMDocument???¨®¡ê????¨¬2¨¦¨º?¡¤?¡ã2¡Á¡ã¨¢?MS XML Parser ??DD?a!") ); } //?¨®?????t pDoc->load( _T("D:\\temp\\mPhone\\Docs\\RSS\\nature.xml") ); //?¨²¨º¡Â?D2¨¦?¨°???achannel¦Ì??¨²¦Ì?, // "//"¡À¨ª¨º??¨²¨¨?¨°a¨°?2?2¨¦?¨° MSXML2::IXMLDOMElementPtr childNode ; childNode = (MSXML2::IXMLDOMElementPtr)(pDoc->selectSingleNode("//channel")); //¦Ì?¦Ì??¨²¦Ì?¨¤¨¤D¨ª MSXML2::DOMNodeType nodeType; childNode->get_nodeType(&nodeType); //?¨²¦Ì???3? BSTR var; CString name; childNode->get_nodeName(&var); name = (char*)(_bstr_t)var; //?¨²¦Ì??¦Ì VARIANT varVal; childNode->get_nodeTypedValue(&varVal); CString strValue = (char*)(_bstr_t)varVal; //?¨²¦Ì?¨º?D?,¡¤??¨²¨¢¡ä¡À¨ª?D MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL; MSXML2::IXMLDOMNodePtr pAttrItem; childNode->get_attributes(&pAttrs); long nCount ; pAttrs->get_length(&nCount); for(int i = 0 ; i < nCount ; i++) { pAttrs->get_item(i,&pAttrItem); //?¨°???¨¦¨°?¨ª¡§1yo¡¥¨ºyget_nodeName,get_nodeTypedValue¦Ì?¦Ì?¨º?D???o¨ª¨º?D??¦Ì //¨°2?¨¦¨°??¡À?¨®¦Ì?¦Ì? CString strAttrName = (char*)(_bstr_t)pAttrItem->nodeName; CString strAttrValue = (char*)(_bstr_t)pAttrItem->nodeTypedValue; } } void mfXmlReadTest( void ) { ::CoInitialize(NULL); MSXML2::IXMLDOMDocumentPtr spPtr; HRESULT hr = spPtr.CreateInstance(__uuidof(MSXML2::DOMDocument30)); ASSERT(SUCCEEDED(hr)); spPtr->loadXML("\ntop\nbottom\n"); spPtr->save("C:\\nature.xml"); spPtr.Release(); ::CoUninitialize(); } XMLÎļþÈçÏ£º