XMLWriter使用zdef扩展属性名称? [英] XMLWriter extends attribute name with zdef?

查看:305
本文介绍了XMLWriter使用zdef扩展属性名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用XMLMapper将一些配置类序列化为xml配置文件。
但我在属性生成方面遇到了一些麻烦。实际上生成的XML是完美的,但XMLMapper有时会为我的属性名称添加前缀。

I try to serialize some config classes to xml config files using the XMLMapper. but I have some trouble with the attribute generation. Actually the generated XML is perfect, but XMLMapper adds sometimes a prefix to my attribute names.

例如

<Config zdef-2031720317:value="0">

而不是

<Config value="0">

这真的很糟糕,因为我不能再用XOM处理xml结构了:(

This is really bad because i can't process the xml Structure afterwards with XOM anymore :(

这个效果来自哪里?
我发现xml生成器似乎自动修复命名空间以使属性唯一。为什么这是必要的我怎么能避免它呢?

Where is this effect coming from? I found already the fact that the xml generator seems to auto fix the namespace to make the attributes unique. Why is this necessary and how can i avoid it?

推荐答案

有一件事经常导致 XmlMapper 是基础XML Stax库 - JDK中包含的一个库有时会添加不必要的名称空间前缀。
解决方案是使用 Woodstox Stax实现,因为它已知在一般情况下工作得更好,并且在这种特定情况下也是如此。

One thing that has often caused problems with XmlMapper is underlying XML Stax library -- one included in JDK sometimes adds unnecessary namespace prefixes. The solution is to use Woodstox Stax implementation instead, as it is known to work better in general, and also in this specific case.

如果您使用Maven,您只需添加这在你的 pom.xml 中:

If you use Maven, you can just add this in your pom.xml:

<dependency>
  <groupId>org.codehaus.woodstox</groupId>
  <artifactId>woodstox-core-asl</artifactId>
  <version>4.1.4</version>
</dependency>

您的问题可能会得到解决。作为额外的好处,这也是更快的XML解析器。

and your problem may be solved. As an added bonus, this is faster XML parser as well.

这篇关于XMLWriter使用zdef扩展属性名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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