Defining Elements to Contain Only Text : simpleContent « XML Schema « XML Tutorial






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="popType">
    <xsd:simpleContent>
      <xsd:extension base="xsd:integer">
        <xsd:attribute name="year" type="xsd:integer" />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
  <xsd:element name="population" type="popType" />
</xsd:schema>

 

File: Data.xml
 
<population xmlns="http://www.java2s.com" year="1999">445</population>








3.54.simpleContent
3.54.1.The simpleContent element is used if the complex type may only have text content
3.54.2.Defining Elements to Contain Only Text
3.54.3.Creating Elements with Simple Content and Attributes
3.54.4.element based on simple type
3.54.5.As simple content models