2010-01-29 84 views
18

I使用XJC工具爲我的XSD模式生成Java類。當我使用JAXB Marshaller將類組裝到XML有效負載中時,我在輸出XML中缺少「schemaLocation」參數,但我在xsd文件中聲明瞭此參數。如何在輸出XML中實施「schemaLocation」參數?JAXB XJC代碼生成 - 由Marshaller生成的xml中缺少「schemaLocation」

下面是我的XSD架構文件用於代碼生成的beggining:

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

問候

+0

你能不能給由正在生成的XML的例子JAXB,以及與你有什麼不同*想要它產生? – skaffman 2010-01-29 10:49:44

+0

已經通過xcut回答。謝謝 – cubesoft 2010-02-01 12:42:45

回答

27

試試這個:

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