如何使用java dom从xml中删除名称空间? [英] How do I remove namespaces from xml, using java dom?
本文介绍了如何使用java dom从xml中删除名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
DocumentBuilderFactory dbFactory_ = DocumentBuilderFactory.newInstance();
Document doc_;
DocumentBuilder dBuilder = dbFactory_.newDocumentBuilder();
StringReader reader = new StringReader(s);
InputSource inputSource = new InputSource(reader);
doc_ = dBuilder.parse(inputSource);
doc_.getDocumentElement().normalize();
然后我可以做
doc_.getDocumentElement();
并获得我的第一个元素,但问题不是 code>元素是
tns:job
。
and get my first element but the problem is instead of being job
the element is tns:job
.
我知道并尝试使用: / p>
I know about and have tried to use:
dbFactory_.setNamespaceAware(true);
但这不是我正在寻找的,我需要一些东西来完全摆脱命名空间
but that is just not what I'm looking for, I need something to completely get rid of namespaces.
任何帮助将不胜感激,
感谢,
Any help would be appreciated, Thanks,
Josh
推荐答案
对于元素和属性节点:
Node node = ...;
String name = node.getLocalName();
将给您节点名称的本地部分。
will give you the local part of the node's name.
这篇关于如何使用java dom从xml中删除名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文