1
votes

I know why we need namespace in XML, which is to differentiate potential same named element with different definition or meaning, like 'table' in HTML and furniture.

But I could not tell the reason why we need a URI in an xmlns declaration. What is it for, and why is it a URI ?

Should XML parser use the content in the URI to checkout some useful info to parse the XML?

If not, why I cannot just use some random numbers to be my URI.

And in my opinion, as long as the prefix does not collide in a single XML, there would not be any collision, because of which we don't need that URI.

Give me some hints, thanks.

XML and JSON are both for data transfering, but it's kind of weird that JSON doesn't have namespaces while XML have namespace and sees it as an important topic? Kind of weird, am I misunderstood something?

1

1 Answers

1
votes

I know why we need namespace in XML, which is to differentiate potential same named element with different definition or meaning, like 'table' in HTML and furniture.

But I could not tell the reason why we need a URI in an xmlns declaration. What is it for, and why is it a URI ?

See Why are XML namespaces HTTP addresses?

Should XML parser use the content in the URI to checkout some useful info to parse the XML?

If not, why I cannot just use some random numbers to be my URI.

See Must an XML namespace name URI be retrievable?

And in my opinion, as long as the prefix does not collide in a single XML, there would not be any collision, because of which we don't need that URI.

XML namespace prefixes are abbreviations. To expect a disparate community to agree to independently self-assign non-conflicting uses of short sequences of characters is unrealistic.

XML and JSON are both for data transfering, but it's kind of weird that JSON doesn't have namespaces while XML have namespace and sees it as an important topic? Kind of weird, am I misunderstood something?

Should JSON schema adoption mature to the point of having to represent independently developed identifier vocabularies and grammars concurrently in a single scope, it will likely develop some mechanism to solve the problem addressed by namespaces. Note, however, that the difference between JSON's strength in data exchange and XML's in document representation is significant.