Converting Java class into XML Schema (XSD) file - java

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>

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>

Src-resolve: Cannot Resolve The Name 'Flowers' To A(n) 'type Definition' Component

cI have an XML file that I need to read and it looks similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<flowers>
<flower name="rose">
<soilType>Podzolic</soilType>
<visualParameters>
<stemColor>Green</stemColor>
<leafColor>Red</leafColor>
<averageSize>50</averageSize>
</visualParameters>
<growingTips>
<LightType>photophilous</LightType>
<temperature>38</temperature>
<watering>1200</watering>
</growingTips>
<multiplying>bySeeds</multiplying>
<origin>Belarus</origin>
<description>Classic Choice</description>
</flower>
</flowers>
At build time I am using JAXB to generate my classes for XSD(this xsd is modified by few columns). When I try to validate it, it complains
Cannot Resolve The Name 'Flowers' To A(n) 'type Definition' Component.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="flowers" type="Flowers"></xs:element>
<xs:complexType name="flowers">
<xs:sequence>
<xs:element name="flower" type="flower" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:element name="flower" type="FlowerType"/>
<xs:complexType name="flower">
<xs:sequence>
<xs:element name="soilType" type="SoilType" minOccurs="0"/>
<xs:element name="visualParameters" type="VisualParameters" minOccurs="0"/>
<xs:element name="growingTips" type="growingTips" minOccurs="0"/>
<xs:element name="multiplyingType" type="multiplyingType" minOccurs="0"/>
<xs:element name="origin" type="xs:string" minOccurs="0"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
<xs:complexType name="growingTips">
<xs:sequence>
<xs:element name="temperature" type="xs:int"/>
<xs:element name="watering" type="xs:int"/>
</xs:sequence>
<xs:attribute name="value" type="lightingType"/>
</xs:complexType>
<xs:complexType name="VisualParameters">
<xs:sequence>
<xs:element name="stemColor" type="xs:string" minOccurs="0"/>
<xs:element name="leafColor" type="xs:string" minOccurs="0"/>
<xs:element name="averageSize" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="multiplyingType">
<xs:restriction base="SoilName"/>
</xs:simpleType>
<xs:complexType name="SoilType">
<xs:sequence>
<xs:element name="value" type="Soil" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="lightingType">
<xs:restriction base="xs:string">
<xs:enumeration value="photophilous"/>
<xs:enumeration value="unphotophilous"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SoilName">
<xs:restriction base="xs:string">
<xs:enumeration value="byLeafs"/>
<xs:enumeration value="byCutting"/>
<xs:enumeration value="bySeeds"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Soil">
<xs:restriction base="xs:string">
<xs:enumeration value="podzolic"/>
<xs:enumeration value="dirt"/>
<xs:enumeration value="sodPodzolic"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
How do I setup my schema to validate successfully the xml ?
I suspect the flowers element definition is the cause, it should probably read:
<xs:complexType name="flowers">
<xs:sequence>
<xs:element name="flower" type="flower" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

xml schema and java objects

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!

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