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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With