xml schema and java objects - java

I have received xml schema from a third party vendor. However the xml schema and the xml don't seem to match atleast that is my guess. I am using Intellij and use the JAXB plugin to get JAVA objects.
My code never returns the field values i.e. it never returns "my string value" back from xml
<field type="Address">
<value type="Value">my string value</value>
</field>
I get data back as
0 = {FieldType#1372}
characters = null
value = {FieldTypeType#1381} "ADDRESS"
value = {String#1383} "Address"
data = null
name = {String#1382} "ADDRESS"
ordinal = 8
1 = {FieldType#1373}
characters = null
value = {FieldTypeType#1387} "CARD_NUMBER"
2 = {FieldType#1374}
characters = null
value = {FieldTypeType#1389} "DATE"
3 = {FieldType#1375}
I have the xml as this (part of it)
<field type="Address">
<value type="Value">my string value</value>
</field>
<field type="CardNumber">
<value type="Value">xxxxx</value>
</field>
<field type="Date">
<value type="Day">21</value>
<value type="Month">4</value>
<value type="Year">2015</value>
</field>
<field type="Phone">
<value type="Value">212XXX</value>
</field>
<field type="SubTotal">
<value type="value">XXX</value>
</field>
and schema is
<xs:complexType name="receiptType">
<xs:sequence>
<xs:element name="field" type="tns:fieldType" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="lineItem" type="tns:lineItemType" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="recognizedText" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
</xs:sequence>
<xs:attribute name="paymentType" type="tns:paymentTypeType"></xs:attribute>
<xs:attribute name="cardType" type="tns:cardTypeType"></xs:attribute>
<xs:attribute name="currency" type="xs:string"></xs:attribute>
<xs:attribute name="purchaseType" type="xs:string"></xs:attribute>
</xs:complexType>
<xs:simpleType name="paymentTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="Card"></xs:enumeration>
<xs:enumeration value="Cash"></xs:enumeration>
<xs:enumeration value="Undefined"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="cardTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="AmericanExpress"></xs:enumeration>
<xs:enumeration value="EuroCard"></xs:enumeration>
<xs:enumeration value="MasterCard"></xs:enumeration>
<xs:enumeration value="Visa"></xs:enumeration>
<xs:enumeration value="Undefined"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="fieldType">
<xs:sequence>
<xs:element name="value" type="tns:valueType" minOccurs="1" maxOccurs="unbounded">
</xs:element>
<xs:element name="characters" type="tns:charactersType" minOccurs="0" maxOccurs="1"></xs:element>
</xs:sequence>
<xs:attribute name="value" type="tns:fieldTypeType"></xs:attribute>
</xs:complexType>
<xs:complexType name="valueType">
<xs:attribute name="type" type="tns:valueTypeType"></xs:attribute>
</xs:complexType>
<xs:simpleType name="valueTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="Value"></xs:enumeration>
<xs:enumeration value="Day"></xs:enumeration>
<xs:enumeration value="Month"></xs:enumeration>
<xs:enumeration value="Year"></xs:enumeration>
<xs:enumeration value="Hour"></xs:enumeration>
<xs:enumeration value="Minute"></xs:enumeration>
<xs:enumeration value="Second"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="fieldTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="Total"></xs:enumeration>
<xs:enumeration value="SubTotal"></xs:enumeration>
<xs:enumeration value="CardNumber"></xs:enumeration>
<xs:enumeration value="TotalTax"></xs:enumeration>
<xs:enumeration value="Tax"></xs:enumeration>
<xs:enumeration value="Date"></xs:enumeration>
<xs:enumeration value="Time"></xs:enumeration>
<xs:enumeration value="Vendor"></xs:enumeration>
<xs:enumeration value="Address"></xs:enumeration>
<xs:enumeration value="Phone"></xs:enumeration>
<xs:enumeration value="Fax"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
Appreciate all the help!

Related

org.xml.sax.SAXParseException: 'GovernmentIDType' is already defined

I a trying to generate Java classes from XSDs provided by third party. However I am getting the error as
[ERROR]
file:/Users/sanket/eblock/code/eblock-graphql/eblock-integration/autotec-auction-access-sqs/src/main/resources/xsd/COMP9.xsd[243,16]
org.xml.sax.SAXParseException: 'GovernmentIDType' is already defined
I am getting same errors for other elements too. I tried adding unique namespace to XSDs but that didn't work. The definition of this particular element 'GovernmentIDType', is different in both XSDs but name is similar.
COMP9.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by Charles Redden (AutoTec, LLC) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:include schemaLocation="Header9.xsd"/>
<xs:annotation>
<xs:documentation>Company Message</xs:documentation>
</xs:annotation>
<xs:element name="BondingCompany">
<xs:annotation>
<xs:documentation>Name of bonding company.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="75"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="BondExpirationDate">
<xs:annotation>
<xs:documentation>Expiration date of bond.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="BondNumber">
<xs:annotation>
<xs:documentation>Bond number as it appears on bond.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="BusinessStartDate">
<xs:annotation>
<xs:documentation>Date company came into business.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="CommercialAccountType">
<xs:annotation>
<xs:documentation>Type of commercial account.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Bank / Credit Union"/>
<xs:enumeration value="Financial Services Company"/>
<xs:enumeration value="Insurance Company"/>
<xs:enumeration value="Manufacturer"/>
<xs:enumeration value="Rental Car Company"/>
<xs:enumeration value="Captive Finance Company"/>
<xs:enumeration value="Fleet Company"/>
<xs:enumeration value="Government Agency"/>
<xs:enumeration value="Salvage/Scrap Company"/>
<xs:enumeration value="Other Business Organization"/>
<xs:enumeration value="Auction"/>
<xs:enumeration value="Non-Profit Company"/>
<xs:enumeration value="Public"/>
<xs:enumeration value="Title Loan Company"/>
<xs:enumeration value="Subprime Finance Company"/>
<xs:enumeration value="Transporter"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CompanyID">
<xs:annotation>
<xs:documentation>AutoTec Company ID</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:maxInclusive value="8999999"/>
<xs:minInclusive value="5000000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CompanyInformation">
<xs:complexType>
<xs:sequence>
<xs:element ref="CompanyID"/>
<xs:element ref="DBAName"/>
<xs:element ref="LegalName" minOccurs="0"/>
<xs:element ref="CompanyType"/>
<xs:element ref="GovernmentID" minOccurs="0"/>
<xs:element ref="GovernmentIDType" minOccurs="0"/>
<xs:element ref="GovernmentIDCountry" minOccurs="0"/>
<xs:element ref="EntityType" minOccurs="0"/>
<xs:element ref="PublicSaleOnly" minOccurs="0"/>
<xs:element ref="NICBNumber" minOccurs="0"/>
<xs:element ref="DunandBradstreetNumber" minOccurs="0"/>
<xs:element ref="InsuranceCompany" minOccurs="0"/>
<xs:element ref="PolicyNumber" minOccurs="0"/>
<xs:element ref="InsuranceExpirationDate" minOccurs="0"/>
<xs:element ref="BondingCompany" minOccurs="0"/>
<xs:element ref="BondNumber" minOccurs="0"/>
<xs:element ref="BondExpirationDate" minOccurs="0"/>
<xs:element ref="RIN" minOccurs="0"/>
<xs:element ref="GST" minOccurs="0"/>
<xs:element ref="BusinessStartDate" minOccurs="0"/>
<xs:element ref="OutOfBusiness" minOccurs="0"/>
<xs:element ref="OutOfBusinessDate" minOccurs="0"/>
<xs:element ref="MembershipExpirationDate" minOccurs="0"/>
<xs:element ref="CommercialAccountType" minOccurs="0"/>
<xs:element ref="ParentCompanyID" minOccurs="0"/>
<xs:element ref="Courier" minOccurs="0"/>
<xs:element ref="CourierAccount" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CompanyType">
<xs:annotation>
<xs:documentation>Indicates company's tax classification.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Sole Proprietorship"/>
<xs:enumeration value="General Partnership"/>
<xs:enumeration value="Limited Partnership"/>
<xs:enumeration value="Sub C Corporation"/>
<xs:enumeration value="Sub S Corporation"/>
<xs:enumeration value="LLC-Sole"/>
<xs:enumeration value="LLC-Partnership"/>
<xs:enumeration value="LLC-Corporation"/>
<xs:enumeration value="Business Corporation"/>
<xs:enumeration value="Limited Liability Company"/>
<xs:enumeration value="Unlimited Liability Corporation"/>
<xs:enumeration value="Government Agency"/>
<xs:enumeration value="Unknown"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Courier">
<xs:annotation>
<xs:documentation>Type of courier.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="No Courier"/>
<xs:enumeration value="Federal Express"/>
<xs:enumeration value="DHL"/>
<xs:enumeration value="United Parcel Service"/>
<xs:enumeration value="United States Postal Service"/>
<xs:enumeration value="Purolator"/>
<xs:enumeration value="Other"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CourierAccount">
<xs:annotation>
<xs:documentation>Courier Account number and information.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DBAName">
<xs:annotation>
<xs:documentation>Company's Doing Business As name.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DunandBradstreetNumber">
<xs:annotation>
<xs:documentation>ID issued to company by Dun and Bradstreet</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="9"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="EntityType">
<xs:annotation>
<xs:documentation>Indicates kind of entity in message. Note: The EntityType enumerations are consistent across all messages. The only values that pertain to this message are: Dealership and Commercial Account. Transporter is a future enhancement and may or may not be relevant to this message in the future.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Dealership"/>
<xs:enumeration value="Transporter"/>
<xs:enumeration value="Commercial Account"/>
<xs:enumeration value="Company Association"/>
<xs:enumeration value="Person"/>
<xs:enumeration value="Bank"/>
<xs:enumeration value="Bank Account"/>
<xs:enumeration value="Third Party Remarketing"/>
<xs:enumeration value="Customer Customization"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GovernmentID">
<xs:annotation>
<xs:documentation>Unique id issued by government.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GovernmentIDCountry">
<xs:annotation>
<xs:documentation>Issuing country of government id</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GovernmentIDType">
<xs:annotation>
<xs:documentation>Indicates type of government id.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="GovtPersonalID"/>
<xs:enumeration value="GovtID"/>
<xs:enumeration value="Passport"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GST">
<xs:annotation>
<xs:documentation>Goods and Services Tax number issued for Canadian companies.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{9}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="InsuranceCompany">
<xs:annotation>
<xs:documentation>Insurance company.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="75"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="InsuranceExpirationDate">
<xs:annotation>
<xs:documentation>Expiration date of insurance policy.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="LegalName">
<xs:annotation>
<xs:documentation>Legal Name of company based on licensing documents.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MembershipExpirationDate">
<xs:annotation>
<xs:documentation>Expiration date for company's AutoTec membership.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element ref="Header"/>
<xs:element ref="CompanyInformation"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NICBNumber">
<xs:annotation>
<xs:documentation>ID issued to company by National Insurance Crime Bureau.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="9"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="OutOfBusiness">
<xs:annotation>
<xs:documentation>Indicates whether a company is out of business. A 'Y' value will always be accompanied by an OutOfBusinessDate.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Y"/>
<xs:enumeration value="N"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="OutOfBusinessDate">
<xs:annotation>
<xs:documentation>Date company went out of business.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="ParentCompanyID">
<xs:annotation>
<xs:documentation>The AutoTec id of any group of which the company is a member.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:maxInclusive value="1200000000"/>
<xs:minInclusive value="1000000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="PolicyNumber">
<xs:annotation>
<xs:documentation>Insurance policy number.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="PublicSaleOnly">
<xs:annotation>
<xs:documentation>Indicates company is allowed to purchase in public sales only.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Y"/>
<xs:enumeration value="N"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="RIN">
<xs:annotation>
<xs:documentation>Registrant Identification Number issued by Canada to Ontario dealerships.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{9}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
</xs:schema>
person.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by Charles Redden (AutoTec, LLC) -->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="Header9.xsd"/>
<xs:annotation>
<xs:documentation>Person Message</xs:documentation>
</xs:annotation>
<xs:element name="CardSentToLocation">
<xs:annotation>
<xs:documentation>Location last card was mailed to</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="35"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CardSequence">
<xs:annotation>
<xs:documentation>Sequence Number of currently active card.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,2}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DateMostRecentCard">
<xs:annotation>
<xs:documentation>Date most recent card printed.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Deceased">
<xs:annotation>
<xs:documentation>Deceased status.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Y"/>
<xs:enumeration value="N"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DOB">
<xs:annotation>
<xs:documentation>Date of Birth.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="FirstName">
<xs:annotation>
<xs:documentation>Individual's first name.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GovernmentID">
<xs:annotation>
<xs:documentation>Unique identification issued by government.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GovernmentIDCountry">
<xs:annotation>
<xs:documentation>Issuing country of government ID.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="GovernmentIDType">
<xs:annotation>
<xs:documentation>Indicates type of government id.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="None"/>
<xs:enumeration value="Social Security Number"/>
<xs:enumeration value="Taxpayer Identification Number"/>
<xs:enumeration value="CURP"/>
<xs:enumeration value="Passport"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="IDVerificationScore" type="xs:int"/>
<xs:element name="LanguagePreference">
<xs:annotation>
<xs:documentation>Preferred language for communication.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="English"/>
<xs:enumeration value="Spanish"/>
<xs:enumeration value="French"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="LastName">
<xs:annotation>
<xs:documentation>Individual's last name.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MembershipExpirationDate">
<xs:annotation>
<xs:documentation>AutoTec renewal date for individual.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union memberTypes="xs:date">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element ref="Header"/>
<xs:element ref="PersonInformation"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="MiddleName">
<xs:annotation>
<xs:documentation>Individual's middle name.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="NickName">
<xs:annotation>
<xs:documentation>Individual's nickname.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="PersonID">
<xs:annotation>
<xs:documentation>AutoTec Individual ID.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="100000001"/>
<xs:maxInclusive value="199999999"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="PersonInformation">
<xs:complexType>
<xs:sequence>
<xs:element ref="PersonID"/>
<xs:element ref="FirstName"/>
<xs:element minOccurs="0" ref="MiddleName"/>
<xs:element ref="LastName"/>
<xs:element minOccurs="0" ref="Prefix"/>
<xs:element minOccurs="0" ref="Suffix"/>
<xs:element ref="GovernmentID"/>
<xs:element ref="GovernmentIDCountry"/>
<xs:element minOccurs="0" ref="GovernmentIDType"/>
<xs:element minOccurs="0" ref="DOB"/>
<xs:element minOccurs="0" ref="DateMostRecentCard"/>
<xs:element minOccurs="0" ref="CardSentToLocation"/>
<xs:element minOccurs="0" ref="NickName"/>
<xs:element ref="MembershipExpirationDate"/>
<xs:element ref="Deceased"/>
<xs:element ref="LanguagePreference"/>
<xs:element minOccurs="0" ref="PublicSaleOnly"/>
<xs:element minOccurs="0" ref="IDVerificationScore"/>
<xs:element ref="CardSequence"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Prefix">
<xs:annotation>
<xs:documentation>Individual's name prefix.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="PublicSaleOnly">
<xs:annotation>
<xs:documentation>Indicates individual may only purchase at a public sale.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Y"/>
<xs:enumeration value="N"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Suffix">
<xs:annotation>
<xs:documentation>Individual's name suffix.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
pom.xml
<build>
<plugins>
<!-- Plugin required to build java classes from XSD using XJC -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-commons-lang</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.sqs.dto</packageName>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<arguments>-Xcommons-lang</arguments>
</configuration>
</plugin>
</plugins>
</build>
I need some solution for this.
UPDATE: I tried adding Binding file as follow but still same error:
PER.xjb
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:bindings schemaLocation="../xsd/PER.xsd">
<jaxb:bindings node="//xs:element[#name='GovernmentIDType']/xs:simpleType">
<jaxb:property name="GovernmentIDTypePER" />
<!--<jaxb:factoryMethod name="GovernmentIDTypePER"/>-->
</jaxb:bindings>
<jaxb:bindings node="//xs:element[#name='GovernmentID']/xs:simpleType">
<jaxb:factoryMethod name="GovernmentIDPER"/>
<!--<jaxb:property name="GovernmentIDPER" />-->
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>

Converting Java class into XML Schema (XSD) file

I have a flat file having multiple records in each line. I've converted each of these records into separate XML files. Now, I need an XSD to validate these XMLs one after another. To generate the XSD, I've an excel mapping document describing each field positions , value and format. I've read the mapping document in a java-file. Now, I WANT TO CONVERT THIS JAVA FILE INTO AN XSD FILE to suffice my need. Hope my requirement is clear.
Please guide me with this problem. Thanks in advance!
Below is a sample XSD to be generated (currently I've prepared it manually). I need the source Java-file to programmatically generate this XSD-file.
XSD File:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Records" type="type_Records" />
<xs:complexType name="type_Records">
<xs:sequence>
<xs:element name="Record" type="type_Record" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="type_Record">
<xs:sequence>
<xs:element name="RecordIdentifier" type="type_RecordIdentifier" />
<xs:element name="AccountType" type="type_AccountType" />
<xs:element name="RoutingNumber8" type="type_RoutingNumber8" />
<xs:element name="RoutingNumberL" type="type_RoutingNumberL" />
<xs:element name="AccountNumber" type="type_AccountNumber" />
<xs:element name="Amount" type="type_Amount" />
<xs:element name="PolicyNumber" type="type_PolicyNumber" />
<xs:element name="AccountHolder" type="type_AccountHolder" />
<xs:element name="AccountSource" type="type_AccountSource" />
<xs:element name="AddendaRecordIdentifier" type="type_AddendaRecordIdentifier" />
<xs:element name="OriginatorIdCode" type="type_OriginatorIdCode" />
<xs:element name="SequenceNumber" type="type_SequenceNumber" />
</xs:sequence>
<xs:attribute name="id" type="type_RecordId" use="required" />
</xs:complexType>
<xs:simpleType name="type_RecordIdentifier">
<xs:restriction base="xs:string">
<xs:pattern value="6" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_AccountType">
<xs:restriction base="xs:string">
<xs:pattern value="27|37" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_RoutingNumber8">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{8}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_RoutingNumberL">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_AccountNumber">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{17}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_Amount">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{10}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_PolicyNumber">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]{10}[ ]{5}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_AccountHolder">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z ]{21}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_AccountSource">
<xs:restriction base="xs:string">
<xs:pattern value="S | " />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_AddendaRecordIdentifier">
<xs:restriction base="xs:string">
<xs:pattern value="0" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_OriginatorIdCode">
<xs:restriction base="xs:string">
<xs:pattern value="05310049" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_SequenceNumber">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{7}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="type_RecordId">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]*" />
</xs:restriction>
</xs:simpleType>
</xs:schema>

javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)

I am getting this error, while unmarshalling a string. I have created Java files using JAXB.
JAXBContext jaxbContext = JAXBContext.newInstance(DocumentType.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// Input string posted below
DocumentType dType = (DocumentType) unmarshaller.unmarshal(new StringReader("input string"));
Stack trace:
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd", local:"document"). Expected elements are (none)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:243)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:238)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1048)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:483)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:465)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3065)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:881)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:214)
at JaxbTest.main(JaxbTest.java:19)
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd"
elementFormDefault="qualified">
<xs:element name="document" type="tns:documentType"></xs:element>
<xs:complexType name="documentType">
<xs:sequence>
<xs:element name="businessCard" type="tns:businessCardType" minOccurs="0" maxOccurs="1"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="businessCardType">
<xs:sequence>
<xs:element name="field" type="tns:fieldType" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="fieldType">
<xs:sequence>
<xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
<xs:element name="characters" type="tns:charactersType" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="fieldComponents" type="tns:fieldComponentsType" minOccurs="0" maxOccurs="1"></xs:element>
</xs:sequence>
<xs:attribute name="type" type="tns:typeType"></xs:attribute>
</xs:complexType>
<xs:simpleType name="typeType">
<xs:restriction base="xs:string">
<xs:enumeration value="Name"></xs:enumeration>
<xs:enumeration value="Phone"></xs:enumeration>
<xs:enumeration value="Mobile"></xs:enumeration>
<xs:enumeration value="Fax"></xs:enumeration>
<xs:enumeration value="Company"></xs:enumeration>
<xs:enumeration value="Job"></xs:enumeration>
<xs:enumeration value="Address"></xs:enumeration>
<xs:enumeration value="Email"></xs:enumeration>
<xs:enumeration value="Web"></xs:enumeration>
<xs:enumeration value="Text"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="charactersType">
<xs:sequence>
<xs:element name="char" type="tns:charType" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="charType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="suspicious" type="xs:boolean" use="optional"></xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="fieldComponentsType">
<xs:sequence>
<xs:element name="fieldComponent" type="tns:fieldComponentType" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="fieldComponentType">
<xs:sequence>
<xs:element name="value" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
</xs:sequence>
<xs:attribute name="type" type="tns:fieldComponentTypeType"></xs:attribute>
</xs:complexType>
<xs:simpleType name="fieldComponentTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="FirstName"></xs:enumeration>
<xs:enumeration value="MiddleName"></xs:enumeration>
<xs:enumeration value="LastName"></xs:enumeration>
<xs:enumeration value="ExtraName"></xs:enumeration>
<xs:enumeration value="PhonePrefix"></xs:enumeration>
<xs:enumeration value="PhoneCountryCode"></xs:enumeration>
<xs:enumeration value="PhoneCode"></xs:enumeration>
<xs:enumeration value="PhoneBody"></xs:enumeration>
<xs:enumeration value="PhoneExtension"></xs:enumeration>
<xs:enumeration value="ZipCode"></xs:enumeration>
<xs:enumeration value="Country"></xs:enumeration>
<xs:enumeration value="City"></xs:enumeration>
<xs:enumeration value="StreetAddress"></xs:enumeration>
<xs:enumeration value="JobPosition"></xs:enumeration>
<xs:enumeration value="JobDepartment"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Input string:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd" xmlns="http://ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd">
<businessCard>
<field type="Phone">
<value>783-37-00</value>
</field>
<field type="Phone">
<value>783-37-01</value>
</field>
<field type="Fax">
<value>783-26-63</value>
</field>
<field type="Email">
<value>john_sm#abbyy.com</value>
</field>
<field type="Web">
<value>www.abbyy.com</value>
</field>
<field type="Address">
<value>Otradnaya str., 2b, bld.6, 127273, Moscow, Russia</value>
</field>
<field type="Name">
<value>John Smith</value>
</field>
<field type="Company">
<value>ABBYY Headquarters</value>
</field>
<field type="Job">
<value>Product Analyst</value>
</field>
<field type="Text">
<value>ABBYY ABBYY Headquarters John Smith Product Analyst ABBYY Headquarters Otradnaya str., 2b, bld.6, 127273, Moscow, Russia Tel: 783-37-00 Fax: 783-26-63 john_sm#abbyy.com www.abbyy.com </value>
</field>
</businessCard>
</document>
When you generate a JAXB model from an XML Schema, global elements that correspond to named complex types will have that metadata captured as an #XmlElementDecl annotation on a create method in the ObjectFactory class. Since you are creating the JAXBContext on just the DocumentType class this metadata isn't being processed. If you generated your JAXB model from an XML Schema then you should create the JAXBContext on the generated package name or ObjectFactory class to ensure all the necessary metadata is processed.
Example solution:
JAXBContext jaxbContext = JAXBContext.newInstance(my.generatedschema.dir.ObjectFactory.class);
DocumentType documentType = ((JAXBElement<DocumentType>) jaxbContext.createUnmarshaller().unmarshal(inputStream)).getValue();
Alternatively if you want to persist in using the DocumentType class.
Then you could just add the following annotation on top of your DocumentType class.
#XmlRootElement(name="document")
Note: the String value "document" refers to the name of the root tag of the xml message.
One of the reasons for this error is the use of the jaxb implementation from the jdk. I am not sure why such a problem can appear in pretty simple xml parsing situations. You may use the latest version of the jaxb library from a public maven repository:
http://mvnrepository.com
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.12</version>
</dependency>
In my case, I got this error when I imported incorrectly jakarta.xml.bind.annotation.XmlRootElement. The correct one should be javax.xml.bind.annotation.XmlRootElement
In our case we were getting UnmarshalException because a wrong Java package was specified in the following. The issue was resolved once the right package was in place:
#Bean
public Unmarshaller tmsUnmarshaller() {
final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller
.setPackagesToScan("java.package.to.generated.java.classes.for.xsd");
return jaxb2Marshaller;
}

JAXB xs:maxLength and minOccurs="0" didn't show in generated class by xsd

I have different complex type in a xsd schema And I use Jaxb to rapresent this on java class. I have rapresented with sucess complextype enumeration in a javaclass in this way:
<xs:element name="SistemaEmissione" type="SistemaEmissione" />
<xs:simpleType name="SistemaEmissione">
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
<xs:enumeration value="P"/>
<xs:enumeration value="G"/>
</xs:restriction>
</xs:simpleType>
but I can't rapresent this restriction in java generated class
<xs:element name="Master" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Both minOccurs="0" and maxLength value="15" was sown in generated java class.
Can Anyone help me? tnx
minOccurs="0"
minOccurs is captured in the required property on the #XmlElement annotation.
http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlElement.html#required()
xs:maxLength
This will not be captured in the metadata. If you want your object data to be validated you can set an instance of Schema on your Marshaller or Unmarshaller.
http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.html

My XSD does not validate the XML despite proper namespace declarations

The XSD <schema> tag:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.cmu.edu/ns/blank"
targetNamespace="http://www.cmu.edu/ns/blank"
elementFormDefault="qualified">
The root of the XML, <people> tag.
<people
xmlns="http://www.cmu.edu/ns/blank"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cmu.edu/ns/blank student.xsd">
How ever I get en error that:
cvc-elt.1.a: Cannot find the declaration of element 'people'
I know it has something to do with namespaces but I can not figure out what.
Please help
XML
<?xml version="1.0" encoding="UTF-8" ?>
<!-- <!DOCTYPE people SYSTEM "validator.dtd"> -->
<people
xmlns="http://www.cmu.edu/ns/blank"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cmu.edu/ns/blank student.xsd">
<student>
<name>John</name>
<course>Computer Technology</course>
<semester>6</semester>
<scheme>E</scheme>
</student>
<student>
<name>Foo</name>
<course>Industrial Electronics</course>
<semester>6</semester>
<scheme>E</scheme>
</student>
</people>
XSD
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.cmu.edu/ns/blank"
targetNamespace="http://www.cmu.edu/ns/blank"
elementFormDefault="qualified">
<xs:element name="people">
<xs:complexType>
<xs:sequence>
<xs:element name="student" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="course" type="xs:string" />
<xs:element name="semester">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
<xs:enumeration value="5" />
<xs:enumeration value="6" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="scheme">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value = "E|C" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The only thing that's not working is the schema location attribute's namespace. The XML Schema Instance namespace is:
http://www.w3.org/2001/XMLSchema-instance
instead of:
http://www.w3c.org/2001/XMLSchema-instance (you put a c in w3c)
For the given XML, the error is
The 'http://www.w3c.org/2001/XMLSchema-instance:schemaLocation' attribute is not declared.

Categories