java JAXB XJC 代码生成 - Marshaller 生成的 xml 中缺少“schemaLocation”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2161350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAXB XJC code generation - "schemaLocation" missing in xml generated by Marshaller
提问by cubesoft
I Use XJC tool to generate Java classes for my XSD schema. When I use JAXB Marshaller to marshall classes into XML payloads, I'm missing "schemaLocation" parameter in the output XML, but I declare this parameter in xsd file. How to enforce "schemaLocation" parameter in the output XML?
我使用 XJC 工具为我的 XSD 模式生成 Java 类。当我使用 JAXB Marshaller 将类编组到 XML 有效负载中时,我在输出 XML 中缺少“schemaLocation”参数,但我在 xsd 文件中声明了这个参数。如何在输出 XML 中强制执行“schemaLocation”参数?
Below is the begining of my xsd schema file used for code generation:
下面是用于代码生成的 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>
Regards
问候
回答by xcut
Try this:
试试这个:
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://my.namespace my.schema.xsd");

