12

I am working on an android application which calls a soap function and returns a Diction<string, List<string>>.

The response looks like the below:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <retrieveDatabasesResponse xmlns="http://tempuri.org/">
         <retrieveDatabasesResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>information_schema</a:Key>
               <a:Value>
                  <a:string>CHARACTER_SETS</a:string>
                  <a:string>COLLATIONS</a:string>
                  <a:string>COLLATION_CHARACTER_SET_APPLICABILITY</a:string>
                  <a:string>COLUMNS</a:string>
                  <a:string>COLUMN_PRIVILEGES</a:string>
                  <a:string>ENGINES</a:string>
                  <a:string>EVENTS</a:string>
                  <a:string>FILES</a:string>
                  <a:string>GLOBAL_STATUS</a:string>
                  <a:string>GLOBAL_VARIABLES</a:string>
                  <a:string>KEY_COLUMN_USAGE</a:string>
                  <a:string>PARAMETERS</a:string>
                  <a:string>PARTITIONS</a:string>
                  <a:string>PLUGINS</a:string>
                  <a:string>PROCESSLIST</a:string>
                  <a:string>PROFILING</a:string>
                  <a:string>REFERENTIAL_CONSTRAINTS</a:string>
                  <a:string>ROUTINES</a:string>
                  <a:string>SCHEMATA</a:string>
                  <a:string>SCHEMA_PRIVILEGES</a:string>
                  <a:string>SESSION_STATUS</a:string>
                  <a:string>SESSION_VARIABLES</a:string>
                  <a:string>STATISTICS</a:string>
                  <a:string>TABLES</a:string>
                  <a:string>TABLESPACES</a:string>
                  <a:string>TABLE_CONSTRAINTS</a:string>
                  <a:string>TABLE_PRIVILEGES</a:string>
                  <a:string>TRIGGERS</a:string>
                  <a:string>USER_PRIVILEGES</a:string>
                  <a:string>VIEWS</a:string>
                  <a:string>INNODB_BUFFER_PAGE</a:string>
                  <a:string>INNODB_TRX</a:string>
                  <a:string>INNODB_BUFFER_POOL_STATS</a:string>
                  <a:string>INNODB_LOCK_WAITS</a:string>
                  <a:string>INNODB_CMPMEM</a:string>
                  <a:string>INNODB_CMP</a:string>
                  <a:string>INNODB_LOCKS</a:string>
                  <a:string>INNODB_CMPMEM_RESET</a:string>
                  <a:string>INNODB_CMP_RESET</a:string>
                  <a:string>INNODB_BUFFER_PAGE_LRU</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>boardies_password_manager</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>categories</a:string>
                  <a:string>passwords</a:string>
                  <a:string>settings</a:string>
                  <a:string>users</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>bugs</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>comments</a:string>
                  <a:string>logfile_history</a:string>
                  <a:string>platforms</a:string>
                  <a:string>privileges</a:string>
                  <a:string>reports</a:string>
                  <a:string>requested_features</a:string>
                  <a:string>settings</a:string>
                  <a:string>short_bulletins</a:string>
                  <a:string>software</a:string>
                  <a:string>users</a:string>
                  <a:string>versions</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>bugs_demo</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>comments</a:string>
                  <a:string>logfile_history</a:string>
                  <a:string>platforms</a:string>
                  <a:string>privileges</a:string>
                  <a:string>reports</a:string>
                  <a:string>requested_features</a:string>
                  <a:string>settings</a:string>
                  <a:string>software</a:string>
                  <a:string>users</a:string>
                  <a:string>versions</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>bugs_old</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>alarms_archive</a:string>
                  <a:string>comments</a:string>
                  <a:string>discussions</a:string>
                  <a:string>message_content</a:string>
                  <a:string>message_details</a:string>
                  <a:string>platforms</a:string>
                  <a:string>reports</a:string>
                  <a:string>settings</a:string>
                  <a:string>software</a:string>
                  <a:string>users</a:string>
                  <a:string>versions</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>critimon</a:Key>
               <a:Value>
                  <a:string>administrators</a:string>
                  <a:string>alarms</a:string>
                  <a:string>android_devices</a:string>
                  <a:string>app_using_api_version</a:string>
                  <a:string>available_sdks</a:string>
                  <a:string>config_groups</a:string>
                  <a:string>config_items</a:string>
                  <a:string>config_values</a:string>
                  <a:string>crash_details</a:string>
                  <a:string>customer_queries</a:string>
                  <a:string>development_devices</a:string>
                  <a:string>generated_monthly_reports</a:string>
                  <a:string>registered_apps</a:string>
                  <a:string>sdk_versions</a:string>
                  <a:string>user_config_groups</a:string>
                  <a:string>user_config_items_18</a:string>
                  <a:string>user_config_values</a:string>
                  <a:string>users</a:string>
                  <a:string>windows_devices</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>email</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>alarms_archive</a:string>
                  <a:string>attachments</a:string>
                  <a:string>config_groups</a:string>
                  <a:string>config_items</a:string>
                  <a:string>config_values</a:string>
                  <a:string>queue</a:string>
                  <a:string>smtp_auth_users</a:string>
                  <a:string>smtp_debug_details</a:string>
                  <a:string>smtp_debug_record</a:string>
                  <a:string>users</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>email_something</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>attachments</a:string>
                  <a:string>authenticated_users</a:string>
                  <a:string>auto_replies</a:string>
                  <a:string>blacklist</a:string>
                  <a:string>emailqueue</a:string>
                  <a:string>logfile_history</a:string>
                  <a:string>settings</a:string>
                  <a:string>smtp_debug_details</a:string>
                  <a:string>smtp_debug_record</a:string>
                  <a:string>users</a:string>
                  <a:string>whitelist</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>email_test</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>attachments</a:string>
                  <a:string>authenticated_users</a:string>
                  <a:string>auto_replies</a:string>
                  <a:string>blacklist</a:string>
                  <a:string>emailqueue</a:string>
                  <a:string>logfile_history</a:string>
                  <a:string>settings</a:string>
                  <a:string>smtp_debug_details</a:string>
                  <a:string>smtp_debug_record</a:string>
                  <a:string>users</a:string>
                  <a:string>whitelist</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>email_user</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>emailserver</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>attachments</a:string>
                  <a:string>authenticated_users</a:string>
                  <a:string>auto_replies</a:string>
                  <a:string>blacklist</a:string>
                  <a:string>emailqueue</a:string>
                  <a:string>logfile_history</a:string>
                  <a:string>settings</a:string>
                  <a:string>smtp_debug_details</a:string>
                  <a:string>smtp_debug_record</a:string>
                  <a:string>users</a:string>
                  <a:string>whitelist</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>mysql</a:Key>
               <a:Value>
                  <a:string>columns_priv</a:string>
                  <a:string>db</a:string>
                  <a:string>event</a:string>
                  <a:string>func</a:string>
                  <a:string>general_log</a:string>
                  <a:string>help_category</a:string>
                  <a:string>help_keyword</a:string>
                  <a:string>help_relation</a:string>
                  <a:string>help_topic</a:string>
                  <a:string>host</a:string>
                  <a:string>ndb_binlog_index</a:string>
                  <a:string>plugin</a:string>
                  <a:string>proc</a:string>
                  <a:string>procs_priv</a:string>
                  <a:string>proxies_priv</a:string>
                  <a:string>servers</a:string>
                  <a:string>slow_log</a:string>
                  <a:string>tables_priv</a:string>
                  <a:string>time_zone</a:string>
                  <a:string>time_zone_leap_second</a:string>
                  <a:string>time_zone_name</a:string>
                  <a:string>time_zone_transition</a:string>
                  <a:string>time_zone_transition_type</a:string>
                  <a:string>user</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>mysql_server_manager</a:Key>
               <a:Value>
                  <a:string>alarms</a:string>
                  <a:string>config_groups</a:string>
                  <a:string>config_items</a:string>
                  <a:string>config_values</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>performance_schema</a:Key>
               <a:Value>
                  <a:string>cond_instances</a:string>
                  <a:string>events_waits_current</a:string>
                  <a:string>events_waits_history</a:string>
                  <a:string>events_waits_history_long</a:string>
                  <a:string>events_waits_summary_by_instance</a:string>
                  <a:string>events_waits_summary_by_thread_by_event_name</a:string>
                  <a:string>events_waits_summary_global_by_event_name</a:string>
                  <a:string>file_instances</a:string>
                  <a:string>file_summary_by_event_name</a:string>
                  <a:string>file_summary_by_instance</a:string>
                  <a:string>mutex_instances</a:string>
                  <a:string>performance_timers</a:string>
                  <a:string>rwlock_instances</a:string>
                  <a:string>setup_consumers</a:string>
                  <a:string>setup_instruments</a:string>
                  <a:string>setup_timers</a:string>
                  <a:string>threads</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>software_audit_dev</a:Key>
               <a:Value>
                  <a:string>fault_notes</a:string>
                  <a:string>faults</a:string>
                  <a:string>notes</a:string>
                  <a:string>software</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
            <a:KeyValueOfstringArrayOfstringty7Ep6D1>
               <a:Key>test</a:Key>
               <a:Value>
                  <a:string>fault_notes</a:string>
                  <a:string>file_history</a:string>
                  <a:string>my_table</a:string>
                  <a:string>stored_connections</a:string>
               </a:Value>
            </a:KeyValueOfstringArrayOfstringty7Ep6D1>
         </retrieveDatabasesResult>
      </retrieveDatabasesResponse>
   </s:Body>
</s:Envelope>

I am trying to get the count of the elemenets within the so I can then loop through to get the list but what I've tried doesn't seem to work.

Below is the code I am using

private void processRetrievedDatabase(SoapObject soapResult)
    {
        int i = 0;
        int j = 0;
        SoapObject rootArray = ((SoapObject)soapResult.getProperty(0));
        SoapObject dbArray = ((SoapObject)rootArray.getProperty(0));
        int dbCount = dbArray.getPropertyCount();
        ArrayList<String> databases = new ArrayList<String>();
        while (i < dbCount)
        {
            if (i % 2 == 0)
            {
                databases.add(dbArray.getPropertyAsString(i));
                Log.d(TAG, dbArray.getPropertyAsString(i));
            }
            else
            {
                SoapObject tablesArray = ((SoapObject)dbArray.getProperty(i));
                int tableCount = tablesArray.getPropertyCount();
                while (j < tableCount)
                {
                    Log.d(TAG, tablesArray.getPropertyAsString(j));
                    j++;
                }
            }
            i++;
        }

Below is what I am getting in the logcat

12-04 19:52:49.480: D/Soap Manager(6204): anyType{Key=information_schema; Value=anyType{string=CHARACTER_SETS; string=COLLATIONS; string=COLLATION_CHARACTER_SET_APPLICABILITY; string=COLUMNS; string=COLUMN_PRIVILEGES; string=ENGINES; string=EVENTS; string=FILES; string=GLOBAL_STATUS; string=GLOBAL_VARIABLES; string=KEY_COLUMN_USAGE; string=PARAMETERS; string=PARTITIONS; string=PLUGINS; string=PROCESSLIST; string=PROFILING; string=REFERENTIAL_CONSTRAINTS; string=ROUTINES; string=SCHEMATA; string=SCHEMA_PRIVILEGES; string=SESSION_STATUS; string=SESSION_VARIABLES; string=STATISTICS; string=TABLES; string=TABLESPACES; string=TABLE_CONSTRAINTS; string=TABLE_PRIVILEGES; string=TRIGGERS; string=USER_PRIVILEGES; string=VIEWS; string=INNODB_BUFFER_PAGE; string=INNODB_TRX; string=INNODB_BUFFER_POOL_STATS; string=INNODB_LOCK_WAITS; string=INNODB_CMPMEM; string=INNODB_CMP; string=INNODB_LOCKS; string=INNODB_CMPMEM_RESET; string=INNODB_CMP_RESET; string=INNODB_BUFFER_PAGE_LRU; }; }
12-04 19:53:01.896: D/Soap Manager(6204): anyType{Key=information_schema; Value=anyType{string=CHARACTER_SETS; string=COLLATIONS; string=COLLATION_CHARACTER_SET_APPLICABILITY; string=COLUMNS; string=COLUMN_PRIVILEGES; string=ENGINES; string=EVENTS; string=FILES; string=GLOBAL_STATUS; string=GLOBAL_VARIABLES; string=KEY_COLUMN_USAGE; string=PARAMETERS; string=PARTITIONS; string=PLUGINS; string=PROCESSLIST; string=PROFILING; string=REFERENTIAL_CONSTRAINTS; string=ROUTINES; string=SCHEMATA; string=SCHEMA_PRIVILEGES; string=SESSION_STATUS; string=SESSION_VARIABLES; string=STATISTICS; string=TABLES; string=TABLESPACES; string=TABLE_CONSTRAINTS; string=TABLE_PRIVILEGES; string=TRIGGERS; string=USER_PRIVILEGES; string=VIEWS; string=INNODB_BUFFER_PAGE; string=INNODB_TRX; string=INNODB_BUFFER_POOL_STATS; string=INNODB_LOCK_WAITS; string=INNODB_CMPMEM; string=INNODB_CMP; string=INNODB_LOCKS; string=INNODB_CMPMEM_RESET; string=INNODB_CMP_RESET; string=INNODB_BUFFER_PAGE_LRU; }; }

I have it almost there but it should be printing out the database followed by all tables within log cat and repeating but for some reason it only prints the first database and its tables.

So in my example above, it should print

information_schema
CHARACTER_SETS
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
etc
etc
boardies_password_manager
alarms
categories
passwords
etc
etc

But i am only getting information_schema and its tables not the rest of the databases

Thanks for any help you can provide.

Boardy
  • 31,944
  • 94
  • 238
  • 411

2 Answers2

4

if I understand correctly, it only prints the first database because the j variable isn't reset to 0 before starting loop for next table. So, the else block should look like this:

  else
       {
            SoapObject tablesArray = ((SoapObject)dbArray.getProperty(i));
            int tableCount = tablesArray.getPropertyCount();

            // j should reset to 0
            j = 0;
            while (j < tableCount)
            {
                Log.d(TAG, tablesArray.getPropertyAsString(j));
                j++;
            }
        }

Or you may want a for loop like this (I like this way because it is easier and clearer than while):

private void processRetrievedDatabase(SoapObject soapResult)
{
    SoapObject rootArray = ((SoapObject)soapResult.getProperty(0));
    SoapObject dbArray = ((SoapObject)rootArray.getProperty(0));
    int dbCount = dbArray.getPropertyCount();
    ArrayList<String> databases = new ArrayList<String>();
    for(int i = 0; i < dbCount; i++){
        if (i % 2 == 0)
        {
            databases.add(dbArray.getPropertyAsString(i));
            Log.d(TAG, dbArray.getPropertyAsString(i));
        }
        else
        {
            SoapObject tablesArray = ((SoapObject)dbArray.getProperty(i));
            int tableCount = tablesArray.getPropertyCount();
            for(int j = 0; j < tableCount; j++){
                Log.d(TAG, tablesArray.getPropertyAsString(j));
            }
        }
    }
}    
R4j
  • 9,575
  • 18
  • 76
  • 154
1

I seems it's not really clear how you parse the SoapObjects I'm not sure you need a modulo. Apparently you guess that all odd properties will be keys while all even properties will be a list of values. I'm not sure it is the best way to do

First you could try to print the value of dbCount and tableCount. Are them what you expect them to be. Then you should change

Log.d(TAG, dbArray.getPropertyAsString(i));

and

Log.d(TAG, tablesArray.getPropertyAsString(j));

to set a different tag so you know which one is printing.

This will help you to find where the code isn't doing exactly what you want it to do, and maybe come back here with the results so we can try to find some more ideas.

Good luck

Basile Perrenoud
  • 3,810
  • 1
  • 24
  • 47