XSD Text-Only Elements

Both text and attributes can be included in a complex text-only element.

Complex Text-Only Elements:

We can add a simpleContent element around the content because the complex text-only element contains only simple content (text and attributes). We need to define an extension or a restriction within the simpleContent element while using simple content.

Syntax 1:


  
    
      
       ....
       ....
      
    
  

Syntax 2:


  
    
      
       ....
       ....
      
    
  

To expand or to limit the base simple type for the element, we can use the extension/restriction element.

Example 1:

18

Explanation:

In the above example, we are defining an XML element “cricketjersey”, that contains text-only.

Example 2:


  
    
      
        
      
    
  

Explanation:

In the above example, we are defining an XML element “cricketjersey” as a complexType whose content is defined as an integer value. This element also contains an attribute named “country”.

Example 3:




  
    
      
    
  

Explanation:

In the above example, we are giving the complexType element a name. Here, the “cricketjersey” element also has a type attribute that refers to the name of the complexType. Several elements can refer to the same complex type, by using this method.

Please follow and like us:
Content Protection by DMCA.com