Why is JAXB namespace of my xml set to default ns1?

萝らか妹 提交于 2019-12-21 16:02:31

问题


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


回答1:


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. The foo element is in the FOO namespace, and the bar element is in the BAR 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.

  • http://blog.bdoughan.com/2011/11/jaxb-and-namespace-prefixes.html


来源:https://stackoverflow.com/questions/14579115/why-is-jaxb-namespace-of-my-xml-set-to-default-ns1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!