3

I'm trying to understand the reasons of the XML-namespaces convention (using URI for namespaces).

I've read this thread on StackOverflow. I understand that namespace's fullname should be unique. But I still don't understand why can't we just use random strings for this?

For example, we're trying to distinguish the real cars from the toy cars in our file:

<?xml version="1.0" encoding="UTF-8"?>
<carstore xmlns:real="http://cxf.apache.org/jaxws/cars/real" xmlns:toy="http://cxf.apache.org/jaxws/cars/toy">
<real:car category="truck">
    <model lang="en">Scania R 770</model>
    <year>2005</year>
    <price currency="US dollar">200000.00</price>
</real:car>
<toy:car category="sedan">
    <title lang="en">Ford Focus</title>
    <year>2012</year>
    <price currency="US dollar">100.00</price>
</toy:car>
</carstore>


<?xml version="1.0" encoding="UTF-8"?>
<carstore xmlns:real="heroigairehgoiaer7272" xmlns:toy="289ry89fhfhbvnsdkljnv">
<real:car category="truck">
<model lang="en">Scania R 770</model>
<year>2005</year>
<price currency="US dollar">200000.00</price>
</real:car>
<toy:car category="sedan">
<title lang="en">Ford Focus</title>
<year>2012</year>
<price currency="US dollar">100.00</price>
</toy:car>
</carstore>

I'll be grateful if someone will explain why this option

xmlns:real="http://cxf.apache.org/jaxws/cars/real"

is better than this one:

xmlns:real="heroigairehgoiaer7272"

What negative consequences can we face using the second one? Probably there is any real-life examples?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
jd2050
  • 182
  • 1
  • 2
  • 16
  • In case you’re not aware of it: You can use a URI that consists of a random string, namely a [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier), e.g. `urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66`. – unor May 01 '19 at 19:30

1 Answers1

3

Random, unique, strings could be used for namespace values, however...

URI-based namespaces offer advantages over random strings:

  1. Leveraging the in-place ownership mechanisms of domain names avoids having to replicate that functionality for control of namespaces.
  2. Domain names communicate ownership, which is useful for identifying a party or project responsible for a namespace.
  3. Although namespace URIs do not have to be retrievable, they can be and often are, thus serving as a convenient means of retrieval of governing schemas or documentation.
  4. Hierarchical nature of URI's can mirror the natural hierarchical organization of name collections.
kjhughes
  • 106,133
  • 27
  • 181
  • 240