gpt4 book ai didi

JAXB 无法生成 XBRL 的 Java 类

转载 作者:行者123 更新时间:2023-12-03 04:35:43 26 4
gpt4 key购买 nike

我正在尝试为 XBRL 中定义的类型生成 Java 类。

我的构建过程基于 Maven 2,以下是我的试验。我只粘贴build部分,它依赖于一些属性:

package是我的目标包的名称

catalog是目录的路径和文件名。因为我没有互联网连接,所以我有很多条目,但我认为这些总是必要的

-- TR9401 for XBRL resources --
SYSTEM http://www.xbrl.org/2003/XLink http/www.xbrl.org/2003/xl-2003-12-31.xsd
SYSTEM http://www.w3.org/1999/xlink http/www.xbrl.org/2003/xlink-2003-12-31.xsd

xsd.path是XSD所在的目录

xsd.file就是下面这个极简XSD的文件名

     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.xbrl.org/2003/instance"
schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>
</xs:schema>

我尝试过的所有插件都无法导入xl:nonEmptyURI .

但是xl映射到http://www.xbrl.org/2003/XLink (在我的目录中)导入 <import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink-2003-12-31.xsd"/>它定义了 nonEmptyURI

怎么了?我该如何修复它?

Apache CXF

        <plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<xsdOptions>
<xsdOption>
<catalog>${catalog}</catalog>
<xsd>${xsd.path}/${xsd.file}</xsd>
<packagename>${package}</packagename>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>

失败

parsing a schema...

[ERROR] src-resolve: Cannot resolve the name 'xl:nonEmptyURI' to a(n) 'type definition' component.
line 389 of cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd

jvnet maven-jaxb2-插件

        <plugin>
<!-- http://jaxb.java.net/ -->
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<catalog>${catalog}</catalog>
<schemaDirectory>${xsd.path}</schemaDirectory>
<generatePackage>${package}</generatePackage>
<strict>false</strict>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
<arg>-XtoString</arg>
</args>
</configuration>
</plugin>

错误是一样的,只是更详细一点

[INFO] Parsing input schema(s)...
[ERROR] Error while parsing schema(s).Location [ cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd{389,74}].
org.xml.sax.SAXParseException: undefined simple type 'xl:nonEmptyURI'
at com.sun.xml.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:180)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:175)
at com.sun.xml.xsom.impl.parser.DelayedRef.resolve(DelayedRef.java:110)
[...]
[ERROR] Error while parsing schema(s).Location [ cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd{412,77}].
org.xml.sax.SAXParseException: undefined simple type 'xl:nonEmptyURI'
at com.sun.xml.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:180)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:175)
at com.sun.xml.xsom.impl.parser.DelayedRef.resolve(DelayedRef.java:110)
[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.2:generate (generate) on project solvency2: Unable to parse input schema(s). Error messages should have been provided. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.2:generate (generate) on project solvency2: Unable to parse input schema(s). Error messages should have been provided.

Mojo jaxb2-maven-插件

         <plugin>
<!--http://mojo.codehaus.org/ -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xjc</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${xsd.path}</schemaDirectory>
<packageName>${package}</packageName>
<catalog>${catalog}</catalog>
</configuration>
</plugin>

同样的错误,Xerces 的说法不同

[ERROR] file:[...]cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd[472,74]
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xl:nonEmptyURI' to a(n) 'simpleType definition' component.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)

最佳答案

您肯定需要下载所有模式并将其添加到您的案例中的目录中。我在生成 Java 类时遇到了类似的问题,但我根本没有使用任何目录,只是将 XBRL 使用的所有模式放入同一个文件夹中。它们在 XBRL 网站上的组织方式相同:

src\main\resources\xbrl\
xbrl-instance-2003-12-31.xsd
xbrl-linkbase-2003-12-31.xsd
xl-2003-12-31.xsd
xlink-2003-12-31.xsd
xbrl_bindings.xjb

此外,我还添加了一个 JAXB 绑定(bind)(如您所见),以解决源生成期间引发的冲突并将其放入同一文件夹中。

xbrl_bindings.xjb:

<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.1">
<bindings schemaLocation="xl-2003-12-31.xsd" version="1.0">
<bindings node="//xs:schema//xs:element[@name='title']">
<property name="xlTitle"/>
</bindings>
</bindings>

Maven插件配置:

         <plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<xsdOptions>
<xsdOption>
<bindingFile>${path.to.xsd}/xbrl_bindings.xjb</bindingFile>
<xsd>${path.to.xsd}/xbrl-instance-2003-12-31.xsd</xsd>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>

享受 XBRL :)

关于JAXB 无法生成 XBRL 的 Java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12913445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com