91-9990449935 0120-4256464 |
XML SchemaWhat is XML schemaXML schema is a language which is used for expressing constraint about XML documents. There are so many schema languages which are used now a days for example Relax- NG and XSD (XML schema definition). An XML schema is used to define the structure of an XML document. It is like DTD but provides more control on XML structure. Checking ValidationAn XML document is called "well-formed" if it contains the correct syntax. A well-formed and valid XML document is one which have been validated against Schema. Visit http://www.xmlvalidation.com to validate the XML file against schema or DTD. XML Schema ExampleLet's create a schema file. employee.xsd Let's see the xml file using XML schema or XSD file. employee.xml Test it NowDescription of XML Schema<xs:element name="employee"> : It defines the element name employee. <xs:complexType> : It defines that the element 'employee' is complex type. <xs:sequence> : It defines that the complex type is a sequence of elements. <xs:element name="firstname" type="xs:string"/> : It defines that the element 'firstname' is of string/text type. <xs:element name="lastname" type="xs:string"/> : It defines that the element 'lastname' is of string/text type. <xs:element name="email" type="xs:string"/> : It defines that the element 'email' is of string/text type. XML Schema Data typesThere are two types of data types in XML schema.
simpleTypeThe simpleType allows you to have text-based elements. It contains less attributes, child elements, and cannot be left empty. complexTypeThe complexType allows you to hold multiple attributes and elements. It can contain additional sub elements and can be left empty.
Next TopicDTD vs XSD
|