首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用XML生成JAXB类

使用XML生成JAXB类
EN

Stack Overflow用户
提问于 2015-09-25 16:23:10
回答 2查看 1.5K关注 0票数 1

我有一个XML文档,第一行如下:(给出了一个internet explorer屏幕截图,因为它突出显示了更好的内容,内容也可以在底部以文本的形式提供)

我想生成一种更好的方法来解析这些特定的发票文档。它在第一行给出了自己的模式位置,所以我用谷歌搜索了一下,找到了以下文档:http://docs.oasis-open.org/ubl/os-UBL-2.0/xsd/maindoc/UBL-Invoice-2.0.xsd。我试图执行xjc来创建类,但它没有找到它所需的其他类:(它们在web上,但是我如何下载它们,或者只是告诉xjc从docs.oasis-open.org中查找?)

代码语言:javascript
复制
# xjc UBL-Invoice-2.0.xsd
parsing a schema...
[WARNING] schema_reference.4: Failed to read schema document '../common/UBL-CommonAggregateComponents-2.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
  line 21 of file:/root/abc/UBL-Invoice-2.0.xsd

我们也得到了一些XSD文件的政府在http://efatura.gov.tr/dosyalar/kilavuzlar/e-FaturaPaketi.zip,但他们没有一个有UBLTR-Invoice-2.0.xsd在其中。我只想问一下,这个模式是Invoice-2还是UBLTR-Invoice-2.0.xsd

代码语言:javascript
复制
<?xml version="1.0"?>
<Invoice xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 UBLTR-Invoice-2.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:ubltr="urn:oasis:names:specification:ubl:schema:xsd:TurkishCustomizationExtensionComponents" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ext:UBLExtensions>
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
<cbc:CustomizationID>TR1.0</cbc:CustomizationID>
<cbc:ProfileID>TEMELFATURA</cbc:ProfileID>
.......

我真的需要一些指针,我没有足够的经验与XML/XSD和任何方向都会很好。

EN

回答 2

Stack Overflow用户

发布于 2015-09-25 16:34:23

您可以打开以下文档。我在发票的页眉上找到了文件的链接。打开文档时,只需右键单击并将其另存为name.xsd即可

您需要的xsd:

  • Invoice
  • CommonAggregateComponents
  • CommonBasicComponents
  • UnqualifiedDataTypeSchemaModule
  • CommonExtensionComponents
  • QualifiedDatatypes

只需将它们添加到您的项目(所有相同的目录)。然后对主xsd (发票)运行xjc,您就可以正常工作了。

通常,您不必手动下载它们,但是发票中的引用不正确,因此jaxb不能自动解析引用。

如果仍然不起作用,只需编辑invoice.xsd中的导入路径,使其与下载文件的数据结构相匹配。

票数 2
EN

Stack Overflow用户

发布于 2015-09-30 14:44:50

有许多可用的工具(快速的google搜索应该会为您提供一些),它们可以从XML生成XSD,假设字符串类型几乎适用于所有内容。您应该能够使用该XSD运行JAXB来获取类。

这里有一个在线工具可以让你做到这一点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32777863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档