XML : How do I place the corresponding tags in this xml to a java object

This is my XML file:

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  <dragonDatabase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">      <dragon>          <Name>Hackatoo</Name>          <Description>This impulsive and reckless member of the Sharp Class is a master at collecting wood...so long as its axe-like snout doesn't get stuck in the tree its cutting! Hackatoo eggs laid at a high altitude can hook on to whatever they hit.</Description>          <Class>Sharp</Class>          <Fire-Type>No Data</Fire-Type>          <Diet>No Data</Diet>      </dragon>      <dragon>          <Name>Hobblegrunt</Name>          <Description>The Hobblegrunt has a single horn and and an expandable frill surrounding its head. It has clawed wings, small arms and big legs like a Deadly Nadder. It also appears to have long neck and tail as well. The Hobblegrunt doesn't have a particular color, but instead it changes color depending on its mood.</Description>          <Class>Stoker, Boulder</Class>          <Fire-Type>Ethane Expectorant</Fire-Type>          <Diet>No Data</Diet>      </dragon>  </dragonDatabase>    

And this is my DragonBean class:

  public class DragonBean {      private String name;      private String description;      private String dragonClass;      private String fireType;      private String diet;            public String getName() {          return name;      }      public void setName(String name) {          this.name = name;      }      public String getDescription() {          return description;      }      public void setDescription(String description) {          this.description = description;      }      public String getDragonClass() {          return dragonClass;      }      public void setDragonClass(String dragonClass) {          this.dragonClass = dragonClass;      }      public String getFireType() {          return fireType;      }      public void setFireType(String fireType) {          this.fireType = fireType;      }      public String getDiet() {          return diet;      }      public void setDiet(String diet) {          this.diet = diet;      }    }    

Basically I want to get each dragon in the xml and place it in a list containing the a DragonBean type. I know that I have to parse the XML. But i don't know where to begin. After placing the info in the list I plan to use Jackson to convert it into a JSON file.

No comments:

Post a Comment