我想让maven完全自动地做这样的事情。我有一个包含一些数据的.xml文件。在这个xml中有一些通过is从一个对象到另一个对象的引用,依此类推。我没有这个.xml的.xsd。
我只需要两件事: 1)将这个xml编译成Java类。2)创建一个以此.xml名称命名的单例类,其中包含与内部.xml结构相关的所有.xml数据。
例如,我的.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<MyBigSinletonWithAllData>
<Cars>
<Car id="1" speed = "5"/>
<Car id="2" speed = "3"/>
</Cars>
</MyBigSinletonWithAllData>我想要像这样的东西,作为自动输出:
class MyBigSinletonWithAllData {
List<Cars> cars;
}
class Car {
double speed;
}
class MyBigSinletonWithAllDataSingleton {
MyBigSinletonWithAllData INSTANCE = new MyBigSinletonWithAllData();
/* And here we read an INSTANCE from our .xml file */
}因此,我的问题是如何通过Maven全自动完成此操作?我不想手动编写"MyBigSinletonWithAllDataSingleton",我只想让它已经为我生成,所以我只需要像这样编写代码行:
MyBigSinletonWithAllDataSingleton.INSTANCE要获得对所有写入相关.xml文件的数据的完全访问权限。
现在,我使用"maven-jaxb2-plugin“从.xsd生成Java类;但我还需要一个从.xml执行.xsd的工具,以及一个自动创建对单例的读/写操作的工具。
发布于 2017-03-10 16:30:27
在基于Java SOAP cxf服务中,有不同的实现,如apache axis和apche cxf。在这些实现中,我们有要运行的工具,或者只是将XML文件传递给该工具,这样就会生成相应的绑定类。
请查看他们的代码,以便对您有所帮助。或者可能会有一些不同的工具(Google it)。
是的,您可以将xml转换为xsd文件。浏览链接
Conver XML to XSD
https://stackoverflow.com/questions/42711893
复制相似问题