XML namespace depth resolution--xml1.0 and XML1.1 differences

Source: Internet
Author: User
Tags xmlns

The XML namespaces are briefly described in the article XML namespace depth resolution--Introduction to namespaces, and this article describes the differences between namespaces in XML1.0 and XML1.1. Let's start with a small example of the journey of the namespace.


example 1:xml1.0 namespace definition is empty

<xml version= "1.0" >

<root xmlns:pre= "" >

</root>

In this example, when the namespace is bound by xmlns, the URL of the namespace is empty, that is, "", if an attempt is made to parse the file, an error is reported:

The value of the attribute "prefix=" "xmlns", localpart= "pre", rawname= "Xmlns:pre" "is invalid. Prefixed namespace
Bindings May is not being empty.


The reason for the error is that the XML1.0 specification does not allow prefix to be bound to an empty URL, so error. What will happen in the XML1.1?

example 2:xml1.1 namespace definition is empty

<xml version= "1.1" >

<root xmlns:pre= "" >

</root> parsing can be found without an error, because in XML1.1 it is allowed to unbind the namespace and prefix by setting the URL to null.


example 2:xml1.1 namespaces and prefix unbound

<xml version= "1.1" >

<pre:root xmlns:pre= "url" >

<IBM xmlns:pre= ""/>

</pre:root>

In this example, the root element binds the namespace Rul to the pre, that is, the pre is in effect throughout the root, but to the root sub-element IBM, using xmlns:pre= "" To remove the binding, That is, within the scope of the IBM element, the pre will not take effect. This is why the XML file parsing fails in example 3.


Example 3:xml1.1 namespaces and prefix Unbound

<xml version= "1.1" >

<pre:root xmlns:pre= "url" >

<PRE:IBM xmlns:pre= ""/>

</pre:root> parsing of the XML file will be reported to the pre is unbound.

After 3 examples, I believe we all know the difference between the namespaces in XML1.0 and XML1.1, then the problem is that if it is for the default namespace.


Example 4:xml1.0 the default namespace is defined as empty

<xml version= "1.0" >

<root xmlns= "" >

</root> parsing of the XML file succeeds, and XML1.0 and XML1.1 support unbinding with an empty URL for the default namespace.



Example 5:xml1.0 the default namespace binding

<xml version= "1.0" >

<root xmlns= "url" >

<IBM xmlns= ""/>

</root> parsing of the XML file will succeed and IBM will not belong to any namespaces.


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.