|
|
|||||||
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> |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Have you compared files? Maybe one is unicode? |
||||||||
|
|
|||||||
Very weird, for the record I write all my code in notepad using ANSI. |
||||||||
|
|
|||||||
Both scripts work for me. |
||||||||
|
|
|||||||
Originally Posted By: apronk Very weird, for the record I write all my code in notepad using ANSI. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Hmmm... Dunno. Will check. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Could you add some @error @serror checks in the UDF's ? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Different system = same results. I'll do some searching on the error code and see what comes up. |
||||||||
|
|
|||||||
Has anyone got both scripts to work ok ? FYI - I'm running Windows XP SP1 (out-of-date I know, I know) ... |
||||||||
|
|
|||||||
I'd really try to install MSXML 6.0 anyway. Did the different system have 6.0 ? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Originally Posted By: apronk I'd really try to install MSXML 6.0 anyway. Did the different system have 6.0 ? Yeah 6.0 is on both systems. It just errors like I said above and then the installation stops. No option to continue. The error I got from the script seems to translate to error 3 - path not found. Getting sick of it or is it the chocolate I'm eating while testing and searching BTW: Running WinXp Pro SP. Fully updated. |
||||||||
|
|
|||||||
Change the @scriptdir to a hard path. no UNC :P |
||||||||
|
|
|||||||
God d#mn That did it I thought I had that at first. Guess not Will do some more testing and see if stuff keeps working. |
||||||||
|
|
|||||||
Hehe, at least it's solved now. |