In other words, the String "http://www.myNameSpace.com" as in:<rootElement xmlns:myNameSpace="http://www.myNameSpace.com">完全是任意的.它不必指向任何地方.另外,所谓的前缀(在本例中为myNameSpace,紧接在"xmlns:"之后的部分)是任意的,只是表示" http://www.myNameSpace.com ".is purely arbitrary. It does not have to point anywhere. Also, the so-called prefix (in this case myNameSpace, the part right after "xmlns:") is arbitrary and just a shorthand way of saying "http://www.myNameSpace.com".话虽如此,但有一些保留意见:Having said that, a few reservations: 1)命名空间可以帮助您将XML数据构造为大文件,例如OpenXML格式的Microsoft Word文档:1) Namespaces can help structure your XML data in large files, for example a Microsoft Word document in OpenXML format:这是典型的OOXML中存在的命名空间的摘录:This is an excerpt of the namespaces present in typical OOXML:xmlns:aml="http://schemas.microsoft.com/aml/2001/core"xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"因此,尽管没有固有的理由要使用单独的名称空间,但它有助于将XML词汇表划分为有意义的类别.So, although there is no inherent reason to have separate namespaces, it helps dividing your XML vocabulary into meaningful categories. 2),您注意到,对任意定义名称空间有一些限制:2) There are a few constraints on arbitrarily defining namespaces, as you noticed:xmlns:xsl="http://www.w3.org/1999/XSL/Transform"这将元素标识为属于XSLT命名空间.但是,除此之外,这还意味着XSLT处理器将这样标记的元素不仅标识为XML代码,而且还标识要执行的XSLT指令.This identifies elements as belonging to the XSLT namespace. But also, beyond that, it means that elements thus marked are identified by an XSLT processor as not merely being XML code, but an XSLT instruction to be carried out.链接" http://www.w3.org/1999/XSL/Transform"指向XSLT规范,其中规定了转换XML文档的规则.现在,回答您的问题:声明名称空间对转换没有帮助.相反,如果省略XSLT处理器,则无法识别XSLT代码.The link "http://www.w3.org/1999/XSL/Transform" points to the XSLT specification, where the rules for transforming XML documents are laid down. Now, to answer your question: Declaring the namespace does not help the transformation. Rather, an XSLT processor does not recognize XSLT code if you omit it.您可以定义名称空间"namespaceA"和"namespaceB":You can define the namespaces "namespaceA" and "namespaceB":xmlns:nsA="namespaceA"xmlns:nsB="namespaceB"但是您不能使用它们来转换XML,除非您只是想更改前缀:but you cannot use them to transform XML, unless you meant to just change the prefix:xmlns:nsA="http://www.w3.org/1999/XSL/Transform"这被认为是不好的做法.which is considered bad practice. 这篇关于XML中的名称空间需求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 05:45