什么是XML名称空间? [英] What are XML namespaces for?

查看:62
本文介绍了什么是XML名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我总是很难解释给别人的东西: 为什么存在XML名称空间? 我们什么时候应该使用它们,什么时候不应该使用? 在XML中使用命名空间时,常见的陷阱有哪些?

This is something that I always find a bit hard to explain to others: Why do XML namespaces exist? When should we use them and when should we not? What are the common pitfalls when working with namespaces in XML?

此外,它们与XML模式有何关系? XSD模式应该始终与命名空间关联吗?

Also, how do they relate to XML schemas? Should XSD schemas always be associated with a namespace?

推荐答案

它们用于允许多种标记语言进行组合,而不必担心元素和属性名称的冲突.

They're for allowing multiple markup languages to be combined, without having to worry about conflicts of element and attribute names.

例如,查看XSLT代码的任何部分,然后思考如果您不使用名称空间而试图编写XSLT,其中输出必须包含模板","for-each",等元素.语法错误,是什么.

For example, look at any bit of XSLT code, and then think what would happen if you didn't use namespaces and were trying to write an XSLT where the output has to contain "template", "for-each", etc, elements. Syntax errors, is what.

我会把建议和陷阱留给比我经验更多的人.

I'll leave the advice and pitfalls to others with more experience than I.

这篇关于什么是XML名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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