iOS Question Not understanding this behaviour od iXMLSAX

karld

Active Member
Licensed User
Longtime User
When I parse in an XML file it is only grabbing the first and last item.

This is the code in my app
B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)

    Dim txt1 As String
    Dim RowCount As Int
   
   If parser.Parents.IndexOf("CodeUpdate") > -1 Then
       If Name = "Version" Then
            Version = Text.ToString
        Else If Name = "ID" Then
            ID = Text.ToString
        Else If Name = "DisAdvantage" Then
            DisAdvantage = Text.ToString
        Else If Name = "DisE500" Then
            DisE500 = Text.ToString
        Else If Name = "DisE300" Then
            DisE300 = Text.ToString
        Else If Name = "DisE700" Then
            DisE700 = Text.ToString
        Else If Name = "Tokheim" Then
            Tokheim = Text.ToString
        Else If Name = "Wayne" Then
            Wayne = Text.ToString
        Else If Name = "ServiceCode" Then
            ServiceCode = Text.ToString
        Else If Name = "ErrDisc" Then
            ErrDisc = Text.ToString
           
            RowCount = sql1.ExecQuerySingleResult ("Select count(*) FROM " & DBTableName1 & ";")
            ID =RowCount +1
           
        If thisVer < Version Then
           
            txt1 = "REPLACE INTO " & DBTableName1
            txt1 = txt1 & " (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc)"
            txt1 = txt1 & " VALUES ('"
            txt1 = txt1 & ID & "','"
            txt1 = txt1 & DisAdvantage & "','"
            txt1 = txt1 & DisE500 & "','"
            txt1 = txt1 & DisE300 & "','"
            txt1 = txt1 & DisE700 & "','"
            txt1 = txt1 & Tokheim & "','"
            txt1 = txt1 & Wayne & "','"
            txt1 = txt1 & ServiceCode & "','"
            txt1 = txt1 & ErrDisc & "')"
        Log(txt1)
            sql1.ExecNonQuery(txt1)
           
        RowCount = 0
        sql1.ExecQuerySingleResult ("PRAGMA user_version = " & Version & ";")
        End If
        End If
     End If
   
End Sub

And THIS is the output being logged.
As you can see is only parsing in the ID and the ErrDisc.

B4X:
Copying updated assets files (10)
Application_Start
Configuring the default app.
The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent.To continue with this plist file, you may change your app's bundle identifier to 'com.starportaurora.pumpcodespro'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.
Application_Active
Select * from Service_Codes WHERE ServiceCode = '' AND DisAdvantage = '1'
[IsInitialized=1, Years=0, Months=0
, Days=530, Hours=22, Minutes=3
, Seconds=55]
going to download upddate
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('285','','','','','','','','Secure Pulser Lift Off Detection')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('286','','','','','','','','Encrypted Pulser: Lid or Cover Removed')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('287','','','','','','','','Door Opened')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('288','','','','','','','','Door Closed')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('289','','','','','','','','Hydraulics Panel Opened')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('290','','','','','','','','Hydraulics Panel Closed')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('291','','','','','','','','PPU Value Changed')
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('292','','','','','','','','Totalizer Not Present')



This is the XML file I am parsing.
B4X:
<?xml version="1.0"?>
<CodeUpdate>
    <Code>
        <Version>5</Version>
        <ID>285</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>8046</ServiceCode>
        <ErrDisc>Secure Pulser Lift Off Detection</ErrDisc>
    </Code>
    <Code>
        <Version>6</Version>
        <ID>286</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>8051</ServiceCode>
        <ErrDisc>Encrypted Pulser: Lid or Cover Removed</ErrDisc>
    </Code>
    <Code>
        <Version>6</Version>
        <ID>287</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>5721</ServiceCode>
        <ErrDisc>Door Opened</ErrDisc>
    </Code>
    <Code>
        <Version>6</Version>
        <ID>288</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>5722</ServiceCode>
        <ErrDisc>Door Closed</ErrDisc>
    </Code>    <Code>
        <Version>6</Version>
        <ID>289</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>5723</ServiceCode>
        <ErrDisc>Hydraulics Panel Opened</ErrDisc>
    </Code>    <Code>
        <Version>6</Version>
        <ID>290</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>5724</ServiceCode>
        <ErrDisc>Hydraulics Panel Closed</ErrDisc>
    </Code>    <Code>
        <Version>6</Version>
        <ID>291</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>5300</ServiceCode>
        <ErrDisc>PPU Value Changed</ErrDisc>
    </Code>   
    <Code>
        <Version>6</Version>
        <ID>292</ID>
        <DisAdvantage>0</DisAdvantage>
        <DisE500>1</DisE500>
        <DisE300>0</DisE300>
        <DisE700>1</DisE700>
        <Tokheim>0</Tokheim>
        <Wayne>0</Wayne>
        <ServiceCode>5181</ServiceCode>
        <ErrDisc>Totalizer Not Present</ErrDisc>
    </Code>
</CodeUpdate>

This exact same code works fine in B4A so I am assuming I am missing something that is different in B4I.
 

karld

Active Member
Licensed User
Longtime User
Here is the output.
It looks to me that it IS parsing it in but for some reason it is not assigning to the variables correctly.

I also verified the database I am using is all text data.

B4X:
Copying updated assets files (10)
Application_Start
Configuring the default app.
The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent.To continue with this plist file, you may change your app's bundle identifier to 'com.starportaurora.pumpcodespro'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.
Application_Active
Select * from Service_Codes WHERE ServiceCode = '' AND DisAdvantage = '1'
[IsInitialized=1, Years=0, Months=0
, Days=531, Hours=17, Minutes=43
, Seconds=26]
going to download upddate
Version: 5
ID: 285
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 8046
ErrDisc: Secure Pulser Lift Off Detection
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('285','','','','','','','','Secure Pulser Lift Off Detection')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 286
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 8051
ErrDisc: Encrypted Pulser: Lid or Cover Removed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('286','','','','','','','','Encrypted Pulser: Lid or Cover Removed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 287
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5721
ErrDisc: Door Opened
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('287','','','','','','','','Door Opened')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 288
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5722
ErrDisc: Door Closed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('288','','','','','','','','Door Closed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 289
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5723
ErrDisc: Hydraulics Panel Opened
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('289','','','','','','','','Hydraulics Panel Opened')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 290
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5724
ErrDisc: Hydraulics Panel Closed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('290','','','','','','','','Hydraulics Panel Closed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 291
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5300
ErrDisc: PPU Value Changed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('291','','','','','','','','PPU Value Changed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 292
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5181
ErrDisc: Totalizer Not Present
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('292','','','','','','','','Totalizer Not Present')
Code:
       
       
       
       
       
       
       
       
       
       
   
CodeUpdate:
 
Upvote 0

karld

Active Member
Licensed User
Longtime User
Please add this line as the first line of that sub and post the output:
B4X:
Log($"${Name}: ${Text.ToString}"$)

I have made some progress on this Erel
This is my updated version of my sub

B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    Log($"${Name}: ${Text.ToString}"$)
    Dim txt1 As String
    Dim RowCount As Int
   
   If parser.Parents.IndexOf("CodeUpdate") > -1 Then
       If Name = "Version" Then
            Version = Text.ToString
        Else If Name = "ID" Then
            ColumnName0 = Text.ToString
        Else If Name = "DisAdvantage" Then
            ColumnName1 = Text.ToString
        Else If Name = "DisE500" Then
            ColumnName2 = Text.ToString
        Else If Name = "DisE300" Then
            ColumnName3 = Text.ToString
        Else If Name = "DisE700" Then
            ColumnName4 = Text.ToString
        Else If Name = "Tokheim" Then
            ColumnName5 = Text.ToString
        Else If Name = "Wayne" Then
            ColumnName6 = Text.ToString
        Else If Name = "ServiceCode" Then
            ColumnName7 = Text.ToString
        Else If Name = "ErrDisc" Then
            ColumnName8 = Text.ToString
           
            RowCount = sql1.ExecQuerySingleResult ("Select count(*) FROM " & DBTableName1 & ";")
            ID =RowCount +1
           
        If thisVer < Version Then
           
            txt1 = "REPLACE INTO " & DBTableName1
            txt1 = txt1 & " (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc)"
            txt1 = txt1 & " VALUES ('"
                txt1 = txt1 & ColumnName0 & "','"
                txt1 = txt1 & ColumnName1 & "','"
                txt1 = txt1 & ColumnName2 & "','"
                txt1 = txt1 & ColumnName3 & "','"
                txt1 = txt1 & ColumnName4 & "','"
                txt1 = txt1 & ColumnName5 & "','"
                txt1 = txt1 & ColumnName6 & "','"
                txt1 = txt1 & ColumnName7 & "','"
                txt1 = txt1 & ColumnName8 & "')"
               
        Log(txt1)
   
        sql1.ExecNonQuery(txt1)
        RowCount = 0
        sql1.ExecQuerySingleResult ("PRAGMA user_version = " & Version & ";")
        End If
        End If
     End If
   
End Sub

Here is the output using the code you gave me.

B4X:
Copying updated assets files (10)
Application_Start
Configuring the default app.
The project's Bundle ID is inconsistent with either the Bundle ID in 'GoogleService-Info.plist', or the Bundle ID in the options if you are using a customized options. To ensure that everything can be configured correctly, you may need to make the Bundle IDs consistent.To continue with this plist file, you may change your app's bundle identifier to 'com.starportaurora.pumpcodespro'. Or you can download a new configuration file that matches your bundle identifier from https://console.firebase.google.com/ and replace the current one.
Application_Active
Select * from Service_Codes WHERE ServiceCode = '' AND DisAdvantage = '1'
[IsInitialized=1, Years=0, Months=0
, Days=532, Hours=20, Minutes=0
, Seconds=58]
going to download upddate
Version: 5
ID: 285
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 8046
ErrDisc: Secure Pulser Lift Off Detection
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('285','0','1','0','1','0','0','8046','Secure Pulser Lift Off Detection')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 286
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 8051
ErrDisc: Encrypted Pulser: Lid or Cover Removed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('286','0','1','0','1','0','0','8051','Encrypted Pulser: Lid or Cover Removed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 287
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5721
ErrDisc: Door Opened
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('287','0','1','0','1','0','0','5721','Door Opened')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 288
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5722
ErrDisc: Door Closed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('288','0','1','0','1','0','0','5722','Door Closed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 289
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5723
ErrDisc: Hydraulics Panel Opened
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('289','0','1','0','1','0','0','5723','Hydraulics Panel Opened')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 290
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5724
ErrDisc: Hydraulics Panel Closed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('290','0','1','0','1','0','0','5724','Hydraulics Panel Closed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 291
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5300
ErrDisc: PPU Value Changed
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('291','0','1','0','1','0','0','5300','PPU Value Changed')
Code:
       
       
       
       
       
       
       
       
       
       
   
Version: 6
ID: 292
DisAdvantage: 0
DisE500: 1
DisE300: 0
DisE700: 1
Tokheim: 0
Wayne: 0
ServiceCode: 5181
ErrDisc: Totalizer Not Present
REPLACE INTO Service_Codes (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc) VALUES ('292','0','1','0','1','0','0','5181','Totalizer Not Present')
Code:
       
       
       
       
       
       
       
       
       
       
   
CodeUpdate:
   
   
   
                   
   
Selected Text was Encore 700
Select * from Service_Codes WHERE 5181 = '8025' AND DisE700 = '1'
Application_Inactive
Application_Background
Application background

What it is doing now is deleting ALL entries in the original database instead of updating it.
I am SO close.

The REPLACE INTO query worked perfect on the B4A app. I am puzzled as to why the same query acts differently on B4i.

ANYONE who has any thoughts are welcome to reply.
 
Upvote 0

karld

Active Member
Licensed User
Longtime User
SUCCESS!!!!!!!!

I had to use THIS CODE

B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)

    Dim txt1 As String
    Dim RowCount As Int

       
   If parser.Parents.IndexOf("CodeUpdate") > -1 Then
       If Name = "Version" Then
            Version = Text.ToString
        Else If Name = "ID" Then
            ID = Text.ToString
        Else If Name = "DisAdvantage" Then
            PDisAdvantage = Text.ToString
        Else If Name = "DisE500" Then
            PDisE500 = Text.ToString
        Else If Name = "DisE300" Then
            PDisE300 = Text.ToString
        Else If Name = "DisE700" Then
            PDisE700 = Text.ToString
        Else If Name = "Tokheim" Then
            PTokheim = Text.ToString
        Else If Name = "Wayne" Then
            PWayane = Text.ToString
        Else If Name = "ServiceCode" Then
            PServiceCode = Text.ToString
        Else If Name = "ErrDisc" Then
            PErrDisc = Text.ToString
           
            RowCount = sql1.ExecQuerySingleResult ("Select count(*) FROM " & DBTableName1 & ";")
            ID =RowCount +1
           
        If thisVer < Version Then
            txt1 = "REPLACE INTO " & DBTableName1
            txt1 = txt1 & " (ID, DisAdvantage, DisE500, DisE300, DisE700, Tokheim, Wayne, ServiceCode, ErrDisc)"
            txt1 = txt1 & " VALUES ('"
                txt1 = txt1 & ID & "','"
                txt1 = txt1 & PDisAdvantage & "','"
                txt1 = txt1 & PDisE500 & "','"
                txt1 = txt1 & PDisE300 & "','"
                txt1 = txt1 & PDisE700 & "','"
                txt1 = txt1 & PTokheim & "','"
                txt1 = txt1 & PWayane & "','"
                txt1 = txt1 & PServiceCode & "','"
                txt1 = txt1 & PErrDisc & "')"
               
        sql1.ExecNonQuery(txt1)
        RowCount = 0
        sql1.ExecQuerySingleResult ("PRAGMA user_version = " & Version & ";")
        End If
        End If
     End If
   
End Sub

The last issue was being caused by not having my variables as GLOBAL
Once i moved them to Process_Globals everything worked like a charm.

There is definitely a few differences how B4i and B4A operate.... But now to finish thoroughly testing this and then to figure out how to update an app on Apple. I have only ever submitted a new app.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…