Page 1 of 1 1
Topic Options
#184123 - 2007-12-21 11:04 AM Read XML from web
Darren_W Offline
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:

 Code:
$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
#184124 - 2007-12-21 11:27 AM Re: Read XML from web [Re: Darren_W]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Reading an XML is a pain with kix. I did some stuff with it and most of the times the output is empty. Did not find anything that solves this in kix.

An ini file is real easy to read with kix.

An example.
Script.
 Code:
Break on

$inifile = "\\server\share\inifile.ini"

$pfilesizeserver1 = ReadProfileString($inifile, "Server01", "Pagefilesize")
?$pfilesizeserver1
$pfilesizeserver2 = ReadProfileString($inifile, "Server02", "Pagefilesize")
?$pfilesizeserver2

Sleep 3


inifile:
 Code:
[server01]
Pagefilesize=1234567890

[server02]
Pagefilesize=1122334455


This just an example so it shows 1234567890 and 1122334455 on your screen and does nothing to specific server.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#184129 - 2007-12-21 01:06 PM Re: Read XML from web [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Guess this is a bit where COM Scripting comes in
 Code:
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 Offline
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:

 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
#184145 - 2007-12-21 04:00 PM Re: Read XML from web [Re: Darren_W]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
COM would work for XML but all it gave me is a headache. I used scripts from several threads on this board and for some weird reason they can read some xml files but on other files with the same layout and encoding they fail. XML is getting bigger and bigger so maybe it is time for some proper XML support in kix.

A web server cannot serve an ini file like it can an html/asp/php, etc.... file.
If it is localhost then why not just use \\server\share\inifile.ini?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#184146 - 2007-12-21 04:19 PM Re: Read XML from web [Re: Mart]
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
No, its not going to be on the localhost, but on a remote server (Intranet), just running a local webserver to test it out.

D
_________________________
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
#184154 - 2007-12-21 07:57 PM Re: Read XML from web [Re: Darren_W]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well without using some type of other remote connection method the actual Web Server is not going to allow you to output that from a central location.

You might be able to modify registry settings etc to force it but then you also might be compromising security of the system.

If it HAS to be read via the Web Serving feature then you may have to look elsewhere than KiX as it has no intrinsic feature that I'm aware of to allow interfacing with a Web Server.

You can also read stuff using WMI if wanted, but I think you probably have something else in mind if the COM method isn't good for you and SMB isn't good for you. Not really sure what else to offer for your project.

There are some XML UDFs in the UDF forum you can look at and see if you can get them to do what you're wanting.

Top
#184162 - 2007-12-21 09:43 PM Re: Read XML from web [Re: NTDOC]
Arend_ Moderator Offline
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
 Code:
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
#184174 - 2007-12-22 04:41 AM Re: Read XML from web [Re: Arend_]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
I thought he said he didn't want to do it locally ? (didn't reread entire thread)
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.138 seconds in which 0.093 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org