Strawberry
Strawberry

Reputation: 67968

What is <ns0: for?

I was looking at this question: How to remove duplicate elements from an xml file?

It has <ns0: for ? I have never seen it before.

Upvotes: 10

Views: 32677

Answers (1)

mjv
mjv

Reputation: 75288

The ns0: prefix for an element name is a reference to a (XML) NameSpace.

In this case (the XML snippet I think you are referencing in the other question), the namespace in question was defined as: xmlns:ns0="http://TestIndexMap.Employees" earlier in the document.

Essentially, with this line, the string "ns0" (one could have chosen most any other string) is associated with a particular namespace, apparently one defining schema for Employees data of sorts.
Note that the URI ("http://TestIndexMap.Employees") doesn't correspond to a valid online resource of sorts. The XML Standard recommends the use of URIs for the purpose of identifying namespaces; that is because URIs are controlled and managed in a distributed and hierarchical fashion, preventing possible clashes, as would be the case, would we use plain strings such as "employee_data". There is no expectation however that the underlying URI would effectively exist as an online resource.
(BTW this particular URI seems bogus, i.e. doesn't include a particular domain, hence making possible albeit unlikely that at some point this document may clash with other documents using the same string for their namespace).

In a nutshell, namespaces are used (among other things) to prevent possible conflicts in the names used in XML documents. They allow for example for a given document to include two distinct, say, <price> elements, or say, closed attributes, so long as one of them is prefixed with a namespace previously defined (and indeed even the one without an explicit namespace prefix belongs to a namespace: the default one).

Upvotes: 20

Related Questions