- XSD simple element :XSD simple element is the element that don't include any other elements.It can be one of many different types and they are :
xs:string xs:decimal xs:integer xs:boolean xs:date xs:timeHow to define simple element : - Code:
<xs:element name="studentname" type="string"/>
The name attribute defines the name of the element (which is here "studentname" ), and the type attribute defines the element data type (which is "string" here). The type "string" is a built-in data type from the XML Schema standard. It represents character strings, including letters, digits, and other characters. This element can be added to an XML document, and it can only contain a string value. It's important to notice that if you want to apply any restriction, such as length, or white space handling, you should define the type as a simpleType and include the restriction within it.
Example of XML to this element definition :
- Code:
<studentname>
jozeph
</studentname>
Element default values :
You can define a default value for the simple element using the "default" attribute.
- Code:
<xs:element name="studentname" type="string" default="no name"/>
The default value is assigned automatically when you don't put a value. This XSD code defines an element called "studentname" with a specific data type of "string" and with a default value "no name". This means that if the element is not present in the XML document, it will be assumed to have the value "no name" by default.
- Code:
<xs:element name="studentname" type="string" fixed="samy"/>
Automatic value assignment to the element with a value you can't change later.
This XSD code defines an element called "studentname" with a specific data type of "string" and with a fixed value "samy". This means that the element must always have the value "samy" in the corresponding XML document, and a user or application cannot change it. If a different value is provided for the element, it will be considered as an error. It is different from the previous XSD code <xs:element name="studentname" type="string" default="no name"/>, in which the element is optional, and it has a default value "no name".