Author Topic: XML Parser  (Read 638 times)

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #15 on: 04. July 2017, 08:41:17 »
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: 04. July 2017, 09:36:36 by John »

B+

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
Re: XML Parser
« Reply #16 on: 04. July 2017, 16:54:22 »
:) 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: 04. July 2017, 17:03:17 by B+ »

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #17 on: 04. July 2017, 19:28:01 »
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: 04. July 2017, 22:50:13 by John »

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #18 on: 08. July 2017, 08:01:58 »
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+

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
Re: XML Parser
« Reply #19 on: 08. July 2017, 16:43:17 »
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: 08. July 2017, 18:08:20 by B+ »

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #20 on: 08. July 2017, 19:36:50 »
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.

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #21 on: 09. July 2017, 19:51:38 »
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

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: XML Parser
« Reply #22 on: 09. July 2017, 21:53:17 »
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.

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #23 on: 09. July 2017, 23:45:20 »
Maybe not a good analogy but I don't think anyone would be interested in a Btrieve like file system these days.
« Last Edit: 10. July 2017, 06:08:21 by John »

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #24 on: 10. July 2017, 18:15:21 »
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.

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #25 on: 13. August 2017, 10:33:01 »
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: 13. August 2017, 10:35:48 by John »

John

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: XML Parser
« Reply #26 on: 18. August 2017, 08:02:20 »
I'm curious what web development interest is here on the forum? It seems Windows desktop is where BASIC calls home.


ZXDunny

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Re: XML Parser
« Reply #27 on: 18. August 2017, 12:33:19 »
I'm on a mac...