XML schemas are used to define the structure of an XML document. In this context, schemas are similar to DTDs that we discussed earlier. Because XML documents are platform independent, they are used extensively to transfer data over a network. This implies that an XML document should adhere to a standard structure. This standard structure is referred to as the XML schema.
When an XML document is transferred over a network, the receiving application might need to process the data to produce a result. However, first the application needs to validate the data in the XML document. Validating the data ensures that no errors are generated while processing the data. In addition, validating the data ensures that the application does not produce erroneous results after processing the data. To validate the data, the receiving application verifies that the data adheres to the XML schema. If the structure of the XML document is not validated, an error is produced.
Defining XML Schemas
An XML schema is a document written in XML syntax that defines the structure of other XML documents. An XML schema consists of elements, attributes, and data types that are allowed to be included in an XML document. In addition, XML schemas define the rules that you need to follow while designing the structure of an XML document. An XML document that adheres to an XML schema is called the document instance of the schema and is an example of a valid document.
As discussed earlier, XML schemas provide a standard against which an XML document is validated. The following section discusses how to validate XML documents in detail.
Validating XML Documents
When an XML document is created and needs to be transferred over a network, both the sending and receiving applications need to mutually agree on a set of elements, attributes, data types, and the structure of the XML document. All this information is included in the XML schema on which the XML document is based.
However, doing this limits the user to use only the components that are included in the XML schema. Therefore, the XML schema constrains the user, as described in the following list:
When an XML document is transferred, the parsers of the receiving application validate the data based on the data type and content type constraints. The parsers then verify the validity of the document.
An example of an XML schema is a DTD. A DTD also defines the structure of a document; therefore, a DTD is used to validate an XML document. However, DTDs have some limitations because of which W3C had to look for an alternative in the form of XML schemas.
The following section compares traditional DTDs with XML schemas.
Comparing DTDs with XML Schemas
Before comparing XML schemas with DTDs, we will list the problems that users face while working with DTDs. This will help you analyze the advantages of XML schemas over DTDs.
Limitations of Using DTDs
Following are some of the limitations of using DTD:
The following section discusses how schema can be a solution to the preceding problems.
XML Schema as a Solution to the Limitations of DTDs
The following list describes the advantages of XML schemas over DTDs:
XML Related Interview Questions
|Soap Tool Interview Questions||HTML Interview Questions|
|PHP Interview Questions||ASP.NET Interview Questions|
|PHP5 Interview Questions||Java Interview Questions|
|CSS Interview Questions||XSLT Interview Questions|
|Java XML Interview Questions||XMLHttpRequest (XHR) Interview Questions|
|ebXML Interview Questions||XML DOM Interview Questions|
|XML-RPC Interview Questions||XSD Interview Questions|
|Soap Web Services Interview Questions||XSL Interview Questions|
|Xml Publisher Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.