Use the target namespace as the default namespace of the schema document : attributeFormDefault « XML Schema « XML Tutorial






File: Data.xml

<?xml version="1.0"?>
<library xmlns="http://java2s.com/ns/library">
  <book id="b0836217462" available="yes">
    <isbn>0836217462</isbn>
    <title>Java</title>
    <authors>
      <person id="CMS">
        <name>name 1</name>
        <born>1956-11-26</born>
        <dead>2000-02-12</dead>
      </person>
    </authors>
    <characters>
      <person id="PP">
        <name>Swing</name>
        <born>1966-08-22</born>
        <qualification>GUI</qualification>
      </person>
      <person id="Snoopy">
        <name>Database</name>
        <born>1950-10-04</born>
        <qualification>JDBC</qualification>
      </person>
    </characters>
  </book>
</library>


File: Schema.xsd

<?xml version="1.0"?>
<xs:schema targetNamespace="http://java2s.com/ns/library"
  elementFormDefault="qualified" attributeFormDefault="unqualified"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns="http://java2s.com/ns/library">
  <xs:element name="library">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="book" type="bookType" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="person">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:string" />
        <xs:element name="born" type="xs:date" />
        <xs:element name="dead" type="xs:date" minOccurs="0" />
        <xs:element name="qualification" type="xs:string"
          minOccurs="0" />
      </xs:sequence>
      <xs:attribute name="id" type="xs:ID" use="required" />
    </xs:complexType>
  </xs:element>
  <xs:complexType name="bookType">
    <xs:sequence>
      <xs:element name="isbn" type="xs:NMTOKEN" />
      <xs:element name="title" type="xs:string" />
      <xs:element name="authors">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="person" maxOccurs="unbounded" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="characters">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="person" maxOccurs="unbounded" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="id" type="xs:ID" use="required" />
    <xs:attribute name="available" type="xs:string" use="required" />
  </xs:complexType>
</xs:schema>








3.85.attributeFormDefault
3.85.1.Set attributeFormDefault to qualified
3.85.2.Define prefixes in the schema for both our target namespace and for the W3C XML Schema namespace
3.85.3.Use the target namespace as the default namespace of the schema document
3.85.4.Use prefixes on the components you are defining and use the W3C XML Schema vocabulary without prefixes