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:
- change nothing
- complete xsd declaring possible elements (and sub-elements) allowing me have specific access each in
param
class. - 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
Post a Comment