简体   繁体   English

使用JAXB支持XSD版本控制

[英]Support XSD versioning with JAXB

I am currently working on an application that performs the task of importing or exporting some entities. 我目前正在处理执行导入或导出某些实体任务的应用程序。 The file format being used for the same is XML . 用于同一文件格式是XML JAXB is being used for XML binding. JAXB用于XML绑定。

The problem is present XSD that defines the structure of entities has no provision for versioning. 目前存在的问题是XSD定义了实体的结构,没有提供版本控制的准备。 How do I get started with defining versioned XSD and subsequently XML instance documents provided JAXB lies as the underlying binding framework ? 如果以JAXB作为基础绑定框架,我如何开始定义版本化的XSD和随后的XML实例文档?

I have read that there are three possible ways of introducing versions in XSD . 我已经读到有三种在XSD中引入版本的可能方法。
1) Change the internal schema version attribute 1)更改内部架构版本属性
2) Create a attribute like schemaVersion on the root element 2)在根元素上创建一个诸如schemaVersion之类的属性
3) Change the schema's target namespace. 3)更改架构的目标名称空间。
Which one best suits the usecase mentioned below? 哪一个最适合下面提到的用例?

Use case: The changes made to the XSD in the next version may invalidate the existing elements. 用例:在下一版本中对XSD所做的更改可能会使现有元素无效。 Although the schema itself may not be backward compatible but the application needs to provides support for handling all versions of schema. 尽管模式本身可能不向后兼容,但是应用程序需要提供对所有版本模式的支持。

XML is designed to facilitate change and flexibility in document structures. XML旨在促进文档结构的更改和灵活性。 Unfortunately, JAXB isn't. 不幸的是,JAXB不是。 The very act of compiling knowledge of document structure into your Java source code makes change to the document structure a lot more difficult. 将文档结构的知识编译到Java源代码中的行为使更改文档结构变得更加困难。

If structural change is part of your agenda, I think you should seriously consider not using JAXB: technologies like XQuery and XSLT are much better suited to this scenario. 如果结构更改是您日程的一部分,我认为您应该认真考虑不使用JAXB:XQuery和XSLT之类的技术更适合这种情况。

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

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