0

I am trying to parse the following XML. In this XML tags are coming dynamically. Tag names are not confirm. Value of the tag named "strCount" gives total number of tags (str0 to str10). Also the encounter tag can appear multiple times.

<pastPregenancies>
  <encounter>
     <strNo>1</strNo>
     <strPPId>1</strPPId>
     <str0>09/03/2004</str0>
     <str1>4</str1>
     <str2>2</str2>
     <str3>6</str3>
     <str4 />
     <str5>m</str5>
     <str6 />
     <str7 />
     <str8 />
     <str9 />
     <str10 />
     <strCount>11</strCount>
  </encounter>
</pastPregenancies>

I am using simple-xml for parsing. Following is the pojo I created for this, which doesn't work -

public class PastPregenancies {

    @ElementList(entry="encounter", inline=true)
    private List<?> encounter;

    public List<?> getEncounter() {
        return encounter;
    }

    public void setEncounter(List<?> encounter) {
        this.encounter = encounter;
    }
}

Please tell me how can I create pojo for parsing this type of xml.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
aaaaa
  • 449
  • 1
  • 5
  • 18
  • It may be best to remain at raw XML level. The XML structure seems simple enought, just elements. – laune Sep 16 '14 at 11:40

1 Answers1

1

For parsing the xml file you need to use parsers.ther are two basic parsers

  1. DOM parser
  2. SAX parser

the DOM parser is more advanced and according to your requirement it is suitable.for more information and example go through this link http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/ this link provides and example for dom parser

Ashay Patil
  • 152
  • 4