xjc生成xml实体对象

Java中提供了xjc [xml java change]的应用。


1. 将xml转换为xsd

登录https://www.freeformatter.com/xsd-generator.html在线转换xml为xsd;

xjc生成xml实体对象_第1张图片

注:

      XSD Design选择Salami Slice, 否则生成的实体会嵌套在一个Class里。


2. xjc命令:

命令格式

xjc [ options ] schema file/URL/dir/jar ... [-bbindinfo ] ...

参考: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/xjc.html

-d dir: By default, the XJC binding compiler generates the Java content classes in the current directory. Use this option to specify an alternate output directory. The output directory must already exist. The XJC binding compiler does not create it for you.

-p pkg: When you specify a target package with this command-line option, it overrides any binding customization for the package name and the default package name algorithm defined in the specification.

为避免中文乱码,请用以下命令:

java -Dfile.encoding=UTF-8 -cp C:\Java\jdk1.8.0_131\lib\tools.jar com.sun.tools.internal.xjc.Driver -p com.test.xml fileName.xsd

xjc生成xml实体对象_第2张图片

你可能感兴趣的:(xjc生成xml实体对象)