JiBX:如何在导入无命名空间架构的架构上运行 codegen

发布于 2024-09-15 15:26:54 字数 1919 浏览 3 评论 0原文

我这里有一个模式,我试图在其中包含/导入另一个没有命名空间的模式(并且不能更改它,因为它来自另一个供应商,并且它将不再验证其 XML)。这是第一个架构:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:samp="http://sample/namespace" 
targetNamespace="http://sample/namespace" 
elementFormDefault="unqualified" attributeFormDefault="unqualified"
xmlns:otr1="http://sample/import/namespace1" 
xmlns:otr2="http://sample/import/namespace2">

<xs:import namespace="http://sample/import/namespace1" schemaLocation="other1.xsd" />
<xs:import namespace="http://sample/import/namespace2" schemaLocation="other2.xsd"  />
<!-- This one below is having problems, it is valid XML, and I am able to use it
but I am not meeting the actual requirments I have (explained later) -->
<xs:import schemaLocation=="NO_NAME_SPACE_PROBLEM.xsd"/>

...
<xs:element ref="some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA"/>
...


</xs:schema>

“NO_NAME_SPACE_SHEMA_PROBLEM.xsd”可以在一定程度上进行更改,但不能有命名空间。

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     elementFormDefault="unqualified" attributeFormDefault="unqualified">

 <xsd:element name="some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA" 
    type="xsd:string" nillable="true"/>

</xs:schema>

运行 JiBX codegen 时遇到的问题:

 [echo] Running code generation
 [java] Output to directory C:\DOCUME~1\user1\LOCALS~1\Temp\nguser\Temp-Src
 [java] ERROR validation.ValidationContext - Error: Referenced element '{http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA` is not defined for element at (line 69, col 32, in parent.xsd)
 [java] Terminating due to errors in input schemas
 [java] Error: Referenced element '{http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA' is not defined for element at (line 69, col 32, in parent.xsd)

I have a schema here where I am trying to include/import another schema that has no namespace (and this cannot be changed because it comes from another vendor and it would no longer validate their XML). Here is the first Schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:samp="http://sample/namespace" 
targetNamespace="http://sample/namespace" 
elementFormDefault="unqualified" attributeFormDefault="unqualified"
xmlns:otr1="http://sample/import/namespace1" 
xmlns:otr2="http://sample/import/namespace2">

<xs:import namespace="http://sample/import/namespace1" schemaLocation="other1.xsd" />
<xs:import namespace="http://sample/import/namespace2" schemaLocation="other2.xsd"  />
<!-- This one below is having problems, it is valid XML, and I am able to use it
but I am not meeting the actual requirments I have (explained later) -->
<xs:import schemaLocation=="NO_NAME_SPACE_PROBLEM.xsd"/>

...
<xs:element ref="some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA"/>
...


</xs:schema>

And the "NO_NAME_SPACE_SHEMA_PROBLEM.xsd" which can be changed to some extent, but it cannot have namespace.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     elementFormDefault="unqualified" attributeFormDefault="unqualified">

 <xsd:element name="some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA" 
    type="xsd:string" nillable="true"/>

</xs:schema>

The problem I get when running JiBX codegen:

 [echo] Running code generation
 [java] Output to directory C:\DOCUME~1\user1\LOCALS~1\Temp\nguser\Temp-Src
 [java] ERROR validation.ValidationContext - Error: Referenced element '{http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA` is not defined for element at (line 69, col 32, in parent.xsd)
 [java] Terminating due to errors in input schemas
 [java] Error: Referenced element '{http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA' is not defined for element at (line 69, col 32, in parent.xsd)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天暗了我发光 2024-09-22 15:26:54

引用 {http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA 的错误消息似乎很奇怪,因为您没有引用 {http://sample/namespace }:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMAsome-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA

我只能看到两个选项:

  • 您没有粘贴完整的父架构示例;在您的实际模式中,您将 xmlns (即没有前缀)绑定到示例名称空间。这可以解释错误消息,并且您可以通过不绑定 xmlns 来修复它。
  • 导入没有目标命名空间的模式时,JiBX 中存在错误。

The error message for the reference to {http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA seems strange, as you are not referencing {http://sample/namespace}:some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA but some-elem-from-NO_NAME_SPACE_PROBLEM_SCHEMA.

I can see only two options:

  • You did not paste the full parent schema sample; in your actual schema you bound xmlns (i.e. without a prefix) to the sample namespace. This would explain the error message, and you could fix it by not binding xmlns.
  • There is a bug in JiBX when importing schemas without a target namespace.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文