Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between targetNamespace and xmlns:target? [duplicate]

Tags:

xsd

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?

like image 382
jojo10 Avatar asked Nov 08 '10 18:11

jojo10


3 Answers

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.

like image 200
Shaun Avatar answered Oct 21 '22 11:10

Shaun


The targetNamespace declares a namespace for other xml and xsd documents to refer to this schema. The target prefix in this case refers to the same namespace and you would use it within this schema definition to reference other elements, attributes, types, etc. also defined in this same schema definition.

like image 43
s_t_e_v_e Avatar answered Oct 21 '22 13:10

s_t_e_v_e


The prefix "target" in xmlns:target="http://www.example.com/name" is nothing special. How would a schema processor know that you wanted that to be the target namespace for your schema? targetNamespace does just that - it declares the namespace that components of your schema belong to.

N.B. Not everything in the schema document goes into the targetNamespace. Note attributes "elementFormDefault" and "attributeFormDefault" on the "schema" element and also attribute "form" on the "element" and "attribute" elements.

like image 2
Kevin Avatar answered Oct 21 '22 11:10

Kevin