【问题标题】:JAXB XJC code generation - "schemaLocation" missing in xml generated by MarshallerJAXB XJC 代码生成 - Marshaller 生成的 xml 中缺少“schemaLocation”
【发布时间】:2011-01-10 19:21:33
【问题描述】:

我使用 XJC 工具为我的 XSD 模式生成 Java 类。当我使用 JAXB Marshaller 将类编组为 XML 有效负载时,我在输出 XML 中缺少“schemaLocation”参数,但我在 xsd 文件中声明了此参数。如何在输出 XML 中强制执行“schemaLocation”参数?

下面是我用于代码生成的 xsd 架构文件的开头:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="xsdns" xmlns:messages="http://www.exampleURI.com/Schema1" xmlns:datatypes="http://www.exampleURI.com/Schema1" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://www.exampleURI.com/Schema1 ./messages.xsd" targetNamespace="http://www.exampleURI.com/Schema1" elementFormDefault="unqualified" version="true">
<xs:include schemaLocation="datatypes.xsd"/>
<xs:complexType name="execute-system-command-struct">
    <xs:annotation>
        <xs:documentation>The request for system command execution.</xs:documentation>
    </xs:annotation>
    <xs:sequence/>
    <xs:attribute name="action" type="datatypes:system-action-kind-enum" use="required">
        <xs:annotation>
            <xs:documentation>The action that the Voice System has to proceed.</xs:documentation>
        </xs:annotation>
    </xs:attribute>

问候

【问题讨论】:

  • 您能否举一个由 JAXB 生成的 XML 的示例,以及它与您想要生成它有何不同?
  • 已经被 xcut answer 解决了。谢谢

标签: java xml xsd jaxb xjc


【解决方案1】:

试试这个:

marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://my.namespace my.schema.xsd");

【讨论】:

    猜你喜欢
    • 2010-11-28
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多