#175521 - 2007-04-20 10:16 AM
Reading XML file returns nothing
|
Mart
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?
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:
Function LoadXml($filename)
Dim $, $rootNode
$loadXml = CreateObject("Microsoft.XMLDOM");
If Not $loadXml
Return
EndIf
$= $loadXml.Load($filename)
EndFunction
ReadXMLValue UDF:
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:
<?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_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
I did the code like this and works fine:
$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
|
|
|
|
#175541 - 2007-04-20 03:40 PM
Re: Reading XML file returns nothing
[Re: Mart]
|
Arend_
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|