I do anmarshaling RSS feed. I slipped it Intelijj IDEA, asked to make JAXB classes from xsd. IDEA did something like this:

@XmlRootElement(name = "rss") public class Rss { public Rss.Channel getChannel() { return channel; } // some getters and setters .... @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "title", "link", "description", "image", "lastBuildDate", "item" }) public static class Channel { @XmlElement(required = true) protected String title; // another properties .... protected List<Rss.Channel.Item> item; public String getTitle() { return title; } // another getters and setters .... public List<Rss.Channel.Item> getItem() { if (item == null) { item = new ArrayList<Rss.Channel.Item>(); } return this.item; } // and so on.... } } 

Further in a certain class, I am unmarshaling from xml using this jaxb-class like this:

 JAXBContext jc = JAXBContext.newInstance("com.ar.ya"); Unmarshaller unmarshaller = jc.createUnmarshaller(); File customerXML = new File("src/ya.xml"); //в перспективе это будет стрим с URL Rss rss = (Rss) JAXBIntrospector.getValue(unmarshaller.unmarshal(customerXML)); 

In the end, I need to throw the item elements in some JSP page. But since channel is an enclosed class, and getItem is its local method, I naturally cannot access them from the rss object variable and later throw some of its items in a loop somewhere. In the console or in the JSP - it does not matter. Accordingly, the question is how best to organize the design in this case so that I can access public List getItem (). The only idea that comes to mind is to make another method in the RSS wrapping class that will call its getItem, but somehow it seems crooked to me ... Thank you in advance!

  • Not quite understand what the complexity of the nested class. rss.getChannel().getItem() should work, isn't it? - lexicore
  • But if you are not satisfied with nested classes, use <jaxb:globalBindings localScoping="toplevel" .../> and you will not have nested classes. - lexicore

0