XML : Wrapping repeated groups of elements in JAXB

I am trying to unmarshall a piece of xml that has repeating groups of tags:

  <Articles>                                                            <BucketId>1</BucketId>                            <BucketName>First</BucketName>                            <TriggerValue>1</TriggerValue>                            <ArticleCount>1</ArticleCount>                              <BucketId>2</BucketId>                            <BucketName>Second</BucketName>                           <TriggerValue>1</TriggerValue>                            <ArticleCount>1</ArticleCount>                              <BucketId>3</BucketId>                            <BucketName>Third</BucketName>                            <TriggerValue>1</TriggerValue>                            <ArticleCount>1</ArticleCount>                          </Articles>    

I saw couple of posts that suggest that I try something like this:

  @XmlElementRefs({       @XmlElementRef(name="BucketId", type=JAXBElement.class),       @XmlElementRef(name="BucketName", type=JAXBElement.class),      @XmlElementRef(name="TriggerValue", type=JAXBElement.class),      @XmlElementRef(name="ArticleCount", type=JAXBElement.class),      @XmlElementRef(name="item", type=JAXBElement.class),    })   private JAXBElement<String> articleElements;    

From this, how do I extract values of each element? What exactly is are the constituents of articleElements here ?

does:

  for( SomeClass articleEelement : articleElements ) {  articleElement.BucketId -------> will this yield the string value of the element ?    

What is the best approach for what I am trying to do ?

No comments:

Post a Comment