本文介紹了JAXB XJC 代碼生成 - “schemaLocation"Marshaller 生成的 xml 中缺少的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我使用 XJC 工具為我的 XSD 模式生成 Java 類.當我使用 JAXB Marshaller 將類編組為 XML 有效負載時,我在輸出 XML 中缺少schemaLocation"參數,但我在 xsd 文件中聲明了此參數.如何在輸出 XML 中強制執行schemaLocation"參數?
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?
下面是我用于代碼生成的 xsd 架構文件的開頭:
Below is the begining 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>
問候
推薦答案
試試這個:
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://my.namespace my.schema.xsd");
這篇關于JAXB XJC 代碼生成 - “schemaLocation"Marshaller 生成的 xml 中缺少的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!