Document Models with a Namespace : targetNamespace « Namespace « XML Tutorial






File: Schema.xsd

<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.java2s.com/namespaces/employee"
  xmlns="http://www.java2s.com/namespaces/employee">
  <xsd:element name="employee">
   <xsd:complexType>
    <xsd:sequence>
     <xsd:element name="name" type="xsd:string"/>
     <xsd:element name="email" type="xsd:string"/>
     <xsd:element name="hireDate" type="xsd:string"/>
    </xsd:sequence>
   </xsd:complexType>
  </xsd:element>
</xsd:schema>

File: Data.xml

<?xml version="1.0"?>
<em:employee
  xmlns:em="http://www.java2s.com/namespaces/employee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.java2s.com/namespaces/employee employee.xsd">
  <name>Joe Smith</name>
  <email>a@a.com</email>
  <hireDate>2008-10-29</hireDate>
</em:employee>








2.2.targetNamespace
2.2.1.Specify a target namespace
2.2.2.Referencing Components with Namespaces
2.2.3.Use targetNamespace as the Default Namespace
2.2.4.Defining the XML Schema Namespace as the Default
2.2.5.Document Models with a Namespace