Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmln:tns and targetNamespace

I am seeing some XSD schema documents that declare both a targetNamespace and an xmlns:tns attribute in their top schema element. E.g. the following one taken from here. They also seem to have the same string value. I understand the role of targetNamespace but what does xmlns:tns do on top of that?

<?xml version="1.0" encoding="UTF-8"?> <schema     xmlns="http://www.w3.org/2001/XMLSchema"     targetNamespace="http://www.example.org/Product"     xmlns:tns="http://www.example.org/Product"     elementFormDefault="qualified"> ... 
like image 946
Marcus Junius Brutus Avatar asked Jun 25 '13 11:06

Marcus Junius Brutus


People also ask

What is targetNamespace in XSD file?

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.

What is TNS in XSD?

tns stands for tns Namespace (short for Target Name Space) and if you will check any enterprise wsdl it is defined in the beginning <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:enterprise.soap.sforce. ...

How do you define targetNamespace?

Most business and communications problems that XML can solve require a combination of several XML vocabularies. XML has a mechanism for qualifying names to be allocated into different namespaces, such as namespaces that apply to different industries.

Is targetNamespace an attribute of schema element?

Specifying a target namespace. The following XSD schema specifies a target namespace by using the xsd:targetNamespace attribute. The schema also sets the elementFormDefault and attributeFormDefault attribute values to "unqualified" (the default value for these attributes).


1 Answers

It lets you refer to the namespace later in the schema. For example, if you declare a named type and then want to also declare an element of that type

<complexType name="someType">   <!-- ... --> </complexType>  <element name="someElement" type="tns:someType" /> 

Simply saying type="someType" wouldn't work because that would be referring to the (non-existent) someType in the http://www.w3.org/2001/XMLSchema namespace (the xmlns="..." of the schema file) rather than the one in the http://www.example.org/Product namespace.

like image 165
Ian Roberts Avatar answered Nov 24 '22 02:11

Ian Roberts