XML Tutorial – Schema- XSD (XML Schema Definition)

The tutorial provides the insight on the XML Schema – XSD ( XML Schema Validation) which defines the structure for the XML Document like XML DTD ( Document Type Definition) .

XML Schema (XSD) and XML DTD both are used to validate the XML Document. In other words, we can say the “well-formed” or “valid” XML Document is VALIDATED against XML Schema.

XML Schema features

  1. XML Schema defines the structure for the XML Document written in XML
  2. XML Schema provides the description for the XSD format
  3. XML Schema provides the support for data types to be defined for each XML element
  4. XML Schema provides the support for XML namespaces
  5. XML Schema can be verified with the sample XML Data

XML Element

The defined XML Tags in the XML Document are elements. The XML elements should follow the below naming rules

  1. XML element is case-sensitive
  2. XML element can start with a “letter” or an “underscore”
  3. The letter “XML”, “xml” “Xml” “xMl” “xmL” are not support as element name as considered a Reserve word
  4. The XML Element can consistes of letters, digits, hyphens, underscores, and periods
  5. XML element with spaces is NOT supported

XML Attributes

XML Attribute stores the data for a specific XML element.

<student gender=’male’>

XML Element vs XML Attribute

XML Attributes are defined for the XML element. The first exmaple shows the usage of XML Attribute as gender in the student element whereas the next example shows the gender as the XML element belongs to the parent element “student”

XML Attribute – Points to Consider

  1. XML Attribute does not support multiple values
  2. XML Attribute does not support Tree structure
  3. XML Attribute is not flexible for change

<student gender="male">
  <firstname>Mohit</firstname>
  <lastname>Sharma</lastname>
</student> 

<student>
  <gender> male </male>
  <firstname>Mohit</firstname>
  <lastname>Sharma</lastname>
</student> 

Empty XML Element

XML Schema supports the empty XML element. The empty XML element also support attributes.

<nickName category=”personal” ></nickName>

The empty XML element has an attribute with category =”personal”

or

<nickName />

The below given is the Student XML Schema Structure , created using XML .

<xs:element name=”student”> depicts the XML element name
<xs:complexType> depicts that the element “student” has the complex type , means it contains multple XML elements
<xs:sequence> depicts the sequence of elements mapped for the XML element student with complex type
<xs:element name=”fisrtName” type=”xs:string”/> depicts the data type as “string” for the element firstName
<xs:element name=”lastName” type=”xs:string”/> depicts the data type as “string” for the element lastName
<xs:element name=”registered” type=”xs:string”/> depicts the data type as “string” for the element registered

 

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.oracleappshelp.com"
xmlns="https://www.oracleappshelp.com"
elementFormDefault="qualified">


<xs:element name="student">

<xs:complexType>
  <xs:sequence>
    <xs:element name="fisrtName" type="xs:string"/>
    <xs:element name="lastName" type="xs:string"/>
    <xs:element name="registered" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

</xs:element> 

</xs:schema>
XML Tutorial – Schema- XSD (XML Schema Definition)
Scroll to top
Copy Protected by Chetan's WP-Copyprotect.