Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Generate Java Code from XML Schema with XJC
How to generate Java code from XML Schema with XJC (XML to Java Compiler)?
✍: FYIcenter.com
If you have an XML Schema, you can create Java code to represent complex XML
elements as Java classes manually according to mapping rules given in the JAXB API specification.
But you can also using the XJC (XML to Java Compiler) tool to generate Java code automatically for you as presented in this tutorial:
1. Create an XML schema document called User.xsd:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) FYIcenter.com -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="User">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="BirthDate" type="xsd:date" />
<xsd:element name="Name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Sex">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Male" />
<xsd:enumeration value="Female" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="ID" type="xsd:int" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
2. Run XJC tool from the JAXB API Reference Implementation package. The script, xjc.sh, needs to be modified as shown in the last tutorial.
fyicenter$ ../jaxb-ri/bin/xjc.sh User.xsd Java major version: 15 parsing a schema... compiling a schema... generated/ObjectFactory.java generated/User.java
You get Java code of 2 Java classes:
⇒ User.java - Java Data Type Class Generated by XJC
⇐ What Is XJC (XML to Java Compiler)
2018-05-08, ∼1570🔥, 0💬
Popular Posts:
Jackson is "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java"....
maven-core-3.5.4.jar is the JAR file for Apache Maven 3.5.4 Core module. Apache Maven is a software ...
What Is poi-5.2.3.jar? poi-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which provides an...
commons-lang-1.0.1.jar is the JAR file for Apache Commons Lang 1.0.1, which provides a host of helpe...
JDK 11 jdk.scripting.nashorn.jm odis the JMOD file for JDK 11 Scripting Nashorn module. JDK 11 Scrip...