0

I have a web service which returns an XML file like this:

    <Service> 
       <id>12</id> 
       <function_code>2</function_code>  
       <cf>AABBBCCCAAA</cf> 
       <active>0</active> 
       <option>resume_state</option> 
    </Service> 

In many case the element may be not returned, and the XML will be:

    <Service> 
       <id>12</id> 
       <function_code>2</function_code>  
       <cf>AABBBCCCAAA</cf> 
       <active>0</active> 
       <option/>
    </Service> 

I'm parsing this element with the following code:

    String id = response.getProperty("cf").toString();
    String func= response.getProperty("function_code").toString();
    int active = Integer.parseInt(response.getProperty("active").toString();
    String option = response.getProperty("option").toString();

where response is SoapObject.

In this situation, when I try to print the option String on error line:

    System.err.println("my option variable contains: "+option);

The result is:

    my option variable contains anyType{}

Why? And what can I do for parsing the option string obtaining null value if the option element is void () ?

GVillani82
  • 17,196
  • 30
  • 105
  • 172

1 Answers1

0
String appname = soapObject.getProperty("appname")
                            .toString();

                    if (appname.equals("anyType{}")) {
                        content.setAppname(null);
                    } else {
                        content.setAppname(appname);
                    }

You can try this, and it works fine..

Prashant Mishra
  • 627
  • 5
  • 18