Page 1 of 2 12>
Topic Options
#175521 - 2007-04-20 10:16 AM Reading XML file returns nothing
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Guy's,

I'm trying to read an XML file with the code below. Unfortunately I get no results. All variables are empty. We have the same code in a different script that also reads an XML file and it works great. The XML encoding on both files is the same. Anyone got some bright ideas on this?

 Code:
Break on
Call @scriptdir + "\functions\LoadXML().udf"
Call @scriptdir + "\functions\ReadXMLValue().udf"

$xml = LoadXml(@SCRIPTDIR + "\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
Sleep 10


LoadXML UDF:
 Code:
Function LoadXml($filename)

Dim $, $rootNode
$loadXml = CreateObject("Microsoft.XMLDOM");
If Not $loadXml
	Return
EndIf

$= $loadXml.Load($filename)

EndFunction


ReadXMLValue UDF:
 Code:
Function ReadXmlValue($xml, $key, optional $defaultValue)

Dim $sectionNode
$sectionNode = $xml.SelectSingleNode($key);
If Not $sectionNode
	$ReadXmlValue = $defaultValue
Else
	$ReadXmlValue = $sectionNode.FirstChild.Text;
EndIf

EndFunction


XML File:
 Quote:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<stuff>
<morestuff>
<id>34538</id>
<name>name</name>
<gender>Male</gender>
<age>29</age>
<place>Amsterdam</place>
<province>Noord Holland</province>
<date_membership>18-april-2007</date_membership>
<url_profile>http://somesite</url_profile>
<url_photothumb>http://somesite.nl/someimage.jpg</url_photothumb>
<advert_title>Title</advert_title>
<advert_description>Description</advert_description>
</morestuff>
</stuff>


Edited by Mart (2007-04-20 10:17 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175525 - 2007-04-20 12:56 PM Re: Reading XML file returns nothing [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
I did the code like this and works fine:
 Code:
$xml = LoadXml(@SCRIPTDIR + "\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

Top
#175528 - 2007-04-20 02:13 PM Re: Reading XML file returns nothing [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Wierd

Copied your exact code and ran it. No luck, all vars are still empty. Doing a LEN() on them also shows a length of 0. Its extra weird because the exact same stuff runs on an other XML file and returns the values just fine.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175530 - 2007-04-20 02:20 PM Re: Reading XML file returns nothing [Re: Mart]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Have you compared files? Maybe one is unicode?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#175531 - 2007-04-20 02:34 PM Re: Reading XML file returns nothing [Re: Les]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Very weird, for the record I write all my code in notepad using ANSI.
Top
#175532 - 2007-04-20 02:47 PM Re: Reading XML file returns nothing [Re: Arend_]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Both scripts work for me.
Top
#175533 - 2007-04-20 02:49 PM Re: Reading XML file returns nothing [Re: Arend_]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: apronk
Very weird, for the record I write all my code in notepad using ANSI.
I meant the XML files.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#175534 - 2007-04-20 02:57 PM Re: Reading XML file returns nothing [Re: Les]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Should make sure "C:\WINDOWS\system32\msxml3.dll" is fully registered.
Also, like I said b4 make sure the XML file is in ANSI as well.

Top
#175535 - 2007-04-20 03:00 PM Re: Reading XML file returns nothing [Re: Les]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hmmm... Dunno. Will check.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175536 - 2007-04-20 03:04 PM Re: Reading XML file returns nothing [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: apronk
Very weird, for the record I write all my code in notepad using ANSI.


Code is written in ASE. XML is supplied by the customer.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175539 - 2007-04-20 03:36 PM Re: Reading XML file returns nothing [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Could you add some @error @serror checks in the UDF's ?
Top
#175540 - 2007-04-20 03:37 PM Re: Reading XML file returns nothing [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: apronk
Should make sure "C:\WINDOWS\system32\msxml3.dll" is fully registered.
Also, like I said b4 make sure the XML file is in ANSI as well.


Yep, msxml3.dll is registered and I saved the file with a different name and as ANSI from notepad.
Still no luck. Will keep on searching.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175541 - 2007-04-20 03:40 PM Re: Reading XML file returns nothing [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Could you install this: MSXML 6.0 Change it to Dutch if your OS is dutch.

Btw, seeying as you are from Rotterdam yourself imma forgive you for putting "Amsterdam" in the xml ;\)

Top
#175542 - 2007-04-20 03:47 PM Re: Reading XML file returns nothing [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: apronk
Could you add some @error @serror checks in the UDF's ?


Allrightie then.
Found something I guess. Just dunno what to do with it \:\(
Changed the ReadXmlValue UDF and added some error checking.

 Code:
Function ReadXmlValue($xml, $key, optional $defaultValue)
	Dim $sectionNode
	$sectionNode = $xml.SelectSingleNode($key)
	If Not $sectionNode
		??@ERROR
		?@SERROR
		?"Not section node"
		Sleep 0.5
		$ReadXmlValue = $defaultValue
	Else
		??@ERROR
		?@SERROR
		?"Section node"
		Sleep 0.5
		$ReadXmlValue = $sectionNode.FirstChild.Text;
	EndIf
EndFunction


Returs this:
 Code:
-2147352573
Member not found.
Not section node


Edited by Mart (2007-04-20 03:56 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175543 - 2007-04-20 03:55 PM Re: Reading XML file returns nothing [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: apronk
Could you install this: MSXML 6.0 Change it to Dutch if your OS is dutch.

Btw, seeying as you are from Rotterdam yourself imma forgive you for putting "Amsterdam" in the xml ;\)


A higher version is already installed on my system comes up when I try to install this.

BTW: You don’t want to know what is really in the XML file. I changed the data between the XML tags (not the tags itself) because they are erotic ads that we process for our customer and could/should get censored by the board.


Edited by Mart (2007-04-20 03:56 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175544 - 2007-04-20 03:59 PM Re: Reading XML file returns nothing [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Could you try it on a different machine then ? I'm betting this has to do with your MSXML version. 6.0 is the latest provided by MS.
Top
#175545 - 2007-04-20 04:12 PM Re: Reading XML file returns nothing [Re: Arend_]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Different system = same results.

I'll do some searching on the error code and see what comes up.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175546 - 2007-04-20 04:15 PM Re: Reading XML file returns nothing [Re: Mart]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Has anyone got both scripts to work ok ? FYI - I'm running Windows XP SP1 (out-of-date I know, I know) ...
Top
#175547 - 2007-04-20 04:16 PM Re: Reading XML file returns nothing [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
I'd really try to install MSXML 6.0 anyway. Did the different system have 6.0 ?
Top
#175548 - 2007-04-20 04:17 PM Re: Reading XML file returns nothing [Re: Shawn]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
 Originally Posted By: Shawn
Has anyone got both scripts to work ok ? FYI - I'm running Windows XP SP1 (out-of-date I know, I know) ...


Hey Shawn, yeah both work ok on my system.
I'm on SP2 with all updates installed.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

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