Defining Empty Elements : complexContent « XML Schema « XML Tutorial






Elements that can contain attributes but that have no content between the opening and closing tags are considered empty.

File: Schema.xsd 
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.java2s.com" xmlns="http://www.java2s.com"
  elementFormDefault="qualified">

  <xsd:complexType name="sourceType">
    <xsd:complexContent>
      <xsd:extension base="xsd:anyType">
        <xsd:attribute name="sectionid" type="xsd:integer" />
        <xsd:attribute name="newspaperid" type="xsd:integer" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  
  <xsd:element name="source" type="sourceType" />
</xsd:schema>

 
File: Data.xml
<?xml version="1.0"?>
<source xmlns="http://www.java2s.com" sectionid="101" newspaperid="21"/>








3.55.complexContent
3.55.1.Defining Empty Elements
3.55.2.Basing Complex Types on Complex Types
3.55.3.Derived by Restriction