What is the difference between targetNamespace and xmlns:target?

xsd
jojo10 picture jojo10 · Nov 8, 2010 · Viewed 88.1k times · Source

What is targetNamespace's function?

<schema xmlns="http://www.w3.org/2001/SchemaXML"
        targetNamespace="http://www.example.com/name"
        xmlns:target="http://www.example.com/name">

I understand that xmlns="http://www.w3.org/2001/SchemaXML defines the Schema XML namespace.

I also understand that xmlns:target="http://www.example.com/name" defines the namespace for my own vocabulary if I'm creating my own schema using the prefix "target"; this acts as a proxy or placeholder for the URI http://www.example.com/name.

That seems like enough to define the needed boundries and vocabularies of namespace participants. So why do I need a targetNamespace attribute which duplicates the http://www.example.com/name namespace?

Answer

Shaun picture Shaun · Oct 11, 2012

Answered quite well over here: targetNamespace and xmlns without prefix, what is the difference?

To restate:

  • targetNamespace="" - As the current XML document is a schema this attribute defines the namespace that this schema is intended to target, or validate.

  • xmlns="" - Defines the default namespace within the current document for all non-prefixed elements (i.e no yada: in <yada:elementName>)

  • xmlns:target="" - here you are just defining your own namespace with the prefix target:, this is unrelated to the previous two special cases.