JAXB XJC代码生成-Marshaller生成的xml中缺少“ schemaLocation”

问题描述

试试这个:

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

解决方法

我使用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>

问候