如何在DOM中的每个节点上更改命名空间? [英] How can I change the namespace on every node in a DOM?

查看:108
本文介绍了如何在DOM中的每个节点上更改命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给我一个w3c DOM(Java的默认实现,具体来说)如何改变这个DOM中每一个元素/属性/节点的命名空间?有效地,优选地。 DOM似乎没有一个setNamespaceURI方法,这是不方便的。



我尝试过XSL方法,但是在JAXP中无法工作变压器(虽然它们在Saxon9B中正常工作,我不能用于各种其他原因)。



基本上,我需要一个纯核心的java解决方案,让我获取一个文档并更改其命名空间。

解决方案

根据我非常有偏见的意见,您想要的将是一个巨大的痛苦屁股。我可以看到类似的地狱和许多循环的循环需要可靠地做到这一点!啊,Java的默认实现,我如何讨厌你的NPE:在内部,反转的逻辑,简单的操作所需的额外的步骤!



所以是的,我的建议是基于我个人经验,Java的默认实现非常糟糕,递归针对每一个可能的节点类型的循环。


How can I, given a w3c DOM (Java's default implementation, specifically) change the namespace of every element/attribute/node in that DOM? Efficiently, preferably. The DOM doesn't seem to have a setNamespaceURI method on it, which is inconvenient.

I've tried XSL approaches, but they've failed to work in the JAXP transformers (although they work all right in Saxon9B, which I can't use for various other reasons).

Basically, I need a pure core java solution that will allow me to take one document and change its namespace.

解决方案

Based on my hugely biased opinion what you want will be a huge pain in the ass. I can see the typecasting hell and numerous recursive for loops needed to do this reliably already! Ahh, Java's default implementation, how I hate your NPE:s at internals, the reversed logic, the extra steps needed for simple operations!

So yes, my suggestion would be recursive for loops with typecasting for every single possible node type, based on my very personal experience the Java's default implementation sucks that badly.

这篇关于如何在DOM中的每个节点上更改命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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