Improve usage of xsd:any in Java code -


i have legacy xml documents import in 1 of software. part causes me troubles @ moment content of param element:

sample.xml

<...>     <param>         <idnumber>12345678</idnumber>         <factor>12.3</factor>         <date>2015-07-01</date>         <counter unit="1">             <medium>1</medium>             ...         </counter>         <counter unit="2">             <medium>4</medium>             ...         </counter>         ...     </param> </...> 

there can many (number can vary) children elements in param , avoid list of them in xsd, has been declared follow:

schema.xsd

... <xs:element name="param">     <xs:complextype>         <xs:sequence>             <xs:any minoccurs="0" maxoccurs="unbounded" processcontents="skip" />         </xs:sequence>     </xs:complextype> </xs:element> ... 

when use xjc tool generate one-to-one classes marshalling/unmarshalling get:

param.java

@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = {     "any" }) @xmlrootelement(name = "param") public class param {      @xmlanyelement     protected list<element> any;      public list<element> getany() {         if (any == null) {             = new arraylist<element>();         }         return this.any;     }  } 

my problem it's not easy work param class because contains list of element , need improve that.

i see 3 solutions:

  1. change nothing
  2. complete xsd declaring possible elements (and sub-elements) allowing me have specific access each in param class.
  3. having map instead of list in param simplify searching/extracting elements. although don't know how achieve , case <counter unit="1"> , <counter unit="2"> problematic.

so, i'm looking advice choose 1 of these 3 solutions or proposing solution.

my opinion;

  • i´d say, if know might come 100% sure, option 2 choice. might painful model xsd.
  • option 3 seems unfeasible me, counter example depth > 2 1 example.
  • finally,i have worked in projects option 1 taken, , should considered (you need write , maintain code it´s straighforward make work).

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -