Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script to extract XML data

Reply
 
Old 11-12-2008   #1 (permalink)
JT


 
 

Script to extract XML data

Hi

This script below connects to a weather RSS feed, what I would like to
do is extract the text value for each <title> element within the <item>
element and assign it a variable. I would also like to get the <url>
text within <image> as a variable too.

I got as far below as displaying the entire document.Element data but
I'm not sure how to traverse through and pick up the field text I
require - can anyone help ?

Thanks

JT


Set objXML=CreateObject("MSXML2.DOMDocument")
Set objXSL=CreateObject("MSXML2.DOMDocument")
objXML.async=False
objXSL.async=False
objXML.setProperty "ServerHTTPRequest",true
objXML.load
("http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/1181.xml")
for each x in objXML.documentElement.childNodes
Msgbox x.nodename
Msgbox x.text
next

My System SpecsSystem Spec
Old 11-12-2008   #2 (permalink)
Tim Williams


 
 

Re: Script to extract XML data

Try this:
'******************************
Dim objXML, objXSL, x

Set objXML = CreateObject("MSXML2.DOMDocument")
Set objXSL = CreateObject("MSXML2.DOMDocument")
objXML.async = False
objXSL.async = False
objXML.setProperty "ServerHTTPRequest", True
objXML.Load "http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/1181.xml"
objXML.setProperty "SelectionLanguage", "XPath"

For Each x In objXML.documentElement.selectNodes(".//item/title")
MsgBox x.nodename & " = " & x.Text
Next

For Each x In objXML.documentElement.selectNodes(".//image/url")
MsgBox x.nodename & " = " & x.Text
Next
'******************************

Tim

"JT" <JT@xxxxxx> wrote in message
news:491b51dd$0$5709$9a6e19ea@xxxxxx
Quote:

> Hi
>
> This script below connects to a weather RSS feed, what I would like to do
> is extract the text value for each <title> element within the <item>
> element and assign it a variable. I would also like to get the <url> text
> within <image> as a variable too.
>
> I got as far below as displaying the entire document.Element data but I'm
> not sure how to traverse through and pick up the field text I require -
> can anyone help ?
>
> Thanks
>
> JT
>
>
> Set objXML=CreateObject("MSXML2.DOMDocument")
> Set objXSL=CreateObject("MSXML2.DOMDocument")
> objXML.async=False
> objXSL.async=False
> objXML.setProperty "ServerHTTPRequest",true
> objXML.load
> ("http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/1181.xml")
> for each x in objXML.documentElement.childNodes
> Msgbox x.nodename
> Msgbox x.text
> next

My System SpecsSystem Spec
Old 11-13-2008   #3 (permalink)
JT


 
 

Re: Script to extract XML data

That's great - thanks a lot!



Tim Williams wrote:
Quote:

> Try this:
> '******************************
> Dim objXML, objXSL, x
>
> Set objXML = CreateObject("MSXML2.DOMDocument")
> Set objXSL = CreateObject("MSXML2.DOMDocument")
> objXML.async = False
> objXSL.async = False
> objXML.setProperty "ServerHTTPRequest", True
> objXML.Load "http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/1181.xml"
> objXML.setProperty "SelectionLanguage", "XPath"
>
> For Each x In objXML.documentElement.selectNodes(".//item/title")
> MsgBox x.nodename & " = " & x.Text
> Next
>
> For Each x In objXML.documentElement.selectNodes(".//image/url")
> MsgBox x.nodename & " = " & x.Text
> Next
> '******************************
>
> Tim
>
> "JT" <JT@xxxxxx> wrote in message
> news:491b51dd$0$5709$9a6e19ea@xxxxxx
Quote:

>> Hi
>>
>> This script below connects to a weather RSS feed, what I would like to do
>> is extract the text value for each <title> element within the <item>
>> element and assign it a variable. I would also like to get the <url> text
>> within <image> as a variable too.
>>
>> I got as far below as displaying the entire document.Element data but I'm
>> not sure how to traverse through and pick up the field text I require -
>> can anyone help ?
>>
>> Thanks
>>
>> JT
>>
>>
>> Set objXML=CreateObject("MSXML2.DOMDocument")
>> Set objXSL=CreateObject("MSXML2.DOMDocument")
>> objXML.async=False
>> objXSL.async=False
>> objXML.setProperty "ServerHTTPRequest",true
>> objXML.load
>> ("http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/1181.xml")
>> for each x in objXML.documentElement.childNodes
>> Msgbox x.nodename
>> Msgbox x.text
>> next
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
script to extract and create contacts VB Script
batch job to extract data from tables in DB2 .NET General
Powershell Script to extract drive information PowerShell
Extract data from web page PowerShell
Script to extract username from path statement PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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