Java Transformer 如何忽略命名空间 [英] Java Transformer how to ignore namespaces

查看:35
本文介绍了Java Transformer 如何忽略命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将 XML 转换为 XHTML,但 XML 定义了一个命名空间 xmlns='http://www.lotus.com/dxl',它从未在整个 XML 中使用过,因此解析器获胜不解析任何东西...

I have to transform XML to XHTML but the XML defines a namespace xmlns='http://www.lotus.com/dxl' which is never used in the whole XML therefore the parser won't parse anything ...

有没有办法忽略命名空间?我正在使用 Oracle java 转换器 import javax.xml.transform.Transformer;导入 javax.xml.transform.TransformerFactory

Is there a way I ignore namepsaces? I am using the Oracle java transformer import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory

或者有没有更好的库?

推荐答案

不,你不能忽略命名空间.

No, you can't ignore namespaces.

如果命名空间声明 xmlns='http://www.lotus.com/dxl' 出现在最外面的元素中,那么你不能说它没有在任何地方使用"——相反,它无处不在!它有效地将文档中的每个元素名称更改为不同的名称.你绝对不能忽视这一点.

If the namespace declaration xmlns='http://www.lotus.com/dxl' appears in the outermost element, then you can't say it "isn't used anywhere" - on the contrary, it is used everywhere! It effectively changes every element name in the document to a different name. There's no way you can ignore that.

如果您使用的是 XSLT 2.0,那么您可以在样式表中声明 xpath-default-namespace="http://www.lotus.com/dxl"做你想做的事:它说匹配模式或 XPath 表达式中的任何无前缀名称都应该被解释为引用命名空间 http://www.lotus.com/dxl.遗憾的是,您选择了一个没有实现 XSLT 2.0 的 XSLT 处理器.因此,您必须以艰难的方式来完成它(这在大约 10,000 篇文章中进行了描述,您可以通过搜索XSLT 默认名称空间"找到这些帖子).

If you were using XSLT 2.0, then you would be able to say in your stylesheet xpath-default-namespace="http://www.lotus.com/dxl" which would pretty much do what you want: it says that any unprefixed name in a match pattern or XPath expression should be interpreted as referring to a name in namespace http://www.lotus.com/dxl. Sadly, you've chosen an XSLT processor that doesn't implement XSLT 2.0. So you'll have to do it the hard way (which is described in about 10,000 posts that you will find by searching for "XSLT default namespace").

这篇关于Java Transformer 如何忽略命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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