0% found this document useful (0 votes)
13 views

Unit 1 - Adbms - 2

Uploaded by

Amrin Mulani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Unit 1 - Adbms - 2

Uploaded by

Amrin Mulani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

XML Documents

DTD
XML Schema
XML Documents, DTD, and XML Schema
• Two types of XML
• Well-Formed XML
• Valid XML
XML Documents, DTD, and XML Schema
• Well-Formed XML
• It must start with an XML declaration to indicate the version of XML being
used—as well as any other relevant attributes.
• It must follow the syntactic guidelines of the tree model.
• This means that there should be a single root element, and every element must include
a matching pair of start tag and end tag within the start and end tags of the parent
element.
XML Documents, DTD, and XML Schema
• Well-Formed XML (contd.)
• A well-formed XML document is syntactically correct
• This allows it to be processed by generic processors that traverse the document and
create an internal tree representation.
• DOM (Document Object Model) - Allows programs to manipulate the resulting tree
representation corresponding to a well-formed XML document. The whole document must be
parsed beforehand when using dom.
• SAX - Allows processing of XML documents on the fly by notifying the processing program
whenever a start or end tag is encountered.
XML Documents, DTD, and XML Schema
• Valid XML
• A stronger criterion is for an XML document to be valid.
• In this case, the document must be well-formed, and in addition the element
names used in the start and end tag pairs must follow the structure specified
in a separate XML DTD (Document Type Definition) file or XML schema file.
XML Documents, DTD, and XML Schema
(contd.)
An XML DTD file called projects
XML Documents, DTD, and XML Schema
(contd.)
• XML DTD Notation
• A * following the element name means that the element can be repeated zero or more
times in the document. This can be called an optional multivalued (repeating) element.
• A + following the element name means that the element can be repeated one or more
times in the document. This can be called a required multivalued (repeating) element.
• A ? following the element name means that the element can be repeated zero or one
times. This can be called an optional single-valued (non-repeating) element.
• An element appearing without any of the preceding three symbols must appear exactly
once in the document. This can be called an required single-valued (non-repeating)
element.
XML Documents, DTD, and XML Schema
• XML DTD Notation (contd.)
• The type of the element is specified via parentheses following the element.
• If the parentheses include names of other elements, these would be the children of the
element in the tree structure.
• If the parentheses include the keyword #PCDATA or one of the other data types available
in XML DTD, the element is a leaf node. PCDATA stands for parsed character data, which
is roughly similar to a string data type.
• Parentheses can be nested when specifying elements.
• A bar symbol ( e1 | e2 ) specifies that either e1 or e2 can appear in the document.
XML Documents, DTD, and XML Schema
(contd.)
• Limitations of XML DTD
• First, the data types in DTD are not very general.
• Second, DTD has its own special syntax and so it requires specialized
processors.
• It would be advantageous to specify XML schema documents using the syntax rules of
XML itself so that the same processors for XML documents can process XML schema
descriptions.
• Third, all DTD elements are always forced to follow the specified ordering the
document so unordered elements are not permitted.
XML Documents, DTD, and XML Schema
(contd.)
An XML schema file called company
XML Documents, DTD, and XML Schema (contd.)

An XML schema file called company (contd.)


XML Documents, DTD, and XML Schema (contd.)

An XML schema file called company (contd.)


XML Documents, DTD, and XML Schema (contd.)
• An XML schema file called company (contd.)
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema
• Schema Descriptions and XML Namespaces
• It is necessary to identify the specific set of XML schema language elements (tags) by a file
stored at a Web site location.
• The second line in our example specifies the file used in this example, which is:
"http://www.w3.org/2001/XMLSchema".
• Each such definition is called an XML namespace.
• The file name is assigned to the variable xsd using the attribute xmlns (XML namespace),
and this variable is used as a prefix to all XML schema tags.
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• Annotations, documentation, and language used:
• The xsd:annotation and xsd:documentation are used for providing comments and other
descriptions in the XML document.
• The attribute XML:lang of the xsd:documentation element specifies the language being
used. E.g., “en”
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• Elements and types:
• We specify the root element of our XML schema. In XML schema, the name attribute of
the xsd:element tag specifies the element name, which is called company for the root
element in our example.
• The structure of the company root element is a xsd:complexType.
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• First-level elements in the company database:
• These elements are named employee, department, and project, and each is specified in
an xsd:element tag. If a tag has only attributes and no further sub-elements or data
within it, it can be ended with the back slash symbol (/>) and termed Empty Element.
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• Specifying element type and minimum and maximum occurrences:
• If we specify a type attribute in an xsd:element, this means that the structure of the
element will be described separately, typically using the xsd:complexType element. The
minOccurs and maxOccurs tags are used for specifying lower and upper bounds on the
number of occurrences of an element. The default is exactly one occurrence.
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• Specifying Keys:
• For specifying primary keys, the tag xsd:key is used.
• For specifying foreign keys, the tag xsd:keyref is used.
• When specifying a foreign key, the attribute refer of the xsd:keyref tag specifies the
referenced primary key whereas the tags xsd:selector and xsd:field specify the referencing
element type and foreign key.
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• Specifying the structures of complex elements via complex types:
• Complex elements in our example are Department, Employee, Project, and Dependent,
which use the tag xsd:complexType. We specify each of these as a sequence of
subelements corresponding to the database attributes of each entity type by using the
xsd:sequence and xsd:element tags of XML schema. Each element is given a name and
type via the attributes name and type of xsd:element.
• We can also specify minOccurs and maxOccurs attributes if we need to change the
default of exactly one occurrence. For (optional) database attributes where null is
allowed, we need to specify minOccurs = 0, whereas for multivalued database attributes
we need to specify maxOccurs = “unbounded” on the corresponding element.
XML Documents, DTD, and XML Schema
(contd.)
• XML Schema (contd.)
• Composite (compound) attributes:
• Composite attributes from ER Schema are also specified as complex types in the XML
schema, as illustrated by the Address, Name, Worker, and WorksOn complex types.
These could have been directly embedded within their parent elements.

You might also like