做网站必须要数据库么,搜索引擎营销总结,手机网页打不开是什么原因,企业网站管理系统有哪些jaxb 生成java类在本文中#xff0c;我将演示如何利用XJC扩展来重用以前从XML模式生成的类。 当其他XML架构导入XML架构并且您不想每次都生成相同的类时#xff0c;这很有用。 导入的架构#xff08;Product.xsd#xff09; 以下XML模式代表有关产品的基本信息。 产品是此… jaxb 生成java类 在本文中我将演示如何利用XJC扩展来重用以前从XML模式生成的类。 当其他XML架构导入XML架构并且您不想每次都生成相同的类时这很有用。 导入的架构Product.xsd 以下XML模式代表有关产品的基本信息。 产品是此示例域中的通用概念因此我决定定义一种可以被其他模式利用的表示形式而不是让每个模式都定义自己的产品信息表示形式。 ?xml version1.0 encodingUTF-8?
schemaxmlnshttp://www.w3.org/2001/XMLSchema targetNamespace http://www.example.org/Product xmlns:tns http://www.example.org/Product elementFormDefaultqualifiedelement nameproductcomplexTypesequenceelement nameid typestring/element namename typestring//sequence/complexType/element
/schema由于多个XML模式导入Product.xsd我们可以利用情节文件以便与Product.xsd对应的类仅生成一次。 以下XJC调用演示了如何生成称为product的情节文件。 情节以及生成的类 xjc -d out -episode product.episode Product.xsd 导入架构ProductPurchaseRequest.xsd 以下是导入Product.xsd的XML模式的示例 ?xml version1.0 encodingUTF-8?
schemaxmlnshttp://www.w3.org/2001/XMLSchema targetNamespace http://www.example.org/ProductPurchaseRequest xmlns:tns http://www.example.org/ProductPurchaseRequest xmlns:prod http://www.example.org/Product elementFormDefaultqualifiedimport namespace http://www.example.org/Product schemaLocationProduct.xsd/element namepurchase-requestcomplexTypesequenceelement refprod:product maxOccursunbounded//sequence/complexType/element
/schema从XML模式生成类时将引用从Product.xsd生成Java类时创建的情节文件。 如果我们未指定情节文件则将为ProductPurchaseRequest.xsd和Product.xsd生成类 另一个导入模式ProductQuoteRequest.xsd 以下是导入Product.xsd的XML模式的另一个示例 ?xml version1.0 encodingUTF-8?
schemaxmlnshttp://www.w3.org/2001/XMLSchema targetNamespace http://www.example.org/ProductQuoteRequest xmlns:tns http://www.example.org/ProductQuoteRequest xmlns:prod http://www.example.org/Product elementFormDefaultqualifiedimport namespace http://www.example.org/Product schemaLocationProduct.xsd/element namequotecomplexTypesequenceelement refprod:product//sequence/complexType/element
/schema同样当我们从该XML模式生成类时我们将引用从Product.xsd生成Java类时创建的情节文件。 xjc -d out ProductQuoteRequest.xsd -extension -b product.episode 它是如何工作的 product.episode 对于你们中的那些人来说这很奇怪。 XJC生成的情节文件实际上只是一个用于自定义类生成的标准JAXB绑定文件。 生成的绑定/情节文件包含一些条目这些条目告诉XJC此类型的类已经存在。 您可以手工编写此文件但是XJC的-episode标志可以帮您完成。 ?xml version1.0 encodingUTF-8 standaloneyes?
bindings version2.1 xmlnshttp://java.sun.com/xml/ns/jaxb
!--This file was generated by the JavaTM Architecture for XML Binding
(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 See
a href http://java.sun.com/xml/jaxb http://java.sun.com/xml/jaxb /a
Any modifications to this file will be lost upon recompilation of the
source schema.
Generated on: 2011.11.02 at 03:40:10 PM EDT --
bindings scdx-schema::tns
xmlns:tns http://www.example.org/Product
schemaBindings mapfalse/
bindings scdtns:product
class reforg.example.product.Product/
/bindings
/bindings
/bindings 参考 Java XML和JSON绑定博客中的JCG合作伙伴 Blaise Doughan 重用了生成的JAXB类 。 相关文章 使用JAXB从XSD生成XML 将对象映射到多个XML模式–天气示例 翻译自: https://www.javacodegeeks.com/2011/12/reusing-generated-jaxb-classes.htmljaxb 生成java类