What is QNAME?

Source: Internet
Author: User
Tags xsl xslt

Author: fbysss
Blog: blog.csdn.net/fbysss
MSN: jameslastchina@hotmail.com
Disclaimer: This article is compiled by fbysss. Please specify the reference address for reprinting or referencing.
Keyword: QNAME
QNAME is often seen when using dom4j. It may be that the XML parsed by myself is too simple, so I haven't studied it carefully, but I think the name is weird, in Google Baidu's search for "What Is QNAME", there are only a few records with no decent answers. Fortunately, I have found some explanations on foreign websites, and I understand it.
1. Origin: QNAME isQualified nameShort
2. Structure: it consists of a namespace prefix, a colon (:), and an element name.
3. Example:
<XSL: stylesheet xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"
Xmlns = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
Version = "1.0">
<XSL: template match = "foo">
<HR/>
</XSL: Template>
</XSL: stylesheet>
XSL is the namespace prefix, template is the element name, and XSL: Template is a QNAME
4. Conclusion: QNAME is nothing more than an XML element with a specific format. Its function is to increase the namespace. For example, if the same element name exists, the namespace is different. I have learned so much about it. Please add it.
Reference address:

Http://infohost.nmt.edu/tcc/help/pubs/pyxml/def-qname.html
The original article is as follows:

A document may contain in elements and attributes from more than one namespace URI. Because namespace Uris can be quite lengthy, it is cumbersome to include the complete namespace URI in each element or attribute name.

XML allows a shorthand notation to simplify assigning names to namespaces. You may invent a shortNamespace prefixAnd associate it with a namespace URI.

For example, suppose your document contains names from both the XSLT and XHTML namespaces. In this situation, it is customary to associate the namespace prefix"xsl"With XSLT. You might use prefix"html"To refer to the XHTML namespace.

AQualified nameHas three parts:

  1. A namespace prefix.

  2. A colon character,":".

  3. ALocal nameThat gives the name of the element or attribute within that namespace.

For example, here is a fragment authentication strating the use of qualified names:

<xsl:template match="separator">  

 

ElementtemplateIs in the XSLT namespace, and ElementhrIs in the HTML namespace.

You can also useUnqualified name, Which is just a local name without the namespace prefix. The namespace of such a name is calledDefault namespace.

The association between a namespace prefix and a namespace URI is made withxmlnsAttribute located in some element. This attribute can have two forms:

  • An Attribute namedxmlns='nsURI'Defines the namespace URI of the default namespace. This namespace is associated with all elements and attributes that have unqualified names.

  • An Attribute namedxmlns:prefix='nsURI'Associates the givenprefixWith the namespace URInsURI.

Here is an example of a complete document using elements from two namespaces:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"     version="1.0">  <xsl:template match="foo">    

In this example,templateElement is in the XSLT namespace.hrElement is in the default namespace, which is associated with the XHTML namespace URI.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.