What is the tns Namespace?

Problem

When generating code from a schema that contains a default namespace, you may see that all the classes generated, are contained within the tns Namespace (short for Target Name Space) .
This is not always the most appropriate namespace, however the generator could not find anything more appropriate to use within the schema.

Sample

<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://sample" xmlns="http://sample" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Customer" type="CustomerType"> <xs:annotation> <xs:documentation>Comment describing your root element</xs:documentation> </xs:annotation> </xs:element> <xs:complexType name="CustomerType"> <xs:sequence> <xs:element name="FirstName" type="xs:string"/> <xs:element name="MiddleInitial" type="xs:string"/> <xs:element ref="LastName"/> </xs:sequence> <xs:attribute name="clubCardMember" type="xs:boolean"/> <xs:attribute ref="customerID"/> </xs:complexType> <xs:element name="LastName" type="xs:string"/> <xs:attribute name="customerID" type="xs:integer"/> </xs:schema>

Resolution

The namespace name can be changed using the schema mapping tool that comes with the XML databinding wizard. Using this the tns namespace can be replaced by an identifier that is more meaningful. Or the schema can be changed to provide an additional alias for the namespace ie

<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://sample" xmlns:MyAlias="http://sample" xmlns="http://sample" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Customer" type="CustomerType"> <xs:annotation> <xs:documentation>Comment describing your root element</xs:documentation> </xs:annotation> </xs:element> <xs:complexType name="CustomerType"> <xs:sequence> <xs:element name="FirstName" type="xs:string"/> <xs:element name="MiddleInitial" type="xs:string"/> <xs:element ref="LastName"/> </xs:sequence> <xs:attribute name="clubCardMember" type="xs:boolean"/> <xs:attribute ref="customerID"/> </xs:complexType> <xs:element name="LastName" type="xs:string"/> <xs:attribute name="customerID" type="xs:integer"/> </xs:schema>

 

Description Value
Article Created 7/2/2006
Applies to Liquid XML 2005 and greater