Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema Complex Elements – Text-Only

XSD Text-Only


A text-only complex element can contain text and attributes.


Text-Only Complex Elements

This type contains only simple content (text and attributes), so we add a simpleContent element to this content. When using simple content, we must define either an extension or a restriction inside the simpleContent element, like this:

  xs:complexType

    xs:simpleContent

     

        ....

        ....

     

   

 

or:

  xs:complexType

    xs:simpleContent

     

        ....

        ....

     

   

 

Tip: Use the extension or restriction element to extend or limit the basic simple type of an element. Here is an example of an XML element, "shoesize", that contains only text:

35

The following example declares a complex type whose content is defined as an integer value, and the "shoesize" element has an attribute named "country":

  xs:complexType

    xs:simpleContent

     

       

     

   

 

We can also give the complexType element a name and let the type attribute of the "shoesize" element refer to this name (by using this method, several elements can refer to the same complex type):

  xs:simpleContent