java - How to handle array in xml / xsd for generating a POJO class? -
sample xml response rest ws -
<userinfodatacontract xmlns="http://schemas.datacontract.org/2004/07/interzoic.sso.shared" xmlns:i="http://www.w3.org/2001/xmlschema-instance"> <displayname>test user</displayname> <email>test@test.com</email> <firstname>test</firstname> <issuperuser>false</issuperuser> <lastname>user</lastname> <password>testuser1</password> <portalid>0</portalid> <roles xmlns:a="http://schemas.microsoft.com/2003/10/serialization/arrays"> <a:string>registered users</a:string> </roles> <userid>43</userid> <username>testuser</username> </userinfodatacontract>
xsd generated using http://xmlgrid.net/xml2xsd.html
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" elementformdefault="qualified" attributeformdefault="unqualified"> <!-- xml schema generated xml document on thu apr 09 2015 11:18:33 gmt-0500 (cdt) --> <!-- xmlgrid.net free online service http://xmlgrid.net --> <xs:element name="userinfodatacontract"> <xs:complextype> <xs:sequence> <xs:element name="displayname" type="xs:string"></xs:element> <xs:element name="email" type="xs:string"></xs:element> <xs:element name="firstname" type="xs:string"></xs:element> <xs:element name="issuperuser" type="xs:string"></xs:element> <xs:element name="lastname" type="xs:string"></xs:element> <xs:element name="password" type="xs:string"></xs:element> <xs:element name="portalid" type="xs:int"></xs:element> <xs:element name="roles"> <xs:complextype> <xs:sequence> <xs:element name="a:string" type="xs:string"></xs:element> </xs:sequence> <xs:attribute name="xmlns:a" type="xs:string"></xs:attribute> </xs:complextype> </xs:element> <xs:element name="userid" type="xs:int"></xs:element> <xs:element name="username" type="xs:string"></xs:element> </xs:sequence> <xs:attribute name="xmlns" type="xs:string"></xs:attribute> <xs:attribute name="xmlns:i" type="xs:string"></xs:attribute> </xs:complextype> </xs:element>
when try create jaxb classes above xsd in eclipse, gives me errors related
<xs:attribute name="xmlns" type="xs:string"></xs:attribute> <xs:attribute name="xmlns:i" type="xs:string"></xs:attribute>
and
<xs:attribute name="xmlns:a" in roles element
and
<xs:element name="a:string" type="xs:string"></xs:element>
so removed them , added
<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://schemas.datacontract.org/2004/07/interzoic.sso.shared" xmlns:i="http://www.w3.org/2001/xmlschema-instance" xmlns:a="http://schemas.microsoft.com/2003/10/serialization/arrays" targetnamespace="http://www.w3.org/2001/xmlschema-instance" elementformdefault="qualified" attributeformdefault="unqualified">
on top.
how "roles" xml referenced in xsd can create correct pojo class?
taking reference http://www.w3.org/tr/xmlschema-0/#listdt, lists should declared way
<xsd:simpletype name="listofmyinttype"> <xsd:list itemtype="myinteger"/> </xsd:simpletype>
i not able figure out how can apply xsd. appreciated.
i think in xml in
<roles xmlns:a="http://schemas.microsoft.com/2003/10/serialization/arrays">
the xmlns:a
considered attribute ide generates xsd, that's why in generated schema have
<xs:attribute name="xmlns" type="xs:string"></xs:attribute>
so agree deleting
<xs:attribute name="xmlns:a" type="xs:string"></xs:attribute> <xs:attribute name="xmlns" type="xs:string"></xs:attribute> <xs:attribute name="xmlns:i" type="xs:string"></xs:attribute>
from xsd.
my guess try setting
targetnamespace="http://schemas.datacontract.org/2004/07/interzoic.sso.shared"
as used explicitly in xml