xmlurluritransformer-modelurn

XML - Trying to grasp the concept of namespace URI


If my XSL have the following heading, I get no error :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

But if I change the xsl namespace URI... :

<xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3schools.com/xml/xml_namespaces.asp"

...I get an error :

javax.xml.transform.TransformerConfigurationException 

I think I do not understand the concept of a namespace URI, because I though that it could be any URL (not to mention URNs) as long as it was unique in the XML/XSL document. Obviously not. I tried to change the URI to test this theory.


At https://www.w3schools.com/xml/xml_namespaces.asp, we can read the following statements :

The namespace URI is not used by the parser to look up information.

The purpose of using an URI is to give the namespace a unique name.

However, companies often use the namespace as a pointer to a web page containing namespace information.

The first statement means that we don't care about what is the web page pointed by the URI, so why can't I set it to point any page I want, or even a page that does not exist ? Why does it have to specially be http://www.w3.org/1999/XSL/Transform ?

Furthermore, later on the above link we can read :

A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource.

So, because of this and because "The purpose of using an URI is to give the namespace a unique name", does it mean that a namespace URI has to be an URL (again, no to mention URNs which I absolutely can't fathom), which means that I can't set a namespace like this :

xlmns:foo="A_random_but_unique_string"

I would finish with this quote from the same link :

The namespace "http://www.w3.org/1999/XSL/Transform" identifies XSLT elements inside an HTML document

So now it means that the parser must certainly use the namespace URL to look up for information (the elements of the namespace), no ?


Solution

  • It has nothing to do with resolving URL's (and downloading schemas). Even though the XML looks the same in both examples: "xsl:stylesheet", your input is read as a stylesheet element (identified by namespace https://www.w3schools.com/xml/xml_namespaces.asp).

    The Java program expects a stylesheet element (identified by namespace http://www.w3.org/1999/XSL/Transform) however and since it cannot find it it throws an exception.