JAXB / XJC - create class from XS: Group

I am using JAXB for the first time and have very bad XML that I cannot change, for which I would like to generate classes.

XML looks something like this:

<root>
   <contacts>
      <name>...</name>
      <phone>...</phone>
      <address>..</address>
      <name>...</name>
      <phone>...</phone>
      <address>..</address>
      <name>...</name>
      <phone>...</phone>
      <address>..</address>
  </contacts>
</root>

      

So I was thinking ok, maybe I can refer to the contacts item as a sequence of groups. Relevant parts:

<xs:group name="Contact">
    <xs:sequence>
        <xs:element name="name" type="xsd:string"/>
        <xs:element name="phone" type="xsd:string"/>
        <xs:element name="address" type="xsd:string"/>
    </xs:sequence>
</xs:group>

<xs:complexType name="ContactList">
    <xs:sequence><xs:group maxOccurs="unbounded" ref="Contact"/></xs:sequence>
</xs:complexType>

      

However, my ContactList object only has a getter that looks like this:

public List<JAXBElement<?>> getContact()

Why is the Contact object not declared and how can I fix it? I don't think I can declare Contact as a complex type since it is not contained in the element.

thank

+3


source to share


1 answer


I think your best bet is to start by converting bad XML to good XML using XSLT. It will then be much easier to process the data in Java. (Who knows, you might be able to process data entirely in XSLT and not translate it entirely to Java format.) Without a decent structure to reproduce, Java rendering can be pretty awful.



+1


source







All Articles