Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

() - enclose a sequence of child elements

, - separates the items in the order on which they must appear

| - separates item in alist where only one item can appear at a time

No symbol -indicates that the item must appear exactly once

? - item can appear atleaste once

* - item can appear any number of times.

+ -item must appear atleast once.

 Mixed:
This element can contain a combination of child elements and character data.
<!ELEMENT elementname (#PCDATA)>

Parsed character
 ANY:
Any content allowed by DTD.it has virtually no structure and can contain character data,
any defined element types or a mixture of both.
<!ELEMENT elementname ANY>

DECLARING ATTRIBUTES IN DTD:


Attributes specify additional info about an element and are used inside the element(Metadata).

<!ATTLIST element name attributenames attributetype default>

Value of attributename type of attribute

The values of default are:

 #REQUIRED : Attribute is required


 #IMPLIED : Attribute is optional
 #FIXED : It has fixed value
 Default : default value
 #CDATA : denotes unparsed character
 Enumerated : series of string values
 NOTATION : notation declared somewhere else in the DTD
 ENTITY : external binary entity
 ENTITIES :multiple external binary entity
 ID : unique identifier
 IDREF : reference to an id declared somewhere else in DTD
 IDREFS : multiple reference to an id declared somewhere else in DTD
 NMTOKEN : name consisting of XML token characters i.e;
numbers,periods,dashes,colons and underscore.
 NMTOKENS : multiple names consisting of XML token characters.

The term CDATA is used about text data that should not be parsed by the XML parser.

Characters like "<" and "&" are illegal in XML elements. To avoid errors code can be defined
as CDATA.

Everything inside a CDATA section is ignored by the parser.A CDATA section starts with

"<![CDATA[" and ends with "]]>"

Internal entities:

<!ENTITY POS “Pinch of salt”>


Eg: <item> Finally add the &POS;</item>

External entities:
<!NOTATION PNG SYSTEM “xv”>

Namespaces:
<!xml :namespace ns=http://URL/namespaces/staff” prefix=”staff”>
<!xml :namespace ns=http://URL/namespaces/dept” prefix=”dept”>

XML Schema:
An XML Schema describes the structure of an XML document.

XML Schema is an XML-based alternative to DTD.


The XML Schema language is also referred to as XML Schema Definition (XSD).

The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a
DTD.
An XML Schema:

 defines elements that can appear in a document


 defines attributes that can appear in a document

 defines which elements are child elements

 defines the order of child elements

 defines the number of child elements

 defines whether an element is empty or can include text

 defines data types for elements and attributes

 defines default and fixed values for elements and attributes

XML Schemas are the Successors of DTDs


We think that very soon XML Schemas will be used in most Web applications as a replacement for
DTDs. Here are some reasons:

 XML Schemas are extensible to future additions


 XML Schemas are richer and more powerful than DTDs

 XML Schemas are written in XML

 XML Schemas support data types

 XML Schemas support namespaces

XML:
<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

XML Schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

XML Schema has a lot of built-in data types. The most common types are:

 xs:string
 xs:decimal

 xs:integer

 xs:boolean

 xs:date

 xs:time

Defining a Simple Element


Example

Here are some XML elements:

<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>

And here are the corresponding simple element definitions:

<xs:element name="lastname" type="xs:string"/>


<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>

Define an Attribute
Example

Here is an XML element with an attribute:

<lastname lang="EN">Smith</lastname>

<xs:attribute name="lang" type="xs:string"/>


Complex Empty Elements
An empty XML element:

<product prodid="1345" />

Schema:

<xs:element name="product">
  <xs:complexType>
    <xs:attribute name="prodid" type="xs:positiveInteger"/>
  </xs:complexType>
</xs:element>

Complex Types Containing Elements Only


An XML element, "person", that contains only other elements:

<person>
  <firstname>John</firstname>
  <lastname>Smith</lastname>
</person>

You can define the "person" element in a schema, like this:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

You might also like