Jump to content

XML Child Node or Path


Recommended Posts

Looked and copy/paste several variations from articles I've read and the key sticking pointing is that I don't under stand how to define the path in the xml file.

XML is a weather page http://forecast.weather.gov/MapClick.php?lat=34.3855&lon=-118.514&unit=0&lg=english&FcstType=dwml

Goal for now is just to learn how to clipput the current temperature.

Thanks in advance.

<data type="current observations">
 <parameters applicable-location="point1">
  <temperature type="apparent" units="Fahrenheit" time-layout="k-p1h-n1-1">
   <value>89</value>
#include <_XMLDomWrapper.au3>
#include <File.au3>

Global $oXML = ObjCreate("Microsoft.XMLHTTP")
$oXML.Open("GET", "http://forecast.weather.gov/MapClick.php?lat=34.3855&lon=-118.514&unit=0&lg=english&FcstType=dwml", 0)
$oXML.Send

Global $sFile = _TempFile(@TempDir, '~', '.xml')
FileWrite($sFile, $oXML.responseText)

$dataName = "current observations"
$tempName = "apparent"

If _XMLFileOpen($sFile) Then
    Local $sLvl = _XMLGetAttrib('/data[@type="' & $dataName & '"]/parameters/temperature[@type="' & $tempName & '"]/value', '')
    ClipPut($sLvl)
EndIf

FileDelete($sFile)

 

Link to comment
Share on other sites

Hi, maybe this would be a little shorter sample.

Opt("MustDeclareVars",1)
Dim $oXmlParser = ObjCreate("MSXML2.DOMDOcument")
With $oXmlParser
    .Async = False
    .Load("http://forecast.weather.gov/MapClick.php?lat=34.3855&lon=-118.514&unit=0&lg=english&FcstType=dwml")
    Dim $sTemperature = .SelectSingleNode("//data[@type=""current observations""]/parameters/temperature[@type=""apparent""]/value").text
    MsgBox(64,"Temperature request","Current temperature is " & $sTemperature)
EndWith

 

Edited by Xameleon
Link to comment
Share on other sites

Hi, maybe this would be a little shorter sample.

Opt("MustDeclareVars",1)
Dim $oXmlParser = ObjCreate("MSXML2.DOMDOcument")
With $oXmlParser
    .Async = False
    .Load("http://forecast.weather.gov/MapClick.php?lat=34.3855&lon=-118.514&unit=0&lg=english&FcstType=dwml")
    Dim $sTemperature = .SelectSingleNode("//data[@type=""current observations""]/parameters/temperature[@type=""apparent""]/value").text
    MsgBox(64,"Temperature request","Current temperature is " & $sTemperature)
EndWith

 

 

9699_stephen-colbert-the-colbert-report-thank-you-thanks_200s.gif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...