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

问题描述 投票:20回答:1

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

问候

java xml xsd jaxb xjc
1个回答
35
投票

尝试一下:

marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://my.namespace my.schema.xsd");
© www.soinside.com 2019 - 2024. All rights reserved.