B
Brad
Hi all,
So after a few days of tinkering I've finally got my very first piece
of vba using the MSXML2 parser to work. I've been using vba for
several years so that's fine but I'm finding the MSXML2 language a
little more complicated. Unfortunately I'm limited to v3.0 due to
corporate constraints.
Could any of you take a peek at what I've done and let me know if
there would have been an easier way to do this. I'm simply trying to
retrieve all the information from the xml file at this stage - for
those of you that are interested it's a news feed from the BBC
website.
Thanks in advance for any hints, tips or suggestions.
Regards,
Brad
'My vba stuff
Sub tester()
Dim xmlDoc As New MSXML2.DOMDocument, mine, mystr As String, i As
Integer, x As Integer
xmlDoc.Load ("http://news.bbc.co.uk/rss/newsonline_uk_edition/business/rss091.xml")
Set mine = xmlDoc.selectNodes("rss/channel/item/title")
For i = 0 To (mine.length - 1)
mystr = ""
For x = 0 To (mine.Item(i).parentNode.childNodes.length - 1)
mystr = mystr & mine.Item(i).parentNode.childNodes(x).nodeName
& " = " & mine.Item(i).parentNode.childNodes(x).Text & Chr(13)
Next x
MsgBox (mystr)
Next i
End Sub
'Sample bit of the XML file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="0.91"><channel>
<title>BBC News | Business | UK Edition</title>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/default.stm</link>
<description>Updated every minute of every day - FOR PERSONAL USE
ONLY</description>
<language>en-gb</language>
<lastBuildDate>Mon, 25 Oct 04 17:14:09 GMT</lastBuildDate>
<copyright>Copyright: (C) British Broadcasting Corporation,
http://news.bbc.co.uk/1/hi/help/3281849.stm</copyright>
<docs>http://www.bbc.co.uk/syndication/</docs>
<image>
<title>BBC News</title>
<url>http://news.bbc.co.uk/nol/shared/img/bbc_news_120x60.gif</url>
<link>http://news.bbc.co.uk</link>
</image>
<item>
<title>Manchester Utd end Glazer talks</title>
<description>Manchester Utd say they have ended talks with the
US sports tycoon Malcolm Glazer over a possible
takeover.</description>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/3950175.stm</link>
</item>
<item>
<title>Morrisons sells 114 Safeway shops</title>
<description>Somerfield is set to take over 114 Safeway stores
and a distribution centre from Morrisons in a £260m
deal.</description>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/3950219.stm</link>
</item>
<item>
<title>M&S starts share buyback scheme</title>
<description>Marks & Spencer begins buying back more than
a quarter of its shares in a move that will return £2.3bn ($4.2bn) to
shareholders.</description>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/3950423.stm</link>
</item>
</channel>
</rss>
So after a few days of tinkering I've finally got my very first piece
of vba using the MSXML2 parser to work. I've been using vba for
several years so that's fine but I'm finding the MSXML2 language a
little more complicated. Unfortunately I'm limited to v3.0 due to
corporate constraints.
Could any of you take a peek at what I've done and let me know if
there would have been an easier way to do this. I'm simply trying to
retrieve all the information from the xml file at this stage - for
those of you that are interested it's a news feed from the BBC
website.
Thanks in advance for any hints, tips or suggestions.
Regards,
Brad
'My vba stuff
Sub tester()
Dim xmlDoc As New MSXML2.DOMDocument, mine, mystr As String, i As
Integer, x As Integer
xmlDoc.Load ("http://news.bbc.co.uk/rss/newsonline_uk_edition/business/rss091.xml")
Set mine = xmlDoc.selectNodes("rss/channel/item/title")
For i = 0 To (mine.length - 1)
mystr = ""
For x = 0 To (mine.Item(i).parentNode.childNodes.length - 1)
mystr = mystr & mine.Item(i).parentNode.childNodes(x).nodeName
& " = " & mine.Item(i).parentNode.childNodes(x).Text & Chr(13)
Next x
MsgBox (mystr)
Next i
End Sub
'Sample bit of the XML file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="0.91"><channel>
<title>BBC News | Business | UK Edition</title>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/default.stm</link>
<description>Updated every minute of every day - FOR PERSONAL USE
ONLY</description>
<language>en-gb</language>
<lastBuildDate>Mon, 25 Oct 04 17:14:09 GMT</lastBuildDate>
<copyright>Copyright: (C) British Broadcasting Corporation,
http://news.bbc.co.uk/1/hi/help/3281849.stm</copyright>
<docs>http://www.bbc.co.uk/syndication/</docs>
<image>
<title>BBC News</title>
<url>http://news.bbc.co.uk/nol/shared/img/bbc_news_120x60.gif</url>
<link>http://news.bbc.co.uk</link>
</image>
<item>
<title>Manchester Utd end Glazer talks</title>
<description>Manchester Utd say they have ended talks with the
US sports tycoon Malcolm Glazer over a possible
takeover.</description>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/3950175.stm</link>
</item>
<item>
<title>Morrisons sells 114 Safeway shops</title>
<description>Somerfield is set to take over 114 Safeway stores
and a distribution centre from Morrisons in a £260m
deal.</description>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/3950219.stm</link>
</item>
<item>
<title>M&S starts share buyback scheme</title>
<description>Marks & Spencer begins buying back more than
a quarter of its shares in a move that will return £2.3bn ($4.2bn) to
shareholders.</description>
<link>http://news.bbc.co.uk/go/click/rss/0.91/public/-/1/hi/business/3950423.stm</link>
</item>
</channel>
</rss>