Author Topic: XML Parser  (Read 4645 times)

ScriptBasic

  • Guest
Re: XML Parser
« Reply #15 on: July 04, 2017, 06:41:17 AM »
That sounds like the Script BASIC HASH extension module functionality.

Or you could use an associative array as a hash.

Code: [Select]
dict{"A"} = 1
dict{"B"} = "bee"
dict{"C"} = "sea"

FOR x = 0 TO UBOUND(dict) STEP 2
  PRINT "Key = ",dict[x],"  Value = ",dict[x+1],"\n"
NEXT

b = "B"
PRINT dict{b},"\n"


jrs@jrs-laptop:~/sb/examples/test$ scriba assray.sb
Key = A  Value = 1
Key = B  Value = bee
Key = C  Value = sea
bee
jrs@jrs-laptop:~/sb/examples/test$
« Last Edit: July 04, 2017, 07:36:36 AM by John »

B+

  • Guest
Re: XML Parser
« Reply #16 on: July 04, 2017, 02:54:22 PM »
:) Yes, that's the idea!

Can you reverse the process eg list all the keys that have the value "bee" or LIKE "bee" in different ways?

BTW, nice Help Link "HASH", I should read it before asking questions ;-))
« Last Edit: July 04, 2017, 03:03:17 PM by B+ »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #17 on: July 04, 2017, 05:28:01 PM »
Something LIKE this?

Code: [Select]
dict{"A"} = 1
dict{"B"} = "bee"
dict{"C"} = "sea"
dict{"D"} = "peebee"

FOR x = 0 TO UBOUND(dict) STEP 2
  IF dict[x+1] = "bee" OR dict[x+1] LIKE "*bee" THEN PRINT "Found: Key = ",dict[x],"  ",dict[x+1],"\n"
NEXT


jrs@jrs-laptop:~/sb/examples/test$ time scriba findval.sb
Found: Key = B  bee
Found: Key = D  peebee

real   0m0.005s
user   0m0.004s
sys   0m0.000s
jrs@jrs-laptop:~/sb/examples/test$


I had added Array Sort to the T(ools) extension module but it can only sort one index at a time and removes duplicate values.



« Last Edit: July 04, 2017, 08:50:13 PM by John »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #18 on: July 08, 2017, 06:01:58 AM »
I had an idea of using an associative array as a keyed file system index with Script BASIC's record based file I/O. The only thing I'm missing is a way to traverse the keys in sorted order forward and back. Direct key access is already covered. Any ideas?

B+

  • Guest
Re: XML Parser
« Reply #19 on: July 08, 2017, 02:43:17 PM »
I had an idea of using an associative array as a keyed file system index with Script BASIC's record based file I/O. The only thing I'm missing is a way to traverse the keys in sorted order forward and back. Direct key access is already covered. Any ideas?

Hi John,

If your inquiry is addressed to me, I have to say sorry there are too many technical phrases in the above quote that are not part of my experience to give ideas.

I have heard of this term: "associative array", interestingly enough, from someone at FB forum who was commenting on something they found at ScriptBasic forum.

"a keyed file system index"
"Script BASIC's record based file I/O"
"traverse the keys in sorted order forward and back"

Jargon talk Yikes! but I will take a stab at last item with a question.

Isn't the point of a key / value structure (like a hash table?) to get away from having to sort things out?

 
APPEND: Dang! I missed your July 4 EDIT, the above reply was made not having read the new link in that edit.
« Last Edit: July 08, 2017, 04:08:20 PM by B+ »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #20 on: July 08, 2017, 05:36:50 PM »
I think I can use my array sort function to create indexes for the records in the file. I'll post something soon to show what I'm talking about.

FYI - Hash tables / Associative arrays are in the order they were entered. I'll have a primary sorted index which is based on the associative element. (key) Other indexes could be built from fields in the data file record.

ScriptBasic

  • Guest
Re: XML Parser
« Reply #21 on: July 09, 2017, 05:51:38 PM »
On second thought trying to recreate an ISAM keyed file system is like trying to keep Z80 programming alive. SQLite is all you need for a local DB solution,

Associative arrays or a combination of both can create some powerful matrices to work with non-normalized data sets.

ZXDunny

  • Guest
Re: XML Parser
« Reply #22 on: July 09, 2017, 07:53:17 PM »
On second thought trying to recreate an ISAM keyed file system is like trying to keep Z80 programming alive.

I don't think there's any effort in that at all - z80 programming is very much alive and well on various platforms - both retro and embedded. z80 CPUs are still being manufactured.

ScriptBasic

  • Guest
Re: XML Parser
« Reply #23 on: July 09, 2017, 09:45:20 PM »
Maybe not a good analogy but I don't think anyone would be interested in a Btrieve like file system these days.
« Last Edit: July 10, 2017, 04:08:21 AM by John »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #24 on: July 10, 2017, 04:15:21 PM »
To get back on topic, I feel the Script BASIC SPLITA and LIKE combo makes for a great lightweight XML parsing solution. My next goal is to get this to work with JSON.

ScriptBasic

  • Guest
Re: XML Parser
« Reply #25 on: August 13, 2017, 08:33:01 AM »
Here is an example of transforming the QuickBooks Online Apps Directory to a simple table list using the Script BASIC application proxy server.

Code: [Select]
' QBO Apps List

IMPORT cgi.bas
IMPORT curl.bas

ch = curl::init()
curl::option(ch,"URL","https://appcenter.intuit.com/allapps")
apps_html = curl::perform(ch)
curl::finish(ch)

cgi::Header 200,"text/html"
cgi::FinishHeader

PRINT """
<html>
<body>
<table>
<center><h1>QBO Apps Listing</h1></center>
<table style="width:100%">
  <tr>
    <th>App Name</th>
    <th>Vendor</th>
    <th>Description</th>
  </tr>
"""

SPLITA apps_html BY "<!-- this is for SEO crawlers -->" TO apps_array

FOR x = 0 TO UBOUND(apps_array)
  IF apps_array[x] LIKE """*<div class="bigappcard-display-name">*</div>*<div class="bigappcard-vendor-name">*</div>*<div class="bigappcard-tagline">*</div>*""" THEN
    PRINT "  <tr>\n"
    PRINT "    <td>",TRIM(joker(2)),"</td>\n"
    PRINT "    <td>",MID(TRIM(joker(4)),4),"</td>\n"
    PRINT "    <td>",TRIM(joker(6)),"</td>\n"
    PRINT "  </tr>\n"
  END IF
NEXT
PRINT """
</table>
</body>
</html>
"""


« Last Edit: August 13, 2017, 08:35:48 AM by John »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #26 on: August 18, 2017, 06:02:20 AM »
I'm curious what web development interest is here on the forum? It seems Windows desktop is where BASIC calls home.


ZXDunny

  • Guest
Re: XML Parser
« Reply #27 on: August 18, 2017, 10:33:19 AM »
I'm on a mac...