简体   繁体   English

从xml生成Java类层次结构(plist)

[英]Generate java class hierarchy from xml (plist)

Are there any tools that can automatically generate java class hierarchy from xml (plist)? 有没有可以从xml(plist)自动生成Java类层次结构的工具?

Say we have: 说我们有:

<blah>
    <item />
    <item />
</blah>

And we need to get something like: 我们需要得到类似的东西:

class Blah {

Collection<Item> items;

}

...and so on and so forth ...等等等等

If I get it right, then the elements shall be transformed into class and field names. 如果我做对了,那么元素将被转换成类和字段名。

This can be done with a few lines of code: 这可以通过几行代码来完成:

  1. parse the xml document into a DOM 将xml文档解析为DOM
  2. walk through the DOM tree and create a java source file in memory (StringBuilder) 遍历DOM树并在内存中创建一个Java源文件(StringBuilder)
  3. write the source file to your file system 将源文件写入文件系统

Or use XSLT to create a transformation from your xml document to a java source file. 或使用XSLT创建从XML文档到Java源文件的转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM