2014-02-07 52 views
1

当我从我的JAXB生成的XSD/Schema类中编组XML时,根节点缺少xmlns:xsi信息,请参见下文。关于如何在我编组的XML中获取名称空间信息的任何想法?未出现在JAXB中的XSD名称空间Marshalled XML

当前马歇尔结果:

<exampleType> 

期望马歇尔结果:

<exampleType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../schemas/example.xsd"> 

我的架构(它的样本部分):

<?xml version="1.0" encoding="UTF-8"?> 
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0.1"> 
     <xs:element name="project" type="exampleType"> 
      <xs:annotation> 
       <xs:documentation>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="../schemas/example.xsd" 
       </xs:documentation> 
      </xs:annotation> 

....

回答

1

要让xsi:noNamespaceSchemaLocation架构位置属性出现在你需要使用JAXB_NO_NAMESPACE_SCHEMA_LOCATION属性来设置它的Marshaller编组XML。

marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "../schemas/example.xsd"); 
相关问题