[英]How to specify an attribute namespace in XSD so that JAXB interprets it correctly?
I have a small problem with attribute namespaces within an existing XSD. 我在现有XSD中的属性命名空间有一个小问题。 I have to modify this XSD in order to use all functionality of a third-party software. 我必须修改此XSD才能使用第三方软件的所有功能。
My goal is to mix an element with a namespaced attribute, like this: 我的目标是将元素与命名空间属性混合,如下所示:
<graphics type="RECTANGLE" cy:nodeLabel="Label 1" />
The <graphics>
element is defined in the default namespace, the attribute cy:nodeLabel
in a specific namespace. <graphics>
元素在默认命名空间中定义,特定命名空间中的属性cy:nodeLabel
。
Currently, my attribute definition in the XSD looks like this: 目前,我在XSD中的属性定义如下所示:
<xsd:attribute name="nodeLabel" type="xsd:string" form="qualified" xmlns="http://www.cytoscape.org"/>
The option form="qualified"
forces JAXB to annotate the @XmlAttribute
with namespace="...."
, but it takes the default namespace, instead of http://www.cytoscape.org . 选项form="qualified"
强制JAXB使用namespace="...."
注释@XmlAttribute
,但它采用默认命名空间,而不是http://www.cytoscape.org 。 If I change this manually in the generated Java classes, the XML output is as desired. 如果我在生成的Java类中手动更改它,则XML输出是所需的。
I would like to define the attribute namespace within the XSD, so that I can rely on JAXB (resp. xjc) to generate the correct Java classes. 我想在XSD中定义属性名称空间,这样我就可以依赖JAXB(相应的xjc)来生成正确的Java类。
How can I specify an attribute namespace for one attribute in the XSD? 如何为XSD中的一个属性指定属性命名空间?
A single xsd file can only define a single namespace. 单个XSD文件只能定义一个命名空间。 you need a separate xsd which defines the second namespace, which you would then import into the original xsd (and reference the attribute accordingly). 你需要一个单独的 xsd来定义第二个命名空间,然后将其导入原始的xsd(并相应地引用该属性)。
Thanks to jtahlborn's answer , I found the appropriate solution: 感谢jtahlborn的回答 ,我找到了合适的解决方案:
Import separate XSD: 导入单独的XSD:
New file cytoscape-additions.xsd
新文件cytoscape-additions.xsd
<?xml version='1.0' encoding='UTF-8'?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.cytoscape.org" elementFormDefault="unqualified"
attributeFormDefault="qualified">
<!-- Cytoscape additions Graphics -->
<xsd:attributeGroup name="cytoscape-addition-graphics">
<xsd:attribute name="nodeLabel" type="xsd:string" form="qualified"
xmlns="http://www.cytoscape.org" />
</xsd:attributeGroup>
</xsd:schema>
Source: https://stackoverflow.com/a/12111103/32043 资料来源: https : //stackoverflow.com/a/12111103/32043
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.