2012-05-21 70 views
1

我已生成的Java類後失蹤,我想從JAXB類編組的前綴命名空間JAXB命名空間從XSD編組

這裏是我有

<?xml version="1.0" encoding="UTF-8"?> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.example.org/event" 
     xmlns:tns="http://www.example.org/event" 
     elementFormDefault="qualified"> 
<element name="Events" type="tns:EventsType"></element> 
<complexType name="EventsType"> 
<sequence> 
<element name="Event" type="tns:inputFlowEventType" maxOccurs="unbounded" minOccurs="1"></element> 
</sequence></complexType> 
<complexType name="inputFlowEventType"> 
<sequence> 
<element name="DISTRIBUTOR_ID" minOccurs="1" maxOccurs="1"> 
<simpleType><restriction base="string"><maxLength value="17"></maxLength></restriction></simpleType> 
</element> 
</sequence> 
</complexType> 
</schema> 

和我有這個

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Events xmlns="http://www.example.org/event"><Event><DISTRIBUTOR_ID>6</DISTRIBUTOR_ID></Event></Events> 

,而不是這個

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <tns:Events xmlns="http://www.example.org/event"> <tns:Event><tns:DISTRIBUTOR_ID>6</tns:DISTRIBUTOR_ID></tns:Event></tns:Events> 

有人知道什麼是錯的嗎?

謝謝

+0

首先,你必須在最後一節,你應該期待,而一個錯字(注意的xmlns:TNS = '''部分): <?xml version =「1.0」encoding =「UTF-8」standalone =「yes」?> 6

回答

0

這兩個文件在名稱空間限定方面是等價的。第一個指定一個默認名稱空間,第二個用前綴聲明一個名稱。如果您想控制所使用的前綴,則答案將取決於您使用的JAXB實現。 MOXy將使用在@XmlSchema註釋中聲明的前綴。該JAXB RI有NamespacePrefixMapper擴展(也由莫西支持):