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

时间:2010-01-29 10:47:55

标签: java xml xsd jaxb xjc

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

此致

1 个答案:

答案 0 :(得分:31)

试试这个:

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