在 Java 中以编程方式从 XML 生成 XSD [英] Generate XSD from XML programmatically in Java
问题描述
我正在寻找一个轻量级的库,它允许我从 Java 中的 XML 生成 XSD(没有命令行工具).我知道这不是一种干净的生成方式,但在这种情况下我需要这样做.此外,XML 在结构方面非常简单.
I'm looking for a leightweight library that allows me to genereate an XSD from XML in Java (no commandline tool). I know that it is not a clean way to generate it, but in this case I need to do it. Also the XML is very simple in terms of structure.
我已经研究过 Trang,但是除了如何从命令行调用它之外,没有 API 文档.
I already looked into Trang, but there is no API documentation except how to call it from command line.
我还检查了 xsd-gen,但该库的问题是需要修改我找不到的源代码中的一些包声明.
Also I checked out xsd-gen, but the issue with that library is that one would need to modify some package declrations in the source code which I couldn't find.
还有其他建议吗?
推荐答案
我是工具 xsd-gen.我也将工具转换为库,并将工件上传到 Maven Central:
I am the author of the tool xsd-gen. I converted the tool to be a library as well, and uploaded the artifact to Maven Central:
<dependency>
<groupId>org.wiztools</groupId>
<artifactId>xsd-gen</artifactId>
<version>0.2.1</version>
</dependency>
现在在您的应用程序中用作库很简单:
Now it is simple to use as a library within your application:
import org.wiztools.xsdgen.XsdGen;
import java.io.File;
import java.io.FileOutputStream;
...
XsdGen gen = new XsdGen();
gen.parse(new File("in.xml"));
File out = new File("out.xsd");
gen.write(new FileOutputStream(out));
这篇关于在 Java 中以编程方式从 XML 生成 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!