在编组期间,每个元素中的jaxb名称空间而不是根元素 [英] jaxb namespaces in each element instead of root element during marshalling

查看:112
本文介绍了在编组期间,每个元素中的jaxb名称空间而不是根元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,jaxb 2在编组期间列出根元素中的所有(所有可能需要的)名称空间:

By default, jaxb 2 lists all (all possible required) namespaces in root element during marshalling:


< rootElement xmlns =default_nsxmlns:ns1 =ns1xmlns:ns2 =ns2>
< ns1:element />
< / rootElement>

有没有办法在每个元素中描述命名空间根元素?:

Is there a way to describe namespace in each element instead of root element ?:


< rootElement xmlns =default_ns>
< element xmlns =ns1/>
< / rootElement>

它还解决了不必要的命名空间问题,这对我来说也很重要。
任何建议表示赞赏。

It also solves the problem of "unnecessary namespaces", which is also important in my case. Any suggestions appreciated.

推荐答案

此外,我倾向于同意@Anton在其他人提供的回复中线。
我真的不应该重要。如果你必须强迫某种方式,你应该总是更喜欢顶级上下文,特别是如果你有可能重复的元素。在兄弟元素中重复名称空间声明是浪费空间,也是接收端解析器的次优。

Also, I tend to agree wtih @Anton in the response he offered in the other thread. I really shouldn't matter. And if you must force one way or the other, you should always prefer the top-level context, especially if you have potentially repeated elements. Repeating the namespace declaration in sibling elements is a waste of space as well as sub-optimal for the parser at the receiving end.

这篇关于在编组期间,每个元素中的jaxb名称空间而不是根元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆