Skip to content

Instantly share code, notes, and snippets.

@payliu
Last active December 27, 2015 13:18
Show Gist options
  • Save payliu/7331894 to your computer and use it in GitHub Desktop.
Save payliu/7331894 to your computer and use it in GitHub Desktop.
JAXB, xsd to java with binding configuration file
<jxb:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="Recipe.xsd">
<jxb:bindings node="//xsd:element[@name='Currency']">
<jxb:class ref="com.sample.finance.common.CurrencyCodeEnum"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
<?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
xjc -d $output common.xsd
xjc -d $output Recipe.xsd -b bindings.xjb
<?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"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:complexType name="Amount">
<xsd:sequence>
<xsd:element name="Currency" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment