XML数据建模工具 [英] XML Data modeling tools
问题描述
我想从为Java应用程序编写的XML创建模型类.有什么好的工具可以将我正在编写的XML转换为自动生成的类?我的XML文件中的示例.
< list name ="NameValuePairListDefinition"><成员target ="NameValuePair"/></list><结构名称="PositiveIntegerList"><成员名称=列表" target ="PositiveIntegerListDefinition"/></structure>
如果您正在使用Java,并且想生成类,我强烈建议您使用 注意:我还建议使用非保留Java关键字(例如 list )的元素名称,我不确定XMLBeans将如何处理它,但我假设它会要么稍微重命名,要么不重载. 这是一个完整的教程,可以派上用场: http://xmlbeans.apache.org/documentation/tutorial_getstarted.html 我假设您正在使用简单的直接XML调用或基于REST的Web服务,但是如果您决定使用更详细的信息(例如SOAP),那么 Apache Axis2 可以轻松地从SOAP XML消息或WSDL生成Java类. I want to create model classes from XML that I have written for my Java application.
What are some good tools to convert auto generated classes from the XML I am writing ?
A sample from my XML file.
If you're working with Java and want to generate classes I would highly suggest going with XMLbeans. It comes with some nice utilities, including: inst2xsd : given the xml , it generates xsd EXAMPLE (will generate xsd file and disable any enumerations of identical type) scomp : compiles the schema into a jar file, which means it generates a pretty nice reusable library for you which contains a class (or multiple classes) based on the namespace of the schema (or starting with noNamespace.something) if you didn't define any in your XML EXAMPLE (which creates xmltypes.jar - which is the jar you want, just rename it to something clever and use it for two-way parsing for getting & setting, reading & writing values) lastly, just launch your java IDE and add all the xmlbeans JARS and JAR for your schema created by scomp You can then load,create,store,manipulate, with your xmldata as it would just be java objects in your projects ;-) Based on the Element of your small XML snippet, you'd be accessing with code that looks roughly as follows: NOTE: Something I'd also suggest is using Element names that are not reserved Java keywords such as list, I'm not exactly sure how XMLBeans will handle it but I'm assuming it would either rename it slightly rather than overload. Here's a full tutorial which could come in handy:
http://xmlbeans.apache.org/documentation/tutorial_getstarted.html I made the assumption you are using simple direct XML calling or REST-based Web Services, but if you decided to use something more verbose like SOAP there are also Apache CXF and Apache Axis2 which can easily generate Java classes from SOAP XML messages or WSDLs. 这篇关于XML数据建模工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! <list name="NameValuePairListDefinition">
<member target="NameValuePair" />
</list>
<structure name="PositiveIntegerList">
<member name="list" target="PositiveIntegerListDefinition" />
</structure>
inst2xsd -enumerations never message.xml
scomp -jar yourschema mySchema.xsd
MyModel myModel = null;
try {
//full path to XML file
File modelXML = new File("Model.xml");
// Bind the incoming XML to an XMLBeans type.
myModel = MyModel.Factory.parse(modelXML);
}
catch (XmlException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
catch (FileNotFoundException e) { e.printStackTrace(); }
// Using the <structure> element.
Structure structure = myModel.getStructure();
Member member = structure.getMember();
String target = member.getTarget(); // "PositiveIntegerListDefinition"