gpt4 book ai didi

java - JAXB XJC 代码生成 - Marshaller 生成的 xml 中缺少 "schemaLocation"

转载 作者:太空狗 更新时间:2023-10-29 22:32:54 25 4
gpt4 key购买 nike

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

问候

最佳答案

试试这个:

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

关于java - JAXB XJC 代码生成 - Marshaller 生成的 xml 中缺少 "schemaLocation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2161350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com