ocean #1079(2007/07/18 17:38 GMT) [ C++ ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#include <atlbase.h> #include <msxml6.h> #pragma comment(lib, "msxml6.lib") #include <iostream> #include <stdexcept> #include <string> struct CoInitializer { CoInitializer() { CoInitialize(NULL); } ~CoInitializer() { CoUninitialize(); } }; void check(HRESULT hr, const std::string& name) { if (FAILED(hr)) { throw std::runtime_error("invocation of " + name); } } int main() { try { CoInitializer init; CComPtr<IXMLDOMDocument> doc; check(doc.CoCreateInstance(CLSID_DOMDocument), "CoCreateInstance"); check(doc->put_async(VARIANT_FALSE), "put_async"); VARIANT_BOOL isSuccessful; check(doc->load(CComVariant("http://ja.doukaku.org/feeds/comments/"), &isSuccessful), "load"); if (isSuccessful == VARIANT_FALSE) { throw std::runtime_error("load failed"); } CComPtr<IXMLDOMNode> node; check(doc->selectSingleNode(CComBSTR(L"//lastBuildDate"), &node), "selectSingleNode"); if (! node) { throw std::runtime_error("node 'lastBuildDate' not found"); } CComBSTR text; check(node->get_text(&text), "get_text"); USES_CONVERSION; // needed for W2A() std::cout << W2A(text) << std::endl; } catch (std::exception& e) { std::cerr << "error: " << e.what() << std::endl; return -1; } return 0; }
Rating0/0=0.00-0+
[ reply ]
ocean
#1079()
[
C++
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]