How Add List of objects to XSD properly - java

<xsd:element minOccurs="0" name="Consents">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="Marketing" type="ConsentType" />
<xsd:element minOccurs="0" name="CheckExternalDB" type="ConsentType" />
<xsd:element minOccurs="0" name="DocsByEMail" type="ConsentType" />
<xsd:element minOccurs="0" name="DocsByPrintHouse" type="ConsentType" />
<xsd:element minOccurs="0" name="DocsByEBOK" type="ConsentType" />
<xsd:element minOccurs="0" name="DataToGroup" type="TimeConsentType" />
<xsd:element minOccurs="0" name="MarketingGroup" type="TimeConsentType" />
<xsd:element minOccurs="0" name="EMarketingInf" type="TimeConsentType" />
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element minOccurs="0" maxOccurs="unbounded" name="CustomerConsents" type="CustomerConsentsBasic" />
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
My class looks like this
public class CompanyType {
#XmlElement(name = "Consents")
protected CompanyType.Consents consents;
}
public static class Consents {
#XmlElement(name = "CustomerConsents")
protected List<CustomerConsentsBasic> customerConsents;
}
customerConsents is a list and I want to represent this correctly. Above is my XSD, could someone correct it if its wrong somewhere.

Related

JAXB marshall & unmarshalling of child element without #XMLRootElement

I am trying to marshall a child element object to get xml string. And then using this xml string I would like to Unmarshall as well.
To clarify, I have generated my jaxb classes from xsd and I don't have any method in ObjectFactory that will provide the desired object.
The xsd defination: IBUSStatusType is a child of root element IBUSMessage
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://soa.myhealth.com/ibus/v1.1.0" targetNamespace="http://soa.myhealth.com/ibus/v1.1.0" elementFormDefault="qualified">
<xsd:element name="IBUSMessage" type="tns:IBUSMessage"/>
<xsd:complexType name="IBUSMessage">
<xsd:sequence>
<xsd:element name="Header" type="tns:IBUSHeaderType"/>
<xsd:element name="Detail" type="tns:IBUSVariantType"/>
<xsd:element name="Status" type="tns:IBUSStatusType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="IBUSHeaderType">
<xsd:sequence>
<xsd:element name="Retry" type="tns:RetryType" minOccurs="0"/>
<xsd:element name="ReplyToStack" type="tns:ReplyToStackType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="TransactionContext" type="tns:TransactionContextType"/>
<xsd:element name="systemType" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="TestEnvironment" type="tns:TestEnvironmentType" minOccurs="0"/>
<xsd:element name="TransactionSetHeader" type="tns:TransactionHeaderType" minOccurs="0"/>
<xsd:element name="BeginningSegment" type="tns:TransactionSegmentType" minOccurs="0"/>
<xsd:element name="LegacySources" type="tns:SourceType" minOccurs="0"/>
<xsd:element name="Variables" type="tns:IBUSVariantType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="RoutingTable" type="tns:RoutingTableType" minOccurs="0" maxOccurs="1"/>
<xsd:element name="OptionalHeaders" type="tns:IBUSVariantType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TestEnvironmentType">
<xsd:sequence>
<xsd:element name="useStubbedService" type="xsd:string" default="false"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TransactionContextType">
<xsd:sequence>
<xsd:element name="source" type="xsd:string" minOccurs="0"/>
<xsd:element name="actionName" type="xsd:string"/>
<xsd:element name="serviceName" type="xsd:string"/>
<xsd:element name="ActionClass" type="tns:ActionClassType" minOccurs="0"/>
<xsd:element name="MessageType" type="tns:MessageResponseType" minOccurs="0"/>
<xsd:element name="processDate" type="xsd:date" minOccurs="0"/>
<xsd:element name="processTime" type="xsd:time" minOccurs="0"/>
<xsd:element name="userId" type="xsd:string" minOccurs="0"/>
<xsd:element name="unitOfWorkId" type="xsd:string" minOccurs="0"/>
<xsd:element name="operationId" type="xsd:string" minOccurs="0"/>
<xsd:element name="parentOperationId" type="xsd:string" minOccurs="0"/>
<xsd:element name="uowGroupIndicator" type="xsd:string" minOccurs="0"/>
<xsd:element name="uowGroupSize" type="xsd:string" minOccurs="0"/>
<xsd:element name="transactionId" type="xsd:string" minOccurs="0"/>
<xsd:element name="responseProtocol" type="xsd:string" minOccurs="0"/>
<xsd:element name="aggregation" type="xsd:string" minOccurs="0"/>
<xsd:element name="actionType" type="xsd:string" minOccurs="0"/>
<xsd:element name="origSource" type="xsd:string" minOccurs="0"/>
<xsd:element name="origSourceClass" type="xsd:string" minOccurs="0"/>
<xsd:element name="requestIdentifier" type="xsd:string" minOccurs="0"/>
<xsd:element name="generatedInterchangeControlNumber" type="xsd:string" minOccurs="0"/>
<xsd:element name="generatedGroupControlNumber" type="xsd:string" minOccurs="0"/>
<xsd:element name="generatedTransactionControlNumber" type="xsd:string" minOccurs="0"/>
<xsd:element name="messageTimeout" type="xsd:string" minOccurs="0"/>
<xsd:element name="ServiceVersion" type="tns:VersionType" minOccurs="0"/>
<xsd:element name="IBUSVersion" type="tns:VersionType" fixed="1.1.0"/>
</xsd:sequence>
</xsd:complexType>
<!-- X12 Transactions ONLY -->
<xsd:complexType name="TransactionHeaderType">
<xsd:sequence>
<xsd:element name="transactionSetIdentifierCode" type="xsd:string" minOccurs="0"/>
<xsd:element name="transactionSetControlNumber" type="xsd:string" minOccurs="0"/>
<xsd:element name="conventionReferenceNumber" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<!-- X12 Transactions ONLY -->
<xsd:complexType name="TransactionSegmentType">
<xsd:sequence>
<xsd:element name="structureCode" type="xsd:string" minOccurs="0"/>
<xsd:element name="transactionIdentifier" type="xsd:string" minOccurs="0"/>
<xsd:element name="transactionSetCreationDate" type="xsd:date" minOccurs="0"/>
<xsd:element name="transactionSetCreationTime" type="xsd:time" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="SourceType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="action" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="IBUSVariantType">
<xsd:sequence>
<xsd:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ReplyToStackType">
<xsd:sequence>
<xsd:element name="ReplyTo" type="tns:ReplyToStackEntry" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ReplyToStackEntry">
<xsd:sequence>
<xsd:element name="replyToQ" type="xsd:string"/>
<xsd:element name="replyToQMgr" type="xsd:string"/>
<xsd:element name="requestIdentifier" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="IBUSStatusType">
<xsd:sequence>
<xsd:element name="code" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="Messages" type="tns:MessagesType" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="MessagesType">
<xsd:sequence>
<xsd:element name="Message" type="tns:StatusMessageType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="StatusMessageType">
<xsd:sequence>
<xsd:element name="Reason" type="tns:StatusPairType"/>
<xsd:element name="type" type="xsd:string"/>
<xsd:element name="FollowUpAction" type="tns:StatusPairType" minOccurs="0"/>
<xsd:element name="Context" type="tns:StatusPairType" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="StatusPairType">
<xsd:sequence>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="code" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="ActionClassType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value=""/>
<xsd:enumeration value="GUI"/>
<xsd:enumeration value="BATCH"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="MessageResponseType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="ServiceRequest"/>
<xsd:enumeration value="ServiceResponse"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="VersionType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="RoutingTableType">
<xsd:sequence>
<xsd:element name="Route" type="tns:RouteType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="RouteType">
<xsd:sequence>
<xsd:element name="key" type="xsd:string"/>
<xsd:element name="routeOverride" type="xsd:string" minOccurs="0"/>
<xsd:element name="routeAppend" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="RetryType">
<xsd:sequence>
<xsd:element name="count" type="xsd:long" minOccurs="0"/>
<xsd:element name="delay" type="xsd:long" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I want to marshall an object of IBUSStatusType. To do that my code for marshalling as follows:
public static StringWriter getStringFromIBUSStatusType(IBUSStatusType iBUSStatusType) throws JAXBException
{
StringWriter stringWriter = new StringWriter();
JAXBContext jaxbContext = JAXBContext
.newInstance(com.myhealth.soa.ibus.v1_1.ObjectFactory.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
new DefaultNamespacePrefixMapper());
marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);
QName qName = new QName("com.myhealth.soa.ibus.v1_1", "iBUSStatusType");
JAXBElement<IBUSStatusType> root = new JAXBElement<>(qName, IBUSStatusType.class, iBUSStatusType);
marshaller.marshal(root, stringWriter);
return stringWriter;
}
I get this xml string when I do marshall IBUSStatusType object:
<ns2:iBUSStatusType xmlns:tns="http://soa.myhealth.com/ibus/v1.1.0" xmlns:ns2="com.myhealth.soa.ibus.v1_1"><tns:code>8</tns:code><tns:description>Completed With Warning</tns:description><tns:Messages><tns:Message><tns:Reason><tns:description>Subscriber's email missing</tns:description><tns:code>2187</tns:code></tns:Reason><tns:type>1</tns:type><tns:Context><tns:description>WARN</tns:description><tns:code>Policy=MissingSubscriberEmail</tns:code></tns:Context></tns:Message></tns:Messages></ns2:iBUSStatusType>
Well, now I want to Unmarshall this xml string I got from marshal process. And the code for Unmarshall:
public static com.myhealth.soa.ibus.v1_1.IBUSStatusType getIBUSStatusType(String xml)
throws JAXBException
{
JAXBContext jaxbContext = JAXBContext
.newInstance(com.myhealth.soa.ibus.v1_1.ObjectFactory.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return ((JAXBElement<IBUSStatusType>) jaxbUnmarshaller
.unmarshal(new StringReader(xml))).getValue();
}
I get this error when I do unmarshall on the generated xml string:
javax.xml.bind.UnmarshalException: unexpected element (uri:"com.myhealth.soa.ibus.v1_1", local:"iBUSStatusType"). Expected elements are <{http://soa.myhealth.com/ibus/v1.1.0}IBUSMessage>
Now provided that my namespaces are:
put("http://soa.myhealth.com/common/v1", "cmn");
put("http://soa.myhealth.com/MemberService/v1", "mems");
put("http://soa.myhealth.com/ibus/v1.1.0", "tns");
put("http://soa.myhealth.com/member/enrollment/v1", "menr");
Just look at your schema
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://soa.myhealth.com/ibus/v1.1.0" targetNamespace="http://soa.myhealth.com/ibus/v1.1.0" elementFormDefault="qualified">
<xsd:element name="IBUSMessage" type="tns:IBUSMessage"/>
<xsd:complexType name="IBUSMessage">
<xsd:sequence>
<xsd:element name="Header" type="tns:IBUSHeaderType"/>
<xsd:element name="Detail" type="tns:IBUSVariantType"/>
<xsd:element name="Status" type="tns:IBUSStatusType"/>
</xsd:sequence>
</xsd:complexType>
There is a namespace http://soa.myhealth.com/ibus/v1.1.0
And when you do unmarsalling it expects http://soa.myhealth.com/ibus/v1.1.0
but previously when you do marshalling you put the following namespace
QName qName = new QName("com.myhealth.soa.ibus.v1_1", "iBUSStatusType");
They are different.
Well, finally we made a solution. I am pasting my solution bellow. I did change the code according to #Iurii but the problem was somewhere else.
So, this is the change in Marshalling part. The 2nd paramater of QName must be the class name NOT the object of it. I tried to follow this link https://codenotfound.com/jaxb-marshal-element-missing-xmlrootelement-annotation.html but did not work. When changed the 2nd parameter of QName to Class name then it worked.
And the context should be made out of that class because ObjectFactory does not have it.
JAXBContext jaxbContext = JAXBContext.newInstance(IBUSStatusType.class);
QName qName = new QName("http://soa.independenthealth.com/ibus/v1.1.0", "IBUSStatusType");
JAXBElement<IBUSStatusType> root = new JAXBElement<IBUSStatusType>(qName, IBUSStatusType.class, iBUSStatusType);
And this is the whole Unmarshal code. We had to change the xml to node before unmarshall it. The import of Element is import org.w3c.dom.Element;
public static IBUSStatusType getIBUSStatusType(String xml)
throws JAXBException, SAXException, IOException, ParserConfigurationException
{
JAXBContext jaxbContext = JAXBContext
.newInstance(IBUSStatusType.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Element node = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(xml.getBytes()))
.getDocumentElement();
return ((JAXBElement<IBUSStatusType>) jaxbUnmarshaller.unmarshal(node, IBUSStatusType.class)).getValue();
}

'OR' operation on element type in XSD

This is a continuity of My question
Assume below is my xsd file,
Updated XSD file
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/wm" xmlns="http://www.example.com/wm" elementFormDefault="qualified" version="1.0">
<xsd:include schemaLocation="Comm.xsd" />
<xsd:element name="testEame1">
<xsd:annotation>
<xsd:documentation> test </xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:string" minOccurs="1" />
<xsd:element name="session" type="rawSess" minOccurs="1" />
</xsd:sequence>
<xsd:attribute name="pid" type="xsd:integer" use="required" />
<xsd:attribute name="version" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
references another XSD which has type defined,
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" targetNamespace="http://www.example.com/wm" xmlns="http://www.example.com/wm" elementFormDefault="qualified">
<xsd:complexType name="rawSess">
<xsd:sequence>
<xsd:element name="oldSessionVersion" type="Sessiontype1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="sessInfo">
<xsd:sequence>
<xsd:element name="newSessionVersion" type="Sessiontype2" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Sessiontype1">
<xsd:sequence>
<xsd:element name="ele1" type="xsd:string" minOccurs="0" />
<xsd:element name="ele2" type="xsd:string" />
<xsd:element name="ele3" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Sessiontype2">
<xsd:sequence>
<xsd:element name="nele1" type="xsd:integer" minOccurs="0" />
<xsd:element name="nele2" type="xsd:integer" />
<xsd:element name="nele3" type="xsd:integer" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
In the above xml, for element session , I want it to have only two types like below. Either sessInfo or rawSess
<xsd:element name="session" type='sessInfo| rawSess' minOccurs="1"/>
Update Note : userDefinedtypes are complex types.
How can I configure my xsd to achieve this
If userDefinedType1 and userDefinedType2 are simple atomic types, then define a union type:
<xs:element name="session" type="one-or-two"/>
<xs:simpleType name="one-or-two">
<xs:union memberTypes="userDefinedType1 userDefinedType2"/>
</xs:simpleType>
We now know that they are actually complex types. Define a type
<xs:complexType name="eitherType">
<xs:choice>
<xs:sequence>... content model of alternative 1</xs:sequence>
<xs:sequence>... content model of alternative 2</xs:sequence>
</xs:choice>
</xs:complexType>
and reference this type from the element declaration.
NB: this only works if there is no ambiguity, that is, if the validator can work out which branch of the choice to take based on the first element name that it sees in the instance document. If your choice were between two content models that both start with an h1 element, for example, you would have to reorganise the content models to remove the ambiguity.

wsdl2java generating ArrayOf<Type> instead of Type

I am using cfx wsdl2java to generate the server (java files). I'm having troubles with one java class. This java class is a complexType and looks like:
EDIT#1: As sugested by #matejko219
<xsd:complexType name="TService">
<xsd:sequence>
<xsd:element name="id"
type="xsd:int" />
<xsd:element name="st"
type="xsd:int" />
<xsd:element name="loc"
type="tns:TLoc" />
<xsd:element minOccurs="0" name="str"
type="xsd:string" />
<xsd:element name="ti"
type="xsd:int" />
<xsd:element name="nump"
type="xsd:int" />
<xsd:element name="prc"
type="xsd:int" />
<xsd:element minOccurs="0" name="dcrt"
type="xsd:dateTime" />
<xsd:element minOccurs="0" name="dini"
type="xsd:dateTime" />
<xsd:element minOccurs="0" name="dend"
type="xsd:dateTime" />
<xsd:element name="ct"
type="xsd:int" />
<xsd:element minOccurs="0" name="ins"
type="tns:TServiceInspections" />
<xsd:element name="id"
type="xsd:int" />
<xsd:element name="st"
type="xsd:int" />
<xsd:element name="loc"
type="tns:TLoc" />
<xsd:element minOccurs="0" name="str"
type="xsd:string" />
<xsd:element name="ti"
type="xsd:int" />
<xsd:element name="nump"
type="xsd:int" />
<xsd:element name="prc"
type="xsd:int" />
<xsd:element minOccurs="0" name="dcrt"
type="xsd:dateTime" />
<xsd:element minOccurs="0" name="dini"
type="xsd:dateTime" />
<xsd:element minOccurs="0" name="dend"
type="xsd:dateTime" />
<xsd:element name="ct"
type="xsd:int" />
<xsd:element minOccurs="0" name="ins"
type="tns:TServiceInspections" />
<xsd:element name="area"
type="xsd:int" />
<xsd:element minOccurs="0" name="desc"
type="xsd:string" />
<xsd:element minOccurs="0" name="tsins"
type="tns:TInspectionServices" />
<xsd:element name="nc"
type="xsd:boolean" />
<xsd:element name="order"
type="xsd:int" />
<xsd:element minOccurs="0" name="tasks"
type="tns:TServiceTasks"/>
</xsd:sequence>
</xsd:complexType>
The generated java file TService.java has the variables as ArrayOf
instead of just the types, for example in id.
/**
* Gets array of all "id" elements
*/
int[] getIdArray();
/**
* Gets ith "id" element
*/
int getIdArray(int i);
/**
* Gets (as xml) array of all "id" elements
*/
org.apache.xmlbeans.XmlInt[] xgetIdArray();
/**
* Gets (as xml) ith "id" element
*/
org.apache.xmlbeans.XmlInt xgetIdArray(int i);
/**
* Returns number of "id" element
*/
int sizeOfIdArray();
/**
* Sets array of all "id" element
*/
void setIdArray(int[] idArray);
/**
* Sets ith "id" element
*/
void setIdArray(int i, int id);
/**
* Sets (as xml) array of all "id" element
*/
void xsetIdArray(org.apache.xmlbeans.XmlInt[] idArray);
/**
* Sets (as xml) ith "id" element
*/
void xsetIdArray(int i, org.apache.xmlbeans.XmlInt id);
/**
* Inserts the value as the ith "id" element
*/
void insertId(int i, int id);
/**
* Appends the value as the last "id" element
*/
void addId(int id);
/**
* Inserts and returns a new empty value (as xml) as the ith "id" element
*/
org.apache.xmlbeans.XmlInt insertNewId(int i);
/**
* Appends and returns a new empty value (as xml) as the last "id" element
*/
org.apache.xmlbeans.XmlInt addNewId();
/**
* Removes the ith "id" element
*/
void removeId(int i);
Is something wrong with my wsdl file?
Thank you in advance!!
Some attributes were repeated, so wsdl2java read it as an array. The correct wsdl is:
<xsd:complexType name="TService">
<xsd:sequence>
<xsd:element name="id"
type="xsd:int" />
<xsd:element name="st"
type="xsd:int" />
<xsd:element name="loc"
type="tns:TLoc" />
<xsd:element minOccurs="0" name="str"
type="xsd:string" />
<xsd:element name="ti"
type="xsd:int" />
<xsd:element name="nump"
type="xsd:int" />
<xsd:element name="prc"
type="xsd:int" />
<xsd:element minOccurs="0" name="dcrt"
type="xsd:dateTime" />
<xsd:element minOccurs="0" name="dini"
type="xsd:dateTime" />
<xsd:element minOccurs="0" name="dend"
type="xsd:dateTime" />
<xsd:element name="ct"
type="xsd:int" />
<xsd:element minOccurs="0" name="ins"
type="tns:TServiceInspections" />
<xsd:element name="area"
type="xsd:int" />
<xsd:element minOccurs="0" name="desc"
type="xsd:string" />
<xsd:element minOccurs="0" name="tsins"
type="tns:TInspectionServices" />
<xsd:element name="nc"
type="xsd:boolean" />
<xsd:element name="order"
type="xsd:int" />
<xsd:element minOccurs="0" name="tasks"
type="tns:TServiceTasks"/>
</xsd:sequence>
</xsd:complexType>

xjc command not creating all classes defined in schema

Hello I am attempting to use xjc command to generate java objects from a .xsd file. The xsd file is massive and a portion of it can be seen below. When I run xjc on the following schema I get 3 classes UpsBas, MsgHdr, and Stm. However Stm should have a handfull of subclasses such as Ipr, Trs, or StmBpy. Why are these subclasses not being created?
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--uses CommercialInvoice v03.9, Shipment v03.7, Waybill v01.3, Manifest v01.8, Event v01.2, Declaration v01.8, BillingInvoice v01.2, Statements v01.3-->
<xsd:element name="UpsBas">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="MsgHdr"/>
<xsd:element ref="Stm" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="MsgHdr">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MsgFmtNr" type="xsd:string" minOccurs="1"/>
<xsd:element name="MsgFmtVerNr" type="xsd:string" minOccurs="1"/>
<xsd:element name="MsgInfSrcCd" type="xsd:string" minOccurs="1"/>
<xsd:element name="MsgOidNr" type="xsd:string" minOccurs="1"/>
<xsd:element name="MsgTs" type="xsd:string" minOccurs="1"/>
<xsd:element name="MsgVerNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="MsgVerMrNr" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Stm">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="StmNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="PrdStmNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmStsCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmRptDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="DlyStmRptDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmPrcDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmPrdSttDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmPrdEndDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="EntSmyPsnDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="NtcCrtDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="DocRcvDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="PmtDueDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="EntTypCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="EntNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="EntPorCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="PrcPorCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="StmTypCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="BkrRefNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="PmtTypCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="Ipr" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="IprNscNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="TotA" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ADscTe" type="xsd:string" minOccurs="0"/>
<xsd:element name="A" type="xsd:string" minOccurs="0"/>
<xsd:element name="FeeTypCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="ASeqNr" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Trs" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="TrsLinNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="PrdStmNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="RelDocNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="DocTypCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="DocRelDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="DocDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="IptDrcScyOptCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="PorCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="DocNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="PmtDueDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="UndRevIr" type="xsd:boolean" minOccurs="0"/>
<xsd:element name="StsCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="TrsDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="OthTrsIr" type="xsd:boolean" minOccurs="0"/>
<xsd:element name="PrcPorCd" type="xsd:string" minOccurs="0"/>
<xsd:element name="EntSmyPsnDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="DlyStmRptDt" type="xsd:string" minOccurs="0"/>
<xsd:element name="A" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ADscTe" type="xsd:string" minOccurs="0"/>
<xsd:element name="ASeqNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="A" type="xsd:string" minOccurs="0"/>
<xsd:element name="FeeTypCd" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="IprBpy" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="BpyNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="IprNa" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SeqNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="IprNa" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="StmBpy" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="BpyRlDscTe" type="xsd:string" minOccurs="0"/>
<xsd:element name="BpyIdDscTe" type="xsd:string" minOccurs="0"/>
<xsd:element name="BpyNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="BpyIdNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="BpyNa" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SeqNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="Na" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="DltEnt" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EntSmyNr" type="xsd:string" minOccurs="0"/>
<xsd:element name="DltSrcCd" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Please use the command prompt. The following is the way for generating from
wsdl.
See the link enter link description here
Use to following command to create the package:
xjc -xmlschema myXsdName.xsd
Use the following command to generate the jar:
jar cvf myJarName.jar packagename/*

Content type exception thrown for xsd validation in elements

I have an element A which can be of simple element as well as complex which gets created dynamically.
sample xml is here :
<A>john</A>
<A>
<B>kathy</B>
<C> bat </C>
</A>
my xsd is like this :
<xsd:element name="A">
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:sequence>
<xsd:element name="B" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="C" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
</xsd:element>
But here i am facing an exception which says :
Element 'A' cannot have character [children], because the type's content type is element-only
You need to specify mixed content in your type:
<xsd:element name="A">
<xs:complexType mixed="true">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:sequence>
<xsd:element name="B" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="C" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
Also it's a bit redundant having a sequence inside a choice. You either want a sequence or not.
Hope that helps.

Categories