如何告诉我的 JAXB 输出包含对创建它的 XSD 的引用?
这是我的pages.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mac="http://www.tvworks.com/tva/xml/ns/max/data-types"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://www.tvworks.com/tva/xml/ns/max/data-types"
schemaLocation="http://developer.tva.tvworks.com/xml/ns/max/data-types-3.2.xsd"/>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="scenes" type="scenesType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="scenesType">
<xs:sequence>
<xs:element name="row" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="page" type="mac:page-ref"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
这是我的pages.xjb
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="pages.xsd" version="1.0"">
<schemaBindings>
<package name="com.mycompany.pages"/>
</schemaBindings>
</bindings>
</bindings>
这是我想要的输出,请注意xsi:noNamespaceSchemaLocation="pages.xsd"
。
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="pages.xsd">
<scenes>
<row>
<page>page1</page>
</row>
<row>
<page>page2</page>
</row>
<row>
<page>page3</page>
</row>
<row>
<page>page4</page>
</row>
</scenes>
</data>
如何将该属性自动添加到 JAXB 输出的 data
元素上?
Here is my pages.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mac="http://www.tvworks.com/tva/xml/ns/max/data-types"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://www.tvworks.com/tva/xml/ns/max/data-types"
schemaLocation="http://developer.tva.tvworks.com/xml/ns/max/data-types-3.2.xsd"/>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="scenes" type="scenesType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="scenesType">
<xs:sequence>
<xs:element name="row" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="page" type="mac:page-ref"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Here is my pages.xjb
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="pages.xsd" version="1.0"">
<schemaBindings>
<package name="com.mycompany.pages"/>
</schemaBindings>
</bindings>
</bindings>
Here is what I want the output to look like, notice the xsi:noNamespaceSchemaLocation="pages.xsd"
.
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="pages.xsd">
<scenes>
<row>
<page>page1</page>
</row>
<row>
<page>page2</page>
</row>
<row>
<page>page3</page>
</row>
<row>
<page>page4</page>
</row>
</scenes>
</data>
How do I get that attribute onto the data
element the JAXB output automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
Marshaller
上将属性jaxb.noNamespaceSchemaLocation
设置为所需的值。编辑:检查 Marshaller 中有关受支持属性的部分文档以及方法 setProperty 了解更多信息。
Set property
jaxb.noNamespaceSchemaLocation
with the desired value on yourMarshaller
.EDIT: check the section on supported properties in the Marshaller documentation as well as method setProperty for additional info.