当前位置: 首页 > 知识库问答 >
问题:

使用XJC将XML模式转换为java类

顾亦
2023-03-14

我使用的是从这里下载的官方XSD模式:

http://docs.oasis-open.org/ubl/os-UBL-2.0.zip

(路径:xsd/maindoc/UBL-Order-2.0.xsd)

当我使用下面的命令用XJC生成java类时,我总是在控制台上得到一个错误,我不知道如何处理。

命令:

xjc -d C:\Users\Oscar\Desktop\results -p com.ubl.order C:\Users\Oscar\Desktop\os-UBL-2.0\xsd\maindoc\UBL-Order-2.0.xsd

错误:

parsing a schema...
[WARNING] Simple type "UnitCodeContentType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 1.093, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
  line 38 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/CodeList_UnitCode_UNECE_7_04.xsd

[WARNING] Simple type "BinaryObjectMimeCodeContentType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 616, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
  line 38 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/CodeList_MIMEMediaTypeCode_IANA_7_04.xsd

[WARNING] Simple type "LanguageCodeContentType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 276, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.
  line 38 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/CodeList_LanguageCode_ISO_7_04.xsd

compiling a schema...
[ERROR] A class/interface with the same name "com.ubl.order.LocationType" is already in use. Use a class customization to resolve this conflict.
  line 9890 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonAggregateComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LocationType" is generated from here.
  line 1543 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.TextType" is already in use. Use a class customization to resolve this conflict.
  line 2598 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "TextType" is generated from here.
  line 1070 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.NameType" is already in use. Use a class customization to resolve this conflict.
  line 1718 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "NameType" is generated from here.
  line 1105 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.AmountType" is already in use. Use a class customization to resolve this conflict.
  line 613 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "AmountType" is generated from here.
  line 57 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.MeasureType" is already in use. Use a class customization to resolve this conflict.
  line 1668 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "MeasureType" is generated from here.
  line 930 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.QuantityType" is already in use. Use a class customization to resolve this conflict.
  line 2143 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "QuantityType" is generated from here.
  line 1035 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.ChannelCodeType" is already in use. Use a class customization to resolve this conflict.
  line 763 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "ChannelCodeType" is generated from here.
  line 119 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.DocumentStatusCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1103 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "DocumentStatusCodeType" is generated from here.
  line 618 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.PackagingTypeCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1873 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "PackagingTypeCodeType" is generated from here.
  line 1113 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.TransportModeCodeType" is already in use. Use a class customization to resolve this conflict.
  line 2753 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "TransportModeCodeType" is generated from here.
  line 1708 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.AllowanceChargeReasonCodeType" is already in use. Use a class customization to resolve this conflict.
  line 603 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "AllowanceChargeReasonCodeType" is generated from here.
  line 19 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.TransportEquipmentTypeCodeType" is already in use. Use a class customization to resolve this conflict.
  line 2728 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "TransportEquipmentTypeCodeType" is generated from here.
  line 1609 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.PaymentMeansCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1978 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "PaymentMeansCodeType" is generated from here.
  line 1212 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.CurrencyCodeType" is already in use. Use a class customization to resolve this conflict.
  line 913 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "CurrencyCodeType" is generated from here.
  line 517 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.LongitudeDirectionCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1563 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LongitudeDirectionCodeType" is generated from here.
  line 915 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.SubstitutionStatusCodeType" is already in use. Use a class customization to resolve this conflict.
  line 2478 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "SubstitutionStatusCodeType" is generated from here.
  line 1411 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.LineStatusCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1528 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LineStatusCodeType" is generated from here.
  line 816 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] A class/interface with the same name "com.ubl.order.LatitudeDirectionCodeType" is already in use. Use a class customization to resolve this conflict.
  line 1468 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Relevant to above error) another "LatitudeDirectionCodeType" is generated from here.
  line 717 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 9890 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonAggregateComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1543 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2598 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1070 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1718 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1105 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 613 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 57 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1668 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 930 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2143 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1035 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UnqualifiedDataTypeSchemaModule-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 763 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 119 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1103 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 618 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1873 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1113 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2753 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1708 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 603 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 19 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2728 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1609 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1978 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1212 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 913 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 517 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1563 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 915 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 2478 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 1411 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1528 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 816 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 1468 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 717 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-QualifiedDatatypes-2.0.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 166 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonAggregateComponents-2.0.xsd

[ERROR] (Related to above error) This is the other declaration.
  line 230 of file:/C:/Users/Oscar/Desktop/os-UBL-2.0/xsd/common/UBL-CommonBasicComponents-2.0.xsd

Failed to produce code.

我尝试的是不使用普通的XSD,而是使用trang.jar.生成我自己的XSD。结果很好,我得到了我生成的java类,但是当我用JAXB(使用这些类)创建一个XML文档时,名称空间就不好了。

所以,我想要的是使用经过修改(可能)的官方XSD使其工作。

我如何解决这个问题来获得我生成的类?

提前谢谢。

共有2个答案

孙凌
2023-03-14

我创建了一个库,它封装了所有UBL2.0和2.1生成的文件,以及一些用于Java1.6和Maven的健全方法。看看https://github.com/phax/ph-ubl详细信息。

高勇
2023-03-14

试试这个。

  1. 确保您的JDK版本为1.6或更高版本
 类似资料:
  • 我想将XML转换为JSON(具体地说,是OAI-PMH响应)。我目前正在使用这个节点。JSXML2JS,但问题是JSON非常冗长,有很多嵌套和数组级别,即使只有一个元素作为子元素,并且永远不会超过一个。问题是,不知道XML文件的模式,因此必须保守。 我的问题是,是否有任何其他(最好是JavaScript)代码可以使用XML架构来指导转换过程?因此,如果架构定义了XML的类型和结构,那么JSON就会

  • XML输入文件: XML输入文件转换为XML输出文件。将XML输入文件的firstName、middleName和lastName标签合并为XML Ouput文件的name标签,将XML输入文件的address1、address2、city、state和pincode标签合并为XML Ouput文件的address标签。 我几乎转换了代码,但我在这里与empId作斗争。我已经在XSLT文件中手动输

  • 问题内容: 我有一组CSV数据要转换为XML。代码看起来不错,但是输出不够完美。它忽略了一些列,因为它们没有值,并且产生了很长的XML数据行,而不是破坏它。 这是我的CSV数据示例: 而我的代码: 当对以上数据执行此代码时,将产生: 我本人以这种形式安排它,但是输出结果很长。产生的输出应为: 问题答案: 我同意Kennet。 我只是添加了 这在元素之间添加了新行,并允许缩进。 更新 首先,我们要介

  • 问题内容: 我想将输入的Excel文件转换为输出XML文件。 如果有人在Java中对如何获取输入Excel文件以及如何将XML写入输出有任何解决方案,请提供任何代码或URL或任何其他解决方案。 谢谢, 米沙尔·沙(Mishal Shah) 问题答案: 查看jexcel或Apache POI库以读取Excel文件。 创建XML文件很简单,只需将XML直接写到文件中,或附加到XML文档中,然后使用标准

  • 问题内容: 我有一个JSON文件,在此JSON文件中使用解析器将其转换为XML格式,然后写回xml文件 我在Groovy中找不到有关如何执行此操作的任何示例 如果我有如下所示的JSON: 然后,应将其转换为如下所示的XML: 我一直在寻找JSON到XML转换代码 问题答案: 如果您使JSON有效(将名称四舍五入,并且在初始块中加一个逗号),则可以执行此操作以将其转换(专门针对此示例) 我不知道将x

  • 我想将 xml 文件转换为路径。 例如,我有一个xml文件,其中包含: 我想要的结果是这样的: Person.name = 测试, person . address . address 1 = Test。 有什么解决办法能让我这么做吗?