github.com/go-ole/go-ole@v1.2.6/_example/msxml/rssreader.go (about) 1 // +build windows 2 3 package main 4 5 import ( 6 "fmt" 7 "time" 8 9 ole "github.com/go-ole/go-ole" 10 "github.com/go-ole/go-ole/oleutil" 11 ) 12 13 func main() { 14 ole.CoInitialize(0) 15 unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP") 16 xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch) 17 _, err := oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false) 18 if err != nil { 19 panic(err.Error()) 20 } 21 _, err = oleutil.CallMethod(xmlhttp, "send", nil) 22 if err != nil { 23 panic(err.Error()) 24 } 25 state := -1 26 for state != 4 { 27 state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val) 28 time.Sleep(10000000) 29 } 30 responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch() 31 items := oleutil.MustCallMethod(responseXml, "selectNodes", "/rdf:RDF/item").ToIDispatch() 32 length := int(oleutil.MustGetProperty(items, "length").Val) 33 34 println(length) 35 for n := 0; n < length; n++ { 36 item := oleutil.MustGetProperty(items, "item", n).ToIDispatch() 37 38 title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch() 39 fmt.Println(oleutil.MustGetProperty(title, "text").ToString()) 40 41 link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch() 42 fmt.Println(" " + oleutil.MustGetProperty(link, "text").ToString()) 43 44 title.Release() 45 link.Release() 46 item.Release() 47 } 48 items.Release() 49 xmlhttp.Release() 50 }