使用XML

时间:2015-09-25 08:23:10

标签: java xml xsd jaxb

我有一个XML文档,其中第一行是这样的:(给出一个Internet Explorer截图,因为它突出显示更好,内容也可以作为文本在底部提供)

Screenshot

我想生成一种更好的方法来解析这些特定的Invoice文档。它在第一行Invoice-2给出了自己的架构位置,因此我搜索了它并找到了以下文档:http://docs.oasis-open.org/ubl/os-UBL-2.0/xsd/maindoc/UBL-Invoice-2.0.xsd。我试图强制xjc来创建类,但它没有找到它的其他必需类:(它们在网上,但我怎样才能全部下载它们或者只是告诉xjc来看看docs.oasis-open.org ?)

# 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

政府还在http://efatura.gov.tr/dosyalar/kilavuzlar/e-FaturaPaketi.zip中提供了一些XSD文件,但其中没有一个UBLTR-Invoice-2.0.xsd。我只想问一下,这个架构是Invoice-2还是UBLTR-Invoice-2.0.xsd

<?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经验,任何方向都会很好。

2 个答案:

答案 0 :(得分:2)

您可以打开以下文件。我找到了发票标题中文件的链接。当您打开文档时,只需右键单击并将其保存为name.xsd

您需要的xsd&#39; s:

只需将它们添加到您的项目(所有相同的目录)。然后运行xjc为主xsd(发票),你们都应该工作正常。

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

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

答案 1 :(得分:1)

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

这是一款可以让您这样做的在线工具。

相关问题