XSD - FAQ's & Interview Questions
What is XML?
Extensible Markup Language (XML) is the universal language for data on the WebXML is a technology which allows us to create our own markup language.
XML documents are universally accepted as a standard way of representing information in platform and language independent manner.
XML is universal standard for information interchange.
XML documents can be created in any language and can be used in any language.
What is XML Schema?
An XML Schema describes the structure of an XML instance document by defining what each element must or may contain.XML Schema is expressed in the form of a separate XML file.XML Schema provides much more control on element and attribute datatypes.
Some datatypes are predefined and new ones can be created.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="test">
<xsd:complexType>
What is a Complex Element?
A complex element is an XML element that contains other elements and/or attributes.There are four kinds of complex elements:
empty elements
elements that contain only other elements
elements that contain only text
elements that contain both other elements and text
What is a Simple Element?
A simple element is an XML element that can contain only text.A simple element cannot have attributes
A simple element cannot contain other elements
A simple element cannot be empty
However, the text can be of many different types, and may have various restrictions applied to it
What are namespaces? Why are they important?
A simple element is an XML element that can contain only text.Namespaces are a simple and straightforward way to distinguish names used in XML documents, no matter where they come from.
XML namespaces are used for providing uniquely named elements and attributes in an XML instance
They allow developers to qualify uniquely the element names and relationships and make these names recognizable, to avoid name collisions on elements that have the same name but are defined in different vocabularies.
They allow tags from multiple namespaces to be mixed, which is essential if data is coming from multiple sources.
What are the ways to use namespaces?
There are two ways to use namespaces:Declare a default namespace
Associate a prefix with a namespace, then use the prefix in the XML to refer to the namespace
Explain why XML Schemas are Estensible?
We can Reuse our XML Schemas with in other XML Schemas.Also we can made our own data types which are derived from standard types.We can Refer multiple schemas in an same XML document.What is inline schema, how does it works?
Schemas can be included inside of XML file is called Inline Schemas.How you define optional and required attributes?
In XML Schema their is no need to set attribute as optional.Because it is by default optional.
You can define attribute is required.Than you define this by using "use" attribute.
Example:
<xs:attribute name="lang" type="xs:string" use="required"/>
Restrictions on XSD?
Restrictions are used to define acceptable values for XML elements or attributes. Restrictions on XML elements are called facets.Restrictions on a Set of Values - To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint.
Restrictions on a Series of Values - To limit the content of an XML element to define a series of numbers or letters that can be used, we would use the pattern constraint.
Restrictions on Whitespace Characters - To specify how whitespace characters should be handled, we would use the whiteSpace constraint.
Restrictions on Length - To limit the length of a value in an element, we would use the length, maxLength, and minLength constraints.