XML 命名空间有什么用? [英] What are XML namespaces for?

查看:24
本文介绍了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 代码的任何部分,然后想想如果您不使用名称空间并尝试编写输出必须包含模板"、for-each"的 XSLT,会发生什么情况,等元素.语法错误,是什么.

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天全站免登陆