Author Topic: XML Parser  (Read 4611 times)

ScriptBasic

  • Guest
XML Parser
« on: June 28, 2017, 05:52:28 PM »
It's been awhile since we had a code challenge here on the forum. I would like to propose a code challenge to parse XML content and extract the data. I've attached a G/L Accounts XML file that is the response from a query to a QuickBooks Online developer sandbox company.

The goal is to extract the <Id>, <Name>, <AccountType> and  <CurrentBalance> as a list.


« Last Edit: June 29, 2017, 05:37:00 AM by John »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #1 on: June 29, 2017, 03:33:04 AM »
As motivation, here is the parsed results in a Script BASIC application server web page.

This example actually gets the data from QuickBooks Online, extracts the data from the XML response and creates a HTML table from it.

QBO Account Listing

« Last Edit: June 29, 2017, 04:13:48 AM by John »

B+

  • Guest
Re: XML Parser
« Reply #2 on: June 29, 2017, 05:10:44 AM »
Code: [Select]
tload "acct_all.txt",all,2:dim f(3),a():f(0)="<Id>":f(1)="<Name>":f(2)="<AccountType>":f(3)="<CurrentBalance>":p=1:s=""
label loop:for i = 0 to 3 : ip = instr(p, all, f(i))
if ip then s += mid(all, ip, instr(ip + len(f(i)), all, "<") - ip) + "  " else tsave "acct_list.txt", a : end
p = instr(ip + len(f(i)) + 1, all, "<") : next : a << s + chr(13) : s = "" : goto loop

Code: [Select]
<Id>33  <Name>Accounts Payable (A/P)  <AccountType>Accounts Payable  <CurrentBalance>-1602.67 
<Id>84  <Name>Accounts Receivable (A/R)  <AccountType>Accounts Receivable  <CurrentBalance>5281.52 
<Id>7  <Name>Advertising  <AccountType>Expense  <CurrentBalance>0 
<Id>89  <Name>Arizona Dept. of Revenue Payable  <AccountType>Other Current Liability  <CurrentBalance>0 
<Id>55  <Name>Automobile  <AccountType>Expense  <CurrentBalance>0 
<Id>56  <Name>Fuel  <AccountType>Expense  <CurrentBalance>0 
<Id>8  <Name>Bank Charges  <AccountType>Expense  <CurrentBalance>0 
<Id>85  <Name>Billable Expense Income  <AccountType>Income  <CurrentBalance>0 
<Id>90  <Name>Board of Equalization Payable  <AccountType>Other Current Liability  <CurrentBalance>-370.94 
<Id>35  <Name>Checking  <AccountType>Bank  <CurrentBalance>1201.00 
<Id>9  <Name>Commissions &amp; fees  <AccountType>Expense  <CurrentBalance>0 
<Id>80  <Name>Cost of Goods Sold  <AccountType>Cost of Goods Sold  <CurrentBalance>0 
<Id>40  <Name>Depreciation  <AccountType>Other Expense  <CurrentBalance>0 
<Id>82  <Name>Design income  <AccountType>Income  <CurrentBalance>0 
<Id>86  <Name>Discounts given  <AccountType>Income  <CurrentBalance>0 
<Id>28  <Name>Disposal Fees  <AccountType>Expense  <CurrentBalance>0 
<Id>10  <Name>Dues &amp; Subscriptions  <AccountType>Expense  <CurrentBalance>0 
<Id>29  <Name>Equipment Rental  <AccountType>Expense  <CurrentBalance>0 
<Id>5  <Name>Fees Billed  <AccountType>Income  <CurrentBalance>0 
<Id>11  <Name>Insurance  <AccountType>Expense  <CurrentBalance>0 
<Id>57  <Name>Workers Compensation  <AccountType>Expense  <CurrentBalance>0 
<Id>25  <Name>Interest Earned  <AccountType>Other Income  <CurrentBalance>0 
<Id>81  <Name>Inventory Asset  <AccountType>Other Current Asset  <CurrentBalance>596.25 
<Id>58  <Name>Job Expenses  <AccountType>Expense  <CurrentBalance>0 
<Id>59  <Name>Cost of Labor  <AccountType>Expense  <CurrentBalance>0 
<Id>60  <Name>Installation  <AccountType>Expense  <CurrentBalance>0 
<Id>61  <Name>Maintenance and Repairs  <AccountType>Expense  <CurrentBalance>0 
<Id>62  <Name>Equipment Rental  <AccountType>Expense  <CurrentBalance>0 
<Id>63  <Name>Job Materials  <AccountType>Expense  <CurrentBalance>0 
<Id>64  <Name>Decks and Patios  <AccountType>Expense  <CurrentBalance>0 
<Id>65  <Name>Fountain and Garden Lighting  <AccountType>Expense  <CurrentBalance>0 
<Id>66  <Name>Plants and Soil  <AccountType>Expense  <CurrentBalance>0 
<Id>67  <Name>Sprinklers and Drip Systems  <AccountType>Expense  <CurrentBalance>0 
<Id>68  <Name>Permits  <AccountType>Expense  <CurrentBalance>0 
<Id>45  <Name>Landscaping Services  <AccountType>Income  <CurrentBalance>0 
<Id>46  <Name>Job Materials  <AccountType>Income  <CurrentBalance>0 
<Id>47  <Name>Decks and Patios  <AccountType>Income  <CurrentBalance>0 
<Id>48  <Name>Fountains and Garden Lighting  <AccountType>Income  <CurrentBalance>0 
<Id>49  <Name>Plants and Soil  <AccountType>Income  <CurrentBalance>0 
<Id>50  <Name>Sprinklers and Drip Systems  <AccountType>Income  <CurrentBalance>0 
<Id>51  <Name>Labor  <AccountType>Income  <CurrentBalance>0 
<Id>52  <Name>Installation  <AccountType>Income  <CurrentBalance>0 
<Id>53  <Name>Maintenance and Repair  <AccountType>Income  <CurrentBalance>0 
<Id>12  <Name>Legal &amp; Professional Fees  <AccountType>Expense  <CurrentBalance>0 
<Id>69  <Name>Accounting  <AccountType>Expense  <CurrentBalance>0 
<Id>70  <Name>Bookkeeper  <AccountType>Expense  <CurrentBalance>0 
<Id>71  <Name>Lawyer  <AccountType>Expense  <CurrentBalance>0 
<Id>43  <Name>Loan Payable  <AccountType>Other Current Liability  <CurrentBalance>-4000.00 
<Id>72  <Name>Maintenance and Repair  <AccountType>Expense  <CurrentBalance>0 
<Id>73  <Name>Building Repairs  <AccountType>Expense  <CurrentBalance>0 
<Id>74  <Name>Computer Repairs  <AccountType>Expense  <CurrentBalance>0 
<Id>75  <Name>Equipment Repairs  <AccountType>Expense  <CurrentBalance>0 
<Id>41  <Name>Mastercard  <AccountType>Credit Card  <CurrentBalance>-157.72 
<Id>13  <Name>Meals and Entertainment  <AccountType>Expense  <CurrentBalance>0 
<Id>14  <Name>Miscellaneous  <AccountType>Other Expense  <CurrentBalance>0 
<Id>91  <Name>MyClients  <AccountType>Accounts Receivable  <CurrentBalance>0 
<Id>44  <Name>Notes Payable  <AccountType>Long Term Liability  <CurrentBalance>-25000.00 
<Id>15  <Name>Office Expenses  <AccountType>Expense  <CurrentBalance>0 
<Id>34  <Name>Opening Balance Equity  <AccountType>Equity  <CurrentBalance>9337.50 
<Id>83  <Name>Other Income  <AccountType>Income  <CurrentBalance>0 
<Id>26  <Name>Other Portfolio Income  <AccountType>Other Income  <CurrentBalance>0 
<Id>27  <Name>Penalties &amp; Settlements  <AccountType>Other Expense  <CurrentBalance>0 
<Id>54  <Name>Pest Control Services  <AccountType>Income  <CurrentBalance>0 
<Id>3  <Name>Prepaid Expenses  <AccountType>Other Current Asset  <CurrentBalance>0 
<Id>16  <Name>Promotional  <AccountType>Expense  <CurrentBalance>0 
<Id>78  <Name>Purchases  <AccountType>Expense  <CurrentBalance>0 
<Id>6  <Name>Refunds-Allowances  <AccountType>Income  <CurrentBalance>0 
<Id>17  <Name>Rent or Lease  <AccountType>Expense  <CurrentBalance>0 
<Id>2  <Name>Retained Earnings  <AccountType>Equity  <CurrentBalance>0 
<Id>79  <Name>Sales of Product Income  <AccountType>Income  <CurrentBalance>0 
<Id>36  <Name>Savings  <AccountType>Bank  <CurrentBalance>800.00 
<Id>1  <Name>Services  <AccountType>Income  <CurrentBalance>0 
<Id>19  <Name>Stationery &amp; Printing  <AccountType>Expense  <CurrentBalance>0 
<Id>20  <Name>Supplies  <AccountType>Expense  <CurrentBalance>0 
<Id>21  <Name>Taxes &amp; Licenses  <AccountType>Expense  <CurrentBalance>0 
<Id>22  <Name>Travel  <AccountType>Expense  <CurrentBalance>0 
<Id>23  <Name>Travel Meals  <AccountType>Expense  <CurrentBalance>0 
<Id>37  <Name>Truck  <AccountType>Fixed Asset  <CurrentBalance>0 
<Id>39  <Name>Depreciation  <AccountType>Fixed Asset  <CurrentBalance>0 
<Id>38  <Name>Original Cost  <AccountType>Fixed Asset  <CurrentBalance>13495.00 
<Id>88  <Name>Unapplied Cash Bill Payment Expense  <AccountType>Expense  <CurrentBalance>0 
<Id>87  <Name>Unapplied Cash Payment Income  <AccountType>Income  <CurrentBalance>0 
<Id>32  <Name>Uncategorized Asset  <AccountType>Other Current Asset  <CurrentBalance>0 
<Id>31  <Name>Uncategorized Expense  <AccountType>Expense  <CurrentBalance>0 
<Id>30  <Name>Uncategorized Income  <AccountType>Income  <CurrentBalance>0 
<Id>4  <Name>Undeposited Funds  <AccountType>Other Current Asset  <CurrentBalance>2062.52 
<Id>24  <Name>Utilities  <AccountType>Expense  <CurrentBalance>0 
<Id>76  <Name>Gas and Electric  <AccountType>Expense  <CurrentBalance>0 
<Id>77  <Name>Telephone  <AccountType>Expense  <CurrentBalance>0 
<Id>42  <Name>Visa  <AccountType>Credit Card  <CurrentBalance>0 

B+

  • Guest
Re: XML Parser
« Reply #3 on: June 29, 2017, 05:41:38 AM »
Without tags:
Code: [Select]
tload "acct_all.txt",all,2:dim f(3),a():f(0)="<Id>":f(1)="<Name>":f(2)="<AccountType>":f(3)="<CurrentBalance>":p=1:s=""
label loop:for i = 0 to 3 : ip = instr(p, all, f(i))
if ip then s+=left(mid(all,ip+len(f(i)),instr(ip+len(f(i)),all,"<")-(ip+len(f(i))))+space(40),40) else tsave "lst.rtf",a:end
p = instr(ip + len(f(i)) + 1, all, "<") : next : a << s + chr(13) : s = "" : goto loop

Code: [Select]
33                                      Accounts Payable (A/P)                  Accounts Payable                        -1602.67                               
84                                      Accounts Receivable (A/R)               Accounts Receivable                     5281.52                                 
7                                       Advertising                             Expense                                 0                                       
89                                      Arizona Dept. of Revenue Payable        Other Current Liability                 0                                       
55                                      Automobile                              Expense                                 0                                       
56                                      Fuel                                    Expense                                 0                                       
8                                       Bank Charges                            Expense                                 0                                       
85                                      Billable Expense Income                 Income                                  0                                       
90                                      Board of Equalization Payable           Other Current Liability                 -370.94                                 
35                                      Checking                                Bank                                    1201.00                                 
9                                       Commissions &amp; fees                  Expense                                 0                                       
80                                      Cost of Goods Sold                      Cost of Goods Sold                      0                                       
40                                      Depreciation                            Other Expense                           0                                       
82                                      Design income                           Income                                  0                                       
86                                      Discounts given                         Income                                  0                                       
28                                      Disposal Fees                           Expense                                 0                                       
10                                      Dues &amp; Subscriptions                Expense                                 0                                       
29                                      Equipment Rental                        Expense                                 0                                       
5                                       Fees Billed                             Income                                  0                                       
11                                      Insurance                               Expense                                 0                                       
57                                      Workers Compensation                    Expense                                 0                                       
25                                      Interest Earned                         Other Income                            0                                       
81                                      Inventory Asset                         Other Current Asset                     596.25                                 
58                                      Job Expenses                            Expense                                 0                                       
59                                      Cost of Labor                           Expense                                 0                                       
60                                      Installation                            Expense                                 0                                       
61                                      Maintenance and Repairs                 Expense                                 0                                       
62                                      Equipment Rental                        Expense                                 0                                       
63                                      Job Materials                           Expense                                 0                                       
64                                      Decks and Patios                        Expense                                 0                                       
65                                      Fountain and Garden Lighting            Expense                                 0                                       
66                                      Plants and Soil                         Expense                                 0                                       
67                                      Sprinklers and Drip Systems             Expense                                 0                                       
68                                      Permits                                 Expense                                 0                                       
45                                      Landscaping Services                    Income                                  0                                       
46                                      Job Materials                           Income                                  0                                       
47                                      Decks and Patios                        Income                                  0                                       
48                                      Fountains and Garden Lighting           Income                                  0                                       
49                                      Plants and Soil                         Income                                  0                                       
50                                      Sprinklers and Drip Systems             Income                                  0                                       
51                                      Labor                                   Income                                  0                                       
52                                      Installation                            Income                                  0                                       
53                                      Maintenance and Repair                  Income                                  0                                       
12                                      Legal &amp; Professional Fees           Expense                                 0                                       
69                                      Accounting                              Expense                                 0                                       
70                                      Bookkeeper                              Expense                                 0                                       
71                                      Lawyer                                  Expense                                 0                                       
43                                      Loan Payable                            Other Current Liability                 -4000.00                               
72                                      Maintenance and Repair                  Expense                                 0                                       
73                                      Building Repairs                        Expense                                 0                                       
74                                      Computer Repairs                        Expense                                 0                                       
75                                      Equipment Repairs                       Expense                                 0                                       
41                                      Mastercard                              Credit Card                             -157.72                                 
13                                      Meals and Entertainment                 Expense                                 0                                       
14                                      Miscellaneous                           Other Expense                           0                                       
91                                      MyClients                               Accounts Receivable                     0                                       
44                                      Notes Payable                           Long Term Liability                     -25000.00                               
15                                      Office Expenses                         Expense                                 0                                       
34                                      Opening Balance Equity                  Equity                                  9337.50                                 
83                                      Other Income                            Income                                  0                                       
26                                      Other Portfolio Income                  Other Income                            0                                       
27                                      Penalties &amp; Settlements             Other Expense                           0                                       
54                                      Pest Control Services                   Income                                  0                                       
3                                       Prepaid Expenses                        Other Current Asset                     0                                       
16                                      Promotional                             Expense                                 0                                       
78                                      Purchases                               Expense                                 0                                       
6                                       Refunds-Allowances                      Income                                  0                                       
17                                      Rent or Lease                           Expense                                 0                                       
2                                       Retained Earnings                       Equity                                  0                                       
79                                      Sales of Product Income                 Income                                  0                                       
36                                      Savings                                 Bank                                    800.00                                 
1                                       Services                                Income                                  0                                       
19                                      Stationery &amp; Printing               Expense                                 0                                       
20                                      Supplies                                Expense                                 0                                       
21                                      Taxes &amp; Licenses                    Expense                                 0                                       
22                                      Travel                                  Expense                                 0                                       
23                                      Travel Meals                            Expense                                 0                                       
37                                      Truck                                   Fixed Asset                             0                                       
39                                      Depreciation                            Fixed Asset                             0                                       
38                                      Original Cost                           Fixed Asset                             13495.00                               
88                                      Unapplied Cash Bill Payment Expense     Expense                                 0                                       
87                                      Unapplied Cash Payment Income           Income                                  0                                       
32                                      Uncategorized Asset                     Other Current Asset                     0                                       
31                                      Uncategorized Expense                   Expense                                 0                                       
30                                      Uncategorized Income                    Income                                  0                                       
4                                       Undeposited Funds                       Other Current Asset                     2062.52                                 
24                                      Utilities                               Expense                                 0                                       
76                                      Gas and Electric                        Expense                                 0                                       
77                                      Telephone                               Expense                                 0                                       
42                                      Visa                                    Credit Card                             0                                       
                           
« Last Edit: June 29, 2017, 05:45:15 AM by B+ »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #4 on: June 29, 2017, 05:41:46 AM »
B+,

Here is my Script BASIC console mode version.

Code: [Select]
' QBO Account Table Listing

OPEN "acct_all.txt" FOR INPUT AS 1
qboxml = INPUT(LOF(1),1)

SPLITA qboxml BY "</Account>" TO accts

FOR x = 0 TO UBOUND(accts)
  IF  accts[x] LIKE "*<Id>*</Id>*<Name>*</Name>*<AccountType>*</AccountType>*<CurrentBalance>*</CurrentBalance>*" THEN
    PRINT joker(2),STRING(7-LEN(joker(2))," ")
    PRINT joker(4),STRING(40-LEN(joker(4))," ")
    PRINT joker(6),STRING(25-LEN(joker(6))," ")
    PRINT FORMAT("%~###,###.00-~",joker(8)),"\n"
  END IF
NEXT


jrs@jrs-laptop:~/work/Finch/sb/test$ time scriba qbo_acct.sb
33     Accounts Payable (A/P)                  Accounts Payable           1,602.67-       
84     Accounts Receivable (A/R)               Accounts Receivable        5,281.52         
7      Advertising                             Expense                        0.00               
89     Arizona Dept. of Revenue Payable        Other Current Liability        0.00               
55     Automobile                              Expense                        0.00               
56     Fuel                                    Expense                        0.00               
8      Bank Charges                            Expense                        0.00               
85     Billable Expense Income                 Income                         0.00               
90     Board of Equalization Payable           Other Current Liability      370.94-       
35     Checking                                Bank                       1,201.00         
9      Commissions &amp; fees                  Expense                        0.00               
80     Cost of Goods Sold                      Cost of Goods Sold             0.00               
40     Depreciation                            Other Expense                  0.00               
82     Design income                           Income                         0.00               
86     Discounts given                         Income                         0.00               
28     Disposal Fees                           Expense                        0.00               
10     Dues &amp; Subscriptions                Expense                        0.00               
29     Equipment Rental                        Expense                        0.00               
5      Fees Billed                             Income                         0.00               
11     Insurance                               Expense                        0.00               
57     Workers Compensation                    Expense                        0.00               
25     Interest Earned                         Other Income                   0.00               
81     Inventory Asset                         Other Current Asset          596.25         
58     Job Expenses                            Expense                        0.00               
59     Cost of Labor                           Expense                        0.00               
60     Installation                            Expense                        0.00               
61     Maintenance and Repairs                 Expense                        0.00               
62     Equipment Rental                        Expense                        0.00               
63     Job Materials                           Expense                        0.00               
64     Decks and Patios                        Expense                        0.00               
65     Fountain and Garden Lighting            Expense                        0.00               
66     Plants and Soil                         Expense                        0.00               
67     Sprinklers and Drip Systems             Expense                        0.00               
68     Permits                                 Expense                        0.00               
45     Landscaping Services                    Income                         0.00               
46     Job Materials                           Income                         0.00               
47     Decks and Patios                        Income                         0.00               
48     Fountains and Garden Lighting           Income                         0.00               
49     Plants and Soil                         Income                         0.00               
50     Sprinklers and Drip Systems             Income                         0.00               
51     Labor                                   Income                         0.00               
52     Installation                            Income                         0.00               
53     Maintenance and Repair                  Income                         0.00               
12     Legal &amp; Professional Fees           Expense                        0.00               
69     Accounting                              Expense                        0.00               
70     Bookkeeper                              Expense                        0.00               
71     Lawyer                                  Expense                        0.00               
43     Loan Payable                            Other Current Liability    4,000.00-       
72     Maintenance and Repair                  Expense                        0.00               
73     Building Repairs                        Expense                        0.00               
74     Computer Repairs                        Expense                        0.00               
75     Equipment Repairs                       Expense                        0.00               
41     Mastercard                              Credit Card                  157.72-       
13     Meals and Entertainment                 Expense                        0.00               
14     Miscellaneous                           Other Expense                  0.00               
91     MyClients                               Accounts Receivable            0.00               
44     Notes Payable                           Long Term Liability       25,000.00-     
15     Office Expenses                         Expense                        0.00               
34     Opening Balance Equity                  Equity                     9,337.50         
83     Other Income                            Income                         0.00               
26     Other Portfolio Income                  Other Income                   0.00               
27     Penalties &amp; Settlements             Other Expense                  0.00               
54     Pest Control Services                   Income                         0.00               
3      Prepaid Expenses                        Other Current Asset            0.00               
16     Promotional                             Expense                        0.00               
78     Purchases                               Expense                        0.00               
6      Refunds-Allowances                      Income                         0.00               
17     Rent or Lease                           Expense                        0.00               
2      Retained Earnings                       Equity                         0.00               
79     Sales of Product Income                 Income                         0.00               
36     Savings                                 Bank                         800.00         
1      Services                                Income                         0.00               
19     Stationery &amp; Printing               Expense                        0.00               
20     Supplies                                Expense                        0.00               
21     Taxes &amp; Licenses                    Expense                        0.00               
22     Travel                                  Expense                        0.00               
23     Travel Meals                            Expense                        0.00               
37     Truck                                   Fixed Asset                    0.00               
39     Depreciation                            Fixed Asset                    0.00               
38     Original Cost                           Fixed Asset               13,495.00       
88     Unapplied Cash Bill Payment Expense     Expense                        0.00               
87     Unapplied Cash Payment Income           Income                         0.00               
32     Uncategorized Asset                     Other Current Asset            0.00               
31     Uncategorized Expense                   Expense                        0.00               
30     Uncategorized Income                    Income                         0.00               
4      Undeposited Funds                       Other Current Asset        2,062.52         
24     Utilities                               Expense                        0.00               
76     Gas and Electric                        Expense                        0.00               
77     Telephone                               Expense                        0.00               
42     Visa                                    Credit Card                    0.00               

real   0m0.022s
user   0m0.020s
sys   0m0.000s
jrs@jrs-laptop:~/work/Finch/sb/test$

« Last Edit: June 29, 2017, 07:13:29 AM by John »

B+

  • Guest
Re: XML Parser
« Reply #5 on: June 29, 2017, 05:48:50 AM »
Hi John,

I like your format better!

Oh, LIKE, yes good.

ScriptBasic

  • Guest
Re: XML Parser
« Reply #6 on: July 02, 2017, 02:43:45 AM »
I guess the days of code challenges are gone. Thanks B+ for your efforts.


B+

  • Guest
Re: XML Parser
« Reply #7 on: July 02, 2017, 11:32:04 AM »
Hey John,

After this challenge, I pulled out some code that was sitting on shelf for three months and finished it.
This challenge helped me clarify what I wanted that code to do.

So you never know what may become of an effort. ;)

And of course, I am always a fan of different ways to do something or how it might be done in different flavors or PLs.


« Last Edit: July 02, 2017, 11:35:14 AM by B+ »

ScriptBasic

  • Guest
Re: XML Parser
« Reply #8 on: July 02, 2017, 04:46:41 PM »
Quote
So you never know what may become of an effort.

Good to hear. I feel my time invested wasn't a wasted effort.

Maybe we'll see a B+ LIKE function for SmallBASIC materialize.

« Last Edit: July 02, 2017, 04:48:56 PM by John »

B+

  • Guest
Re: XML Parser
« Reply #9 on: July 02, 2017, 05:35:38 PM »
 :) Yes, you might see a Python like dictionary SIM using the LIKE keyword.


ScriptBasic

  • Guest
Re: XML Parser
« Reply #10 on: July 02, 2017, 06:33:56 PM »
I could never get my arms around regex as LIKE seems to handle most of my patten matching tasks.

ScriptBasic

  • Guest
Re: XML Parser
« Reply #11 on: July 03, 2017, 06:15:05 AM »
Quote
Yes, you might see a Python like dictionary SIM using the LIKE keyword.

Can you expand on that?

File directory? What does Python bring to the table?

ScriptBasic

  • Guest
Re: XML Parser
« Reply #12 on: July 03, 2017, 06:45:12 AM »
Maybe we should change direction with this thread and make the challenge writing a LIKE function in BASIC.  :D

Hopefully someone will come up with a better name than JOKER.

BTW The Script BASIC LIKE can be either case sensitive (default) or case insensitive.
« Last Edit: July 03, 2017, 06:57:33 AM by John »

B+

  • Guest
Re: XML Parser
« Reply #13 on: July 03, 2017, 01:34:37 PM »
Code: [Select]
' like test.bas SmallBASIC 0.12.9 (B+=MGA) 2017-07-03
dim hello(), world()
open "Word List.txt" for input as #1
while eof(1)=0
  lineinput #1, fline
  two = left(fline,2)
  if two <> lasttwo then
    locate 1, 1 : ? space(20) : locate 1, 1 : ? two : lasttwo = two
  fi
  if fline like "h*" then
    if fline like "h?ll?" then hello << fline : ? fline
  elif fline like "w*" then
    if fline like "w?r?d" then world << fline : ? fline
  fi
wend
close #1
cls

for h in hello
  for w in world
    ? h;" ";w,
    c++ : if c mod 6 = 0 then ?
  next
next
?
pause

B+

  • Guest
Re: XML Parser
« Reply #14 on: July 03, 2017, 01:59:45 PM »
Python dictionary structure is a variable/value pairing like what might be used for properties. As a common acquaintance of ours once explained it, instead of having an array with numeric indexes, you have an array of string indexes.

For BASIC sim of the dictionary structure, I would use strings and I would use one delimiter for the var/value pair, probably = sign, and another delimiter for the pairings probably a space.