为什么我的xml的JAXB名称空间设置为默认ns1? [英] Why is JAXB namespace of my xml set to default ns1?
问题描述
我使用NetBeans 7.2(在Windows 7环境下)从Web应用程序构建了一个war文件,该文件在测试阶段使用NetBeans上下文中的GlassFish 3.1.2服务器正确运行。
package-info.java
文件中定义的命名空间已正确添加到我的xml文件中。
然而,当我将war文件部署到Linux机器上独立运行的GlassFish服务器时,命名空间被设置为默认的ns1,而不是由package-info.java文件定义的那个?
我做错了什么?
问候,
Gerard
ns1
不是名称空间,而是前缀。前缀不重要。例如,以下文件均等同。 foo
元素位于 FOO
命名空间中,并且栏
元素位于 BAR
命名空间中。
< a:foo xmlns:a =FOOxmlns:b =BAR>
< b:bar> Hello World< / b:bar>
< / a:foo>
< ns1:foo xmlns:ns1 =FOOxmlns:ns2 =BAR>
< ns2:bar> Hello World< / ns2:bar>
< / ns1:foo>
< foo xmlns = FOOxmlns:b =BAR>
< b:bar> Hello World< / b:bar>
< / foo>
pre>
我做错了什么?
blockquote>
无。 JAXB( JSR-222) 实现不需要使用在
下面是我写的一篇文章的链接更详细一点,并涵盖可能的@XmlSchema
注释中指定的前缀。 EclipseLink JAXB(MOXy) 显示JAXB RI的最新版本.JAXB的版本/实现在NetBeans 7.2中似乎是这样,而GlassFish 3.1.2使用的JAXB的版本/实现则不然。NamespacePrefixMapper
扩展名在这里很有用。
I've build a war file from my web application using NetBeans 7.2 (in Windows 7 environment!), which runs correctly during test phase with GlassFish 3.1.2 server within NetBeans context.
The defined namespace within the
package-info.java
file is correctly added to my xml file.However when I deploy the war file in a seperatetely running GlassFish server on a Linux machine the namespace is set to the default ns1 and NOT to the one defined by the package-info.java file?
What am I doing wrong?
Regards, Gerard
解决方案Why is JAXB namespace of my xml set to default ns1?
ns1
is not the namespace but the prefix. The prefix is not significant. For example the following documents are all equivalent. Thefoo
element is in theFOO
namespace, and thebar
element is in theBAR
namespace.<a:foo xmlns:a="FOO" xmlns:b="BAR> <b:bar>Hello World</b:bar> </a:foo>
<ns1:foo xmlns:ns1="FOO" xmlns:ns2="BAR> <ns2:bar>Hello World</ns2:bar> </ns1:foo>
<foo xmlns="FOO" xmlns:b="BAR> <b:bar>Hello World</b:bar> </foo>
What am I doing wrong?
Nothing. A JAXB (JSR-222) implementation is not required to use the prefix specified in the
@XmlSchema
annotation. EclipseLink JAXB (MOXy) does and recent versions of the JAXB RI appear to. The version/implementation of JAXB in NetBeans 7.2 appears to, while the version/implementation of JAXB that GlassFish 3.1.2 uses does not.Below is a link to an article that I wrote that goes into a little more detail and covers the
NamespacePrefixMapper
extension that may be useful here.这篇关于为什么我的xml的JAXB名称空间设置为默认ns1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!