I'm new to using xml files and the Xbasic that's used to mess with them and I need a little help.
What I'm trying to do is prepare a pdf file for a user to download. The actual long filename is a decoded hexadecimal path, the short filename being the hexadecimal equivalent to the version id number....USUALLY. However; sometimes (when that file doesn't exist) I'll have to look for the version ref number. Below is an example of when the version id number is not the proper file name.
Lets say I'm looking for the version 2 file. Well, the file path would end in "00000002.pdf". Unfortunately, that file doesn't actually exist so I will need to search the xml file to find out the "referenced file"
Here's an example of an xml file:
So, I need to sort through that and find out that even though I'm on version id 2, it's referencing version 1 of the file and the ending file path should really be "00000001.pdf"
It can get a little more complicated. Here is the XML file for a file that had a version 3 but was then "rolled back" to a version 2..
You can see that the reference is on the second to last instead of the last node
Basically, I need to search for the last occurrence of "version ref" in my xml file, read the value in it, and return that to my Xbasic.
Here was my first rendition, which I found worked in the case of the first xml file above but didn't work in the case of the second Xml file above because of how I was trying to find the reference number.
There's probably a really easy way to do this and I'm just missing it.
Any help is greatly appreciated.
Thanks!
What I'm trying to do is prepare a pdf file for a user to download. The actual long filename is a decoded hexadecimal path, the short filename being the hexadecimal equivalent to the version id number....USUALLY. However; sometimes (when that file doesn't exist) I'll have to look for the version ref number. Below is an example of when the version id number is not the proper file name.
Lets say I'm looking for the version 2 file. Well, the file path would end in "00000002.pdf". Unfortunately, that file doesn't actually exist so I will need to search the xml file to find out the "referenced file"
Here's an example of an xml file:
Code:
<?xml version="1.0"?> -<index version="9.0"> <filename>Part1.pdf</filename> <version date="2015-07-08 15:05:20" uid="210449" id="1"/> <version date="2015-07-08 15:05:22" uid="210521" id="2" ref="1"/> </index>
It can get a little more complicated. Here is the XML file for a file that had a version 3 but was then "rolled back" to a version 2..
Code:
<?xml version="1.0" ?> - <index version="9.0"> <filename>Part1.pdf</filename> <version id="1" uid="210449" date="2015-07-08 15:05:20" /> <version id="2" ref="1" uid="210521" date="2015-07-08 15:05:22" /> <version id="3" uid="212007" date="2015-07-08 15:12:48" /> </index>
Basically, I need to search for the last occurrence of "version ref" in my xml file, read the value in it, and return that to my Xbasic.
Here was my first rendition, which I found worked in the case of the first xml file above but didn't work in the case of the second Xml file above because of how I was trying to find the reference number.
Code:
dim jscmd as c DIM requester as C = a5ws_getcurrentuser() dim fileloc AS c = e.HexPath dim status AS c = e.Status dim fnam AS c = word(e.Filename,1,".") dim fext AS c = word(e.Filename,2,".") dim outfolder AS c = "C:\A5Webroot\DBW_Downloads" dim outfile AS c if file.exists(fileloc) = .f. then fileloc = left(fileloc,len(fileloc) - len(lastword(fileloc,chr(92)))) sm = xmlSchemaManager.Get() xml = get_from_file(fileloc +"index.xml") dom = sm.LoadXML(xml) dim ele as n = dom.all.size() if variable_exists("dom.all["+ele+"].attribute[2].Name") then if dom.all[ele].attribute[2].Name = "ref" then dim hxnm as n = Convert_Type(dom.all[ele].attribute[2].Value,"N") fileloc = fileloc + *to_hex(hxnm) + "." + fext end if end if end if
Any help is greatly appreciated.
Thanks!
Comment