为给定的XML Schema生成Stax Writer API

时间:2014-09-25 09:29:12

标签: xml xsd stax

我有一个XML Schema。我已经在Stax上写了一个薄层,以便“动态”生成符合要求的文档(我不需要类似dom的API,我需要低/无占用空间)。 API只有以下方法:

writeCar(String manufacturer)
writeWheels(String manufacturer, boolean winter)
...

执行状态检查,然后调用适当的stax方法。

一个专长是没有writeEndXXX方法(我的架构是不明确的,因此你不能在wheel元素中有任何汽车。这意味着我总是知道何时关闭打开的元素)。唯一的例外是有一个flush(),它将写入所有挂起的结束标记。

writeCar(..)   // <car>
writeWheels(..) // inside the car <wheels>
writeCar(..) // close the pending tags </wheels></car> and new car <car>
flush() // this writes all pending close tags

这很好用。现在架构发展了:)

我现在正在手动更新API。因为我很有道德,我真的不想这样做:)。在给定XML Schema定义的情况下,是否有可用于生成此API(或类似)的工具?

1 个答案:

答案 0 :(得分:0)

基于JAXB

  1. 从XML生成XSD。您也可以使用this link或其他工具正常使用。
  2. 通过XJC,Maven插件see here
  3. 从XSD生成类
  4. 使用任何JAXB教程执行编组和解组以读取和写入xml。 see here
  5. 我建议你也这些链接

    我希望它可以帮到你