- Generate Xsd From Xml
- Xsd To Database Schema
- Xsd To Database Java
- Xsd To Database Schema Java
- Open Xsd File
The XML Schema definition language (XSD) allows to define the structure and data types for XML documents. It contains a set of rules to which an XML document must conform in order to be valid. It is the current standard schema language, it is a recommendation of the World Wide Web Consortium (W3C). The XSD structure used to register XML schema in the database differs only on the XSD schema annotations used according to the database versions, as described in the following sections: For Oracle Database 11 g Release 1 or Later. For Oracle Database Earlier Than 11 g Release 1. If you want to make a sample XML file for testing from given XSD schema file, you could spend anything from a few minutes to a few hours manually analyzing and converting XSD to XML (and be bored to tears). Or you could use this online tool and spend just a few seconds to do it automatically!!!
What is an XML Schema?
An XML Schema describes the structure of an XML document.
The XML Schema language is also referred to as XML Schema Definition (XSD).
XSD Example
The purpose of an XML Schema is to define the legal building blocks of an XML document:
- the elements and attributes that can appear in a document
- the number of (and order of) child elements
- data types for elements and attributes
- default and fixed values for elements and attributes
Why Learn XML Schema?
In the XML world, hundreds of standardized XML formats are in daily use.
Many of these XML standards are defined by XML Schemas.
XML Schema is an XML-based (and more powerful) alternative to DTD.
XML Schemas Support Data Types
One of the greatest strength of XML Schemas is the support for data types.
- It is easier to describe allowable document content
- It is easier to validate the correctness of data
- It is easier to define data facets (restrictions on data)
- It is easier to define data patterns (data formats)
- It is easier to convert data between different data types
XML Schemas use XML Syntax
Another great strength about XML Schemas is that they are written in XML.
- You don't have to learn a new language
- You can use your XML editor to edit your Schema files
- You can use your XML parser to parse your Schema files
- You can manipulate your Schema with the XML DOM
- You can transform your Schema with XSLT
XML Schemas are extensible, because they are written in XML.
With an extensible Schema definition you can:
- Reuse your Schema in other Schemas
- Create your own data types derived from the standard types
- Reference multiple schemas in the same document
XML Schemas Secure Data Communication
When sending data from a sender to a receiver, it is essential that both parts have the same 'expectations' about the content.
With XML Schemas, the sender can describe the data in a way that the receiver will understand.
A date like: '03-11-2004' will, in some countries, be interpreted as 3.November and in other countries as 11.March.
However, an XML element with a data type like this:
2004-03-11
ensures a mutual understanding of the content, because the XML data type 'date' requires the format 'YYYY-MM-DD'.
Well-Formed is Not Enough
A well-formed XML document is a document that conforms to the XML syntax rules, like:
- it must begin with the XML declaration
- it must have one unique root element
- start-tags must have matching end-tags
- elements are case sensitive
- all elements must be closed
- all elements must be properly nested
- all attribute values must be quoted
- entities must be used for special characters
Even if documents are well-formed they can still contain errors, and those errors can have serious consequences.
Think of the following situation: you order 5 gross of laser printers, instead of 5 laser printers. With XML Schemas, most of these errors can be caught by your validating software.
- XSD Tutorial
- XSD Useful Resources
- Selected Reading
XML Schema Definition, commonly known as XSD, is a way to describe precisely the XML language. XSD checks the validity of structure and vocabulary of an XML document against the grammatical rules of the appropriate XML language.
An XML document can be defined as −
Well-formed − If the XML document adheres to all the general XML rules such as tags must be properly nested, opening and closing tags must be balanced, and empty tags must end with '/>', then it is called as well-formed.
OR
Valid − An XML document said to be valid when it is not only well-formed, but it also conforms to available XSD that specifies which tags it uses, what attributes those tags can contain, and which tags can occur inside other tags, among other properties.
The following diagram shows how XSD is used to structure XML documents −
Here is a simple XSD code. Take a look at it.
Features
Here is a list of some of the popular features of XSD −
- XSDs can be extensible for future additions.
- XSD is richer and more powerful than DTD.
- XSD is written in XML.
- XSD supports data types.
- XSD supports namespaces.
- XSD is W3C recommendation.
An XML XSD is kept in a separate document and then the document can be linked to an XML document to use it.
Syntax
The basic syntax of a XSD is as follows −
Element
Schema is the root element of XSD and it is always required.
The above fragment specifies that elements and datatypes used in the schema are defined in http://www.w3.org/2001/XMLSchema namespace and these elements/data types should be prefixed with xs. It is always required.
The above fragment specifies that elements used in this schema are defined in http://www.tutorialspoint.com namespace. It is optional.
The above fragment specifies that default namespace is http://www.tutorialspoint.com.
The above fragment indicates that any elements declared in this schema must be namespace qualified before using them in any XML Document.It is optional.
Referencing Schema
Take a look at the following Referencing Schema −
The above fragment specifies default namespace declaration. This namespace is used by the schema validator check that all the elements are part of this namespace. It is optional.
After defining the XMLSchema-instance xsi, use schemaLocation attribute. This attribute has two values, namespace and location of XML Schema, to be used separated by a space. It is optional.
We'll use Java based XSD validator to validate students.xml against the students.xsd.
students.xml
students.xsd
XSDValidator.java
Steps to validate XML against XSD
Copy the XSDValidator.java file to any location, say E: > java
Copy the students.xml to same location E: > java
Copy the students.xsd to same location E: > java
Compile XSDValidator.java using console. Make sure you have JDK 1.5 onwards installed on your machine and classpaths are configured. For details on how to use JAVA, see JAVA Tutorial
Execute XSDValidator with students.xsd and students.xml passed as argument.
Verify the output
You'll see the following result −
In this chapter, we'll see Simple Types that XSD defines.
S.No. | Simple Type & Description |
---|---|
1 | Simple Element can contain only text. It can not contain any other element. |
2 | Attribute is itself a type and is used in Complex Element. |
3 | Restriction defines the acceptable values of an XML element. |
Complex Element is an XML element which can contain other elements and/or attributes. We can create a complex element in two ways −
Define a complex type and then create an element using the type attribute
Define a complex type directly by naming
Define a Complex Type and then create an element using type attribute.
Define a Complex Type directly by naming.
Following is the list of Complex Types that XSD supports.
S.No. | Simple Type & Description |
---|---|
1 | Complex Empty complex type element can only have attributes but no contents. |
2 | Elements-Only complex type element can only contain elements |
3 | Text-Only complex type element can only contain attribute and text. |
4 | Mixed complex type element can contain element, attribute and text. |
5 | Indicators controls the ways how elements are to be organized in an XML document. |
6 | The element is used for elements which are not defined by schema |
7 | The attribute is used for attribute which are not defined by schema. |
String data types are used to represent characters in the XML documents.
data type
The data type can take characters, line feeds, carriage returns, and tab characters. The XML processor does not replace line feeds, carriage returns, and tab characters in the content with space and keep them intact. For example, multiple spaces or tabs are preserved during display.
Example
Element declaration in xsd −
Element usage in xml −
data type
The data type is derived from data type and can take characters, line feeds, carriage returns, and tab characters. XML processor will remove line feeds, tabs, carriage returns, leading and trailing spaces, and multiple spaces.
Example
Element declaration in xsd −
Element usage in xml −
String Data Types
Following is the list of commonly used data types which are derived from data type.
S.No. | Name & Description |
---|---|
1 | ID Represents the ID attribute in XML and is used in schema attributes. |
2 | IDREF Represents the IDREF attribute in XML and is used in schema attributes. |
3 | language Represents a valid language id |
4 | Name Represents a valid XML name |
5 | NMTOKEN Represents a NMTOKEN attribute in XML and is used in schema attributes. |
6 | normalizedString Represents a string that does not contain line feeds, carriage returns, or tabs. |
7 | string Represents a string that can contain line feeds, carriage returns, or tabs. |
8 | token Represents a string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces |
Restrictions
Following types of restrictions can be used with String data types −
- enumeration
- length
- maxLength
- minLength
- pattern
- whiteSpace
Generate Xsd From Xml
Date and Time data types are used to represent date and time in the XML documents.
data type
The data type is used to represent date in YYYY-MM-DD format.
YYYY − represents year
MM − represents month
DD − represents day
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent time in hh:mm:ss format.
hh − represents hours
mm − represents minutes
ss − represents seconds
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent date and time in YYYY-MM-DDThh:mm:ss format.
YYYY − represents year
MM − represents month
DD − represents day
T − represents start of time section
hh − represents hours
mm − represents minutes
ss − represents seconds
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent time interval in PnYnMnDTnHnMnS format. Each component is optional except P.
P − represents start of date section
nY − represents year
nM − represents month
nD − represents day
T − represents start of time section
nH − represents hours
nM − represents minutes
nS − represents seconds
Example
Element declaration in XSD −
Element usage in xml to represent period of 6 years, 3 months, 10 days and 15 hours.
Date Data Types
Following is the list of commonly used date data types.
S.No. | Name & Description |
---|---|
1. | date Represents a date value |
2. | dateTime Represents a date and time value |
3. | duration Represents a time interval |
4. | gDay Represents a part of a date as the day (DD) |
5. | gMonth Represents a part of a date as the month (MM) |
6. | gMonthDay Represents a part of a date as the month and day (MM-DD) |
7. | gYear Represents a part of a date as the year (YYYY) |
8. | gYearMonth Represents a part of a date as the year and month (YYYY-MM) |
9. | time Represents a time value |
Restrictions
Following types of restrictions can be used with Date data types −
- enumeration
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- whiteSpace
Numeric data types are used to represent numbers in XML documents.
data type
The data type is used to represent numeric values. It supports decimal numbers up to 18 digits.
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent integer values.
Example
Element declaration in XSD −
Element usage in XML −
Numeric Data Types
Following is the list of commonly used numeric data types.
S.No. | Name & Description |
---|---|
1. | byte A signed 8 bit integer |
2. | decimal A decimal value |
3. | int A signed 32 bit integer |
4. | integer An integer value |
5. | long A signed 64 bit integer |
6. | negativeInteger An integer having only negative values (.,-2,-1) |
7. | nonNegativeInteger An integer having only non-negative values (0,1,2,.) |
8. | nonPositiveInteger An integer having only non-positive values (.,-2,-1,0) |
9. | positiveInteger An integer having only positive values (1,2,.) |
10. | short A signed 16 bit integer Hammer 6 9 1 download free. |
11. | unsignedLong An unsigned 64 bit integer |
12. | unsignedInt An unsigned 32 bit integer |
13. | unsignedShort An unsigned 16 bit integer |
14. | unsignedByte An unsigned 8 bit integer |
Restrictions
Following types of restrictions can be used with Date data types −
- enumeration
- fractionDigits
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- totalDigits
- whiteSpace
XSD has a few other important data types, such as Boolean, binary, and anyURI.
data type
The data type is used to represent true, false, 1 (for true) or 0 (for false) value.
Example
Element declaration in XSD −
Element usage in XML −
Binary data types
Xsd To Database Schema
The Binary data types are used to represent binary values. Two binary types are common in use.
base64Binary − represents base64 encoded binary data
hexBinary − represents hexadecimal encoded binary data
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent URI.
Xsd To Database Java
Example
Element declaration in XSD −
Xsd To Database Schema Java
Restrictions
Following types of restrictions can be used with String data types −
- enumeration
- length
- maxLength
- minLength
- pattern
- whiteSpace
Generate Xsd From Xml
Date and Time data types are used to represent date and time in the XML documents.
data type
The data type is used to represent date in YYYY-MM-DD format.
YYYY − represents year
MM − represents month
DD − represents day
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent time in hh:mm:ss format.
hh − represents hours
mm − represents minutes
ss − represents seconds
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent date and time in YYYY-MM-DDThh:mm:ss format.
YYYY − represents year
MM − represents month
DD − represents day
T − represents start of time section
hh − represents hours
mm − represents minutes
ss − represents seconds
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent time interval in PnYnMnDTnHnMnS format. Each component is optional except P.
P − represents start of date section
nY − represents year
nM − represents month
nD − represents day
T − represents start of time section
nH − represents hours
nM − represents minutes
nS − represents seconds
Example
Element declaration in XSD −
Element usage in xml to represent period of 6 years, 3 months, 10 days and 15 hours.
Date Data Types
Following is the list of commonly used date data types.
S.No. | Name & Description |
---|---|
1. | date Represents a date value |
2. | dateTime Represents a date and time value |
3. | duration Represents a time interval |
4. | gDay Represents a part of a date as the day (DD) |
5. | gMonth Represents a part of a date as the month (MM) |
6. | gMonthDay Represents a part of a date as the month and day (MM-DD) |
7. | gYear Represents a part of a date as the year (YYYY) |
8. | gYearMonth Represents a part of a date as the year and month (YYYY-MM) |
9. | time Represents a time value |
Restrictions
Following types of restrictions can be used with Date data types −
- enumeration
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- whiteSpace
Numeric data types are used to represent numbers in XML documents.
data type
The data type is used to represent numeric values. It supports decimal numbers up to 18 digits.
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent integer values.
Example
Element declaration in XSD −
Element usage in XML −
Numeric Data Types
Following is the list of commonly used numeric data types.
S.No. | Name & Description |
---|---|
1. | byte A signed 8 bit integer |
2. | decimal A decimal value |
3. | int A signed 32 bit integer |
4. | integer An integer value |
5. | long A signed 64 bit integer |
6. | negativeInteger An integer having only negative values (.,-2,-1) |
7. | nonNegativeInteger An integer having only non-negative values (0,1,2,.) |
8. | nonPositiveInteger An integer having only non-positive values (.,-2,-1,0) |
9. | positiveInteger An integer having only positive values (1,2,.) |
10. | short A signed 16 bit integer Hammer 6 9 1 download free. |
11. | unsignedLong An unsigned 64 bit integer |
12. | unsignedInt An unsigned 32 bit integer |
13. | unsignedShort An unsigned 16 bit integer |
14. | unsignedByte An unsigned 8 bit integer |
Restrictions
Following types of restrictions can be used with Date data types −
- enumeration
- fractionDigits
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- totalDigits
- whiteSpace
XSD has a few other important data types, such as Boolean, binary, and anyURI.
data type
The data type is used to represent true, false, 1 (for true) or 0 (for false) value.
Example
Element declaration in XSD −
Element usage in XML −
Binary data types
Xsd To Database Schema
The Binary data types are used to represent binary values. Two binary types are common in use.
base64Binary − represents base64 encoded binary data
hexBinary − represents hexadecimal encoded binary data
Example
Element declaration in XSD −
Element usage in XML −
data type
The data type is used to represent URI.
Xsd To Database Java
Example
Element declaration in XSD −
Xsd To Database Schema Java
Element usage in XML −
Numeric Data Types
Following is the list of commonly used numeric data types.
S.No. | Name & Description |
---|---|
1. | byte A signed 8 bit integer |
2. | decimal A decimal value |
3. | int A signed 32 bit integer |
4. | integer An integer value |
5. | long A signed 64 bit integer |
6. | negativeInteger An integer having only negative values (.,-2,-1) |
7. | nonNegativeInteger An integer having only non-negative values (0,1,2,.) |
8. | nonPositiveInteger An integer having only non-positive values (.,-2,-1,0) |
9. | positiveInteger An integer having only positive values (1,2,.) |
10. | short A signed 16 bit integer |
11. | unsignedLong An unsigned 64 bit integer |
12. | unsignedInt An unsigned 32 bit integer |
13. | unsignedShort An unsigned 16 bit integer |
14. | unsignedByte An unsigned 8 bit integer |
Restrictions
Open Xsd File
Following types of restrictions can be used with Miscellaneous data types except on boolean data type −
- enumeration
- length
- maxLength
- minLength
- pattern
- whiteSpace