Some explanation of XML Schema namespace using with Axis Web Service

We will use the following example to explain how schema works

<xs:schema xmlns:xs="" xmlns:x="urn:sapParam" targetNamespace="urn:sapParam" elementFormDefault="qualified" attributeFormDefault="unqualified">

                <xs:complexType name="mainTable">


                                                <xs:element name="child_email" type="x:TableOfChildEmail" nillable="true" minOccurs="0" maxOccurs="unbounded"/>

                                                <xs:element name="ipaddress_range" type="x:TableOfIpaddress" nillable="true" minOccurs="0" maxOccurs="unbounded"/>

                                                <xs:element name="website" nillable="false" minOccurs="0">


                                                                                <xs:restriction base="xs:string">

                                                                                                <xs:maxLength value="80"/>






                <xs:complexType name="TableOfIpaddress">


                                                <xs:element name="ipfrom" type="xs:string" minOccurs="0"/>

                                                <xs:element name="ipto" type="xs:string" minOccurs="0"/>



                <xs:complexType name="TableOfChildEmail">


                                                <xs:element name="childEmail" type="xs:string" minOccurs="0"/>





  • For schema, you can have complexType (contains multiple elements) and simpleType (contains single element) inside your root tag ( <xs:schema …> )
  • The root tag contains the definition of the target namespace and other namespace, where target namespace indicates that where the elements defined by this schema (those complexType and simpleType described above) come from (urn:sapParam) and other name space such as xmlns:xs specifies that the elements and data types that come from the " ".  When you need to refer to the element from somewhere, you need to use the respective prefix for the namespace that defined. For example, xs:string refer to the element defined in the namespace One thing you need to be aware of here is that you must define a namespace that associate to the target namespace when you refer to the element defined in this schema from inside of another one. For example TableOfChildEmail is defined as local element, but when you refer to it from mainTable, you must provide a prefix that associated with the target namespace. Therefore, you need to define another namespace xmlns:x="urn:sapParam" and let prefix to indicate that you want to refer to the same namespace as target namespace.   
  • The preceding paragraph showed one case that targetNamespace is mandatory required. There is another case when we import the schema inside the WSDL.
    <s:schema elementFormDefault="qualified" targetNamespace=""  xmlns:sapParam="urn:sapParam">
    s:import namespace="urn:sapParam" schemaLocation="file:///C:/dev /mySchema.xsd"/>

    The namespace attribute is mandatory for us, as we need it when we want to refer to the element defined in the imported schema (by using prefix sapParam). And the value of this namespace should be identical to the target namespace (urn:sapParam) defined in the imported schema. Therefore the target namespace is mandatory in this case.
  • elementFormDefault="qualified" indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified.
  • One more thing needs to be addressed here regarding to the incomplete support of xml schema from AXIS. You may find that there is no restriction defined for element childEmail, ipfrom and ipto, but website. The reason is that when the element has maxOccurs="unbounded" and as well as the restriction, AXIS will create the following tags in the run time WSDL.
    However, this is not valid as the extension require a value for the ‘base’ attribute. AXIS 2 version 1.0 does not support XML Schema for restriction and extension and therefore we could not provide restriction for those three elements.  
This entry was posted in Web Service. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s