Skip to content

Instantly share code, notes, and snippets.

@payliu
Last active December 27, 2015 13:18
Show Gist options
  • Save payliu/7331818 to your computer and use it in GitHub Desktop.
Save payliu/7331818 to your computer and use it in GitHub Desktop.
JAXB, xsd to java,
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:com:sample:common"
xmlns="urn:com:sample:common"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- here, declare namespace: targetNamespace and xmlns-->
<xsd:simpleType name="CurrencyCodeEnum">
<xsd:restriction base="xsd:string">
<xsd:minLength value="3"/>
<xsd:maxLength value="3"/>
<xsd:pattern value=""/>
<xsd:enumeration value="AED"/>
<xsd:enumeration value="AFN"/>
<xsd:enumeration value="ALL"/>
<xsd:enumeration value="AMD"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
#!/bin/bash
output='gen'
rm -rf $output
mkdir $output
# generate java to "gen" folder
xjc -d $output Recipe.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:com:sample:Finance"
targetNamespace="urn:com:sample:Finance"
xmlns:prefixName="urn:com:sample:common"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- here, see: 'xmlns:prefixName' -->
<xsd:import schemaLocation="common.xsd" namespace="urn:com:sample:common"/> <!-- add import here -->
<xsd:complexType name="Amount">
<xsd:sequence>
<xsd:element name="Currency"
type="prefixName:CurrencyCodeEnum" /> <!-- imported type-->
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment