#184123 - 2007-12-21 11:04 AM
Read XML from web
|
Darren_W
Hey THIS is FUN
Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
|
Hi All,
I've got about 180 x 2003 servers running a script and I would like to fine tune the parameters they are using.
I was thinking about having a central XML file on a web server or a ini file.
How do I go about getting it to read a file from the Internet/intranet as apposed from a local file system?
Tried somthing like this but dont get any output:
$xml = LoadXml("http:\\localhost\test.xml")
$id = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/id")
$name = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/name")
$gender = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/gender")
$age = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/age")
$place = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/place")
$province = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/province")
$date_membership = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/date_membership")
$url_profile = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/url_profile")
$url_photothumb = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/url_photothumb")
$advert_title = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/advert_title")
$advert_description = ReadXmlValue($xml, "stuff/morestuff" + $index2 + "/advert_description")
? $id
? $name
? $gender
? $age
? $place
? $province
? $date_membership
? $url_profile
? $url_photothumb
? $advert_title
? $advert_description
Function ReadXmlValue($xml, $key, optional $defaultValue)
Dim $sectionNode
$sectionNode = $xml.SelectSingleNode($key);
If Not $sectionNode
$ReadXmlValue = $defaultValue
Else
$ReadXmlValue = $sectionNode.FirstChild.Text;
EndIf
EndFunction
Function LoadXml($filename)
Dim $rootNode
$loadXml = CreateObject("Microsoft.XMLDOM")
If Not $loadXml
Return
EndIf
$= $loadXml.Load($filename)
EndFunction Darren
Edited by Darren_W (2007-12-21 11:04 AM)
_________________________
I want to share something with you - the three sentences that will get you through life. Number 1, 'cover for me.' Number 2, 'oh, good idea, boss.' Number 3, 'it was like that when I got here'.
|
Top
|
|
|
|
#184129 - 2007-12-21 01:06 PM
Re: Read XML from web
[Re: Mart]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Guess this is a bit where COM Scripting comes in
Dim $xmlDoc, $objNodeList, $plot
$xmlDoc = CreateObject("Msxml2.DOMDocument")
$xmlDoc.load("c:\inetpub\wwwroot\test.xml")
$objNodeList = $xmlDoc.getElementsByTagName("description")
If $objNodeList.length > 0
For each $x in $objNodeList
$plot = $x.Text
? $plot
Next
Else
? chr(34) + "description" + chr(34) + " field not found."
EndIf
This is just something I quickly translated from the web, just search google for Microsoft.XMLDOM
|
Top
|
|
|
|
#184137 - 2007-12-21 02:28 PM
Re: Read XML from web
[Re: Arend_]
|
Darren_W
Hey THIS is FUN
Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
|
Humm,
I would like to read it from a webserver, I'm just testing it on a local install of apache as below using "http://localhost/inifile.ini" but dont get anything, what is the correct syntax to do this? code:
Break on
$inifile = "http://localhost/inifile.ini"
$pfilesizeserver1 = ReadProfileString($inifile, "Server01", "Pagefilesize")
?$pfilesizeserver1
$pfilesizeserver2 = ReadProfileString($inifile, "Server02", "Pagefilesize")
?$pfilesizeserver2
Sleep 3
Darren
_________________________
I want to share something with you - the three sentences that will get you through life. Number 1, 'cover for me.' Number 2, 'oh, good idea, boss.' Number 3, 'it was like that when I got here'.
|
Top
|
|
|
|
#184162 - 2007-12-21 09:43 PM
Re: Read XML from web
[Re: NTDOC]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
One could use CreateObject("Microsoft.XMLHttp") to download the file locally and read it out from there. For instance
Dim $xml, $get
$xml = CreateObject("Microsoft.XMLHTTP")
$xml.Open("GET","http://www.somesite.org/news.xml",Not 1)
$xml.Send
$get = CreateObject("ADODB.Stream")
$get.Mode = 3 ;adModeReadWrite
$get.Type = 1 ;adTypeBinary
$get.Open
$get.Write($xml.ResponseBody)
$get.SaveToFile("C:\temp.xml",2) ;2 is adSaveCreateOverwrite
$get.Close
$get = ""
$xml = ""
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 557 anonymous users online.
|
|
|