Results 1 to 2 of 2
  1. #1
    jenil0713 is offline Member
    Join Date
    Mar 2015
    Posts
    1
    Rep Power
    0

    Default Data getting overridden on loop after parsing a xml

    I have an xml with 'n' number of data which i am parsing,for test i hardcoded without looping has below,now the below line is just parsing and showing the data for index '1' ,i need to loop this and i am not sure how can i do this.How do i find the length of obj and loop,i cannot find any method in SoapObject.I used like below but the data is getting overridden after parsing

    for(int i=0;i<obj.getPropertyCount();i++) {
    KSoap2ResultParser.parseBusinessObject(obj.getProp erty(i).toString(), getReminder);
    }



    call in another class

    public static void parseBusinessObject(String input, Object output) throws NumberFormatException, IllegalArgumentException, IllegalAccessException, InstantiationException{
    System.out.println("input----> " +input);
    Class theClass = output.getClass();
    Field[] fields = theClass.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
    Type type=fields[i].getType();
    System.out.println("type--" +type);
    fields[i].setAccessible(true);

    //detect String
    if (fields[i].getType().equals(String.class)) {
    String tag = fields[i].getName() + "="; //"s" is for String in the above soap response example + field name for example Name = "sName"
    System.out.println("fff------------"+tag);
    if(input.contains(tag)){
    String strValue = input.substring(input.indexOf(tag)+tag.length(), input.indexOf(";", input.indexOf(tag)));
    System.out.println("strvalue------------"+strValue);

    if(strValue.length()!=0){
    fields[i].set(output, strValue);
    }
    }
    }

    //detect int or Integer
    if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
    String tag = fields[i].getName() + "="; //"i" is for Integer or int in the above soap response example+ field name for example Goals = "iGoals"
    if(input.contains(tag)){
    String strValue = input.substring(input.indexOf(tag)+tag.length(), input.indexOf(";", input.indexOf(tag)));
    System.out.println("strvalue------------"+strValue);

    if(strValue.length()!=0){
    fields[i].setInt(output, Integer.valueOf(strValue));
    }
    }
    }

    //detect float or Float
    if (type.equals(Float.TYPE) || type.equals(Float.class)) {
    String tag = "f" + fields[i].getName() + "=";
    if(input.contains(tag)){
    String strValue = input.substring(input.indexOf(tag)+tag.length(), input.indexOf(";", input.indexOf(tag)));
    if(strValue.length()!=0){
    fields[i].setFloat(output, Float.valueOf(strValue));
    }
    }
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Data getting overridden on loop after parsing a xml

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. parsing binary data to ASCII with javacc
    By nab2329 in forum New To Java
    Replies: 6
    Last Post: 05-24-2014, 03:08 AM
  2. Parsing Huge Data Files
    By newsomjk in forum Advanced Java
    Replies: 17
    Last Post: 08-07-2012, 10:54 AM
  3. parsing out some data.. from an HTML response
    By AndyMan in forum New To Java
    Replies: 1
    Last Post: 11-29-2010, 02:00 AM
  4. java data fields parsing
    By sardare in forum Advanced Java
    Replies: 8
    Last Post: 10-02-2009, 12:17 PM
  5. parsing/storing large text data
    By hkansal in forum New To Java
    Replies: 4
    Last Post: 10-19-2008, 06:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •