How do XML namespaces work without a working network connection?

Try to ignore the fact that many namespace names look like URLs that you might type into your browser. They are just random strings of characters, they aren't addresses of resources on the web. The reason people adopt this convention is that it shows who "owns" the name - it's clearer what http://www.w3.org/2001/XMLSchema refers to than if they had chosen "xsd1.0" as the namespace name, and it's less likely to conflict accidentally with a name chosen by someone else. Some people also like the fact that you can put documentation at the relevant location, but no XML software will go looking for the documentation automatically.


Let us assume we have this XML document.

<?xml version="1.0" encoding="UTF-8"?>
<html>
      <body>
        Your text here
      </body>
      <body>
        <height>182 cm</height>
        <weight>83 kg</weight>
      </body>
</html>

It includes HTML which has a body tag with a semantic meaning for a HTML renderer. It also has another body tag which carries information about a specific person. A namespace defines a semantic scope for this tag. Without a namespace(as in the example provided), it is impossible for a parser to tell the difference because they are syntactically the same.

Here is the semantically correct version of the same document:

<?xml version="1.0" encoding="UTF-8"?>
<html:html xmlns:html="http://www.w3.org/TR/xhtml1/">
  <html:body>
    Your text here
  </html:body>
  <human:body xmlns:human="http://www.example.com/human/">
    <human:height>182 cm</human:height>
    <human:weight>83 kg</human:weight>
  </human:body>
</html:html>

Thus thanks to namespaces we do not have worry about conflicting tags with different meanings.

The namespace URIs themselves are never actually resolved, and are arbitrary (thus you can use them offline).