Controlling the namespace's in the generated code

Support FAQ > Liquid XML Data Binding
When generating Xml classes from my schema I noticed that the support classes (e.g. ClassFactory) have a namespace of the  default one that I specified in the Databinder wizard (e.g. mycompany.projectX) while the classes that represent the actual schema items have a different namespace (e.g. mycompany.tns) that seems to have been auto generated. Why is this and can I change the namespace for the generated schema classes to reflect what I want?



When classes are generated they are placed into the appropriate namespace.

If you do not specify a targetNamespace in your schema then all the items will go into the default (no-name) namespace. You can control the name this gets in the code in the Language selection page of the wizard - Default Class Namespace.

If a targetNamespace is specified then typically all the generated classes will go into this namespace. By default this is named 'tns'. There are 2 ways to control the naming of this namespace in the generated code.
  • You can define an alias for the namespace in the schema xmlns:myComp="www.mycompany.com"

     <xs:schema xmlns:myComp="www.mycompany.com" elementFormDefault="qualified"
    targetNamespace="www.mycompany.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    This allows the generator to associate the alias "myComp" with the namesapce "http://www.mycompany.com/" which is the target namespace.

  • You can change the name of the namespace in the wizard "Select Output Options->Change Schema  to Object Mappings ...". Then change the "Class Namespace" Property of the namespace.
You may think that if a target namespace is specified then all the items in this namespace should be placed into the default namespace and then there would be no need for the 'tns' alias stuff. Unfortunately things are a little more complicated than that, and it is possible to define a schema that contains items in the default (no-name) namespace and a target namespace. So under some circumstances both are used in the same schema.

Sample Schema (No target namespace)

1 <?xml version="1.0" encoding="utf-8" ?>
2 <!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
3 <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
4   <xs:element name="RootElm">
5     <xs:complexType>
6       <xs:sequence>
7         <xs:element name="Item" type="xs:string" />
8       </xs:sequence>
9     </xs:complexType>
10   </xs:element>
11 </xs:schema>

Sample Schema (Anonymous Target namespace)





1 <?xml version="1.0" encoding="utf-8" ?>
2 <!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
3 <xs:schema elementFormDefault="qualified" targetNamespace=http://www.mycompany.com/
xmlns:xs
="http://www.w3.org/2001/XMLSchema">
4   <xs:element name="RootElm">
5     <xs:complexType>
6       <xs:sequence>
7         <xs:element name="Item" type="xs:string" />
8       </xs:sequence>
9     </xs:complexType>
10   </xs:element>
11 </xs:schema>






Sample Schema (Aliased Target namespace)
1 <?xml version="1.0" encoding="utf-8" ?>
2 <!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
3 <xs:schema xmlns:myComp="www.mycompany.com" elementFormDefault="qualified"
targetNamespace
="www.mycompany.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
4   <xs:element name="RootElm">
5     <xs:complexType>
6       <xs:sequence>
7         <xs:element name="Item" type="xs:string" />
8       </xs:sequence>
9     </xs:complexType>
10   </xs:element>
11 </xs:schema>

Add Feedback