JAXB XJC代码生成 - “schemaLocation” Marshaller生成的xml中缺少 [英] JAXB XJC code generation - "schemaLocation" missing in xml generated by Marshaller

查看:188
本文介绍了JAXB XJC代码生成 - “schemaLocation” Marshaller生成的xml中缺少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



以下是用于代码生成的xsd模式文件的开始:



'pre> < XML版本= 1.0 编码= UTF-8 >< XS:?架构的xmlns:XS =HTTP:// WWW。 w3.org/2001/XMLSchema的xmlns = xsdns 的xmlns:消息= http://www.exampleURI.com/Schema1 的xmlns:数据类型= 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 / Schema1elementFormDefault =unqualifiedversion =true>
< xs:include schemaLocation =datatypes.xsd/>
< xs:complexType name =execute-system-command-struct>
< xs:annotation>
< xs:documentation>系统命令执行请求。< / xs:documentation>
< / xs:annotation>
< xs:sequence />
< xs:attribute name =actiontype =datatypes:system-action-kind-enumuse =required>
< xs:annotation>
< xs:documentation>语音系统必须执行的操作。< / xs:documentation>
< / xs:annotation>
< / xs:attribute>

问候

解决方案

试试这个:

  marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,HTTP://my.namespace我。 schema.xsd); 


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?

Below is the beggining of my xsd schema file used for code generation:

<?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

解决方案

Try this:

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

这篇关于JAXB XJC代码生成 - “schemaLocation” Marshaller生成的xml中缺少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆