SlideShare a Scribd company logo
1 of 77
UNIT I INTRODUCTION TO XML
XML document structure – Well formed and valid
documents – Namespaces – DTD – XML Schema
– X-Files.
Well formed and valid documents
well-structured XML document can easily be
transported b/w systems and devices
Introduction
• XML documents can be well formed, and they can also be valid.
• Validity implies “well-formedness,” but not vice versa.
• A valid XML document is a strict form of a well-formed XML document.
• It’s like saying that a square is a rectangle, but not vice versa.
Well-Formed Documents
• An XML document is well formed
– If it follows all syntax rules of XML.
– If it does not includes inappropriate markup or characters that cannot be
processed by XML parsers
• An XML document can’t be partially well formed.
• And, by definition, if a document is not well formed, it is not XML.
Valid Documents
• Property of “well-formedness”
– A matter of making sure the XML document complies to syntactical rules
• A well-formed XML document is considered valid only
– If it contains a proper Document Type Declaration and
– If the document obeys the constraints of that declaration
• Constraints of the declaration will be expressed as
– A DTD or
– An XML Schema.
Valid Vs Well-formed XML Document
• Well-formed XML documents are designed for use without any constraints
– Valid XML documents explicitly require these constraint mechanisms
• Valid XML documents can take advantage of certain advanced features of
XML
– Those advanced features of XML are not available to merely well-formed
documents due to their lack of a DTD or XML Schema.
• Creation of well-formed XML is a simple process,
– But the use of valid XML documents can greatly improve the quality of
document processes
Well Formed Document
• Use our XML validator to syntax-check your XML.
• An XML document with correct syntax is called "Well Formed".
• Important Syntax rules :
1. XML documents must have a root element
2. XML elements must have a closing tag
3. XML tags are case sensitive
4. XML elements must be properly nested
5. XML attribute values must be quoted
XML Errors Will Stop You
• Errors in XML documents will stop your XML applications.
• W3C XML specification states that
– A program should stop processing an XML document if it finds an error.
• The reason is that XML software should be small, fast, and compatible.
• HTML browsers are allowed to display HTML documents with errors
(like missing end tags).
• With XML, errors are not allowed.
Valid XML Documents
• A "well formed" XML document is not the same as a "valid" XML
document.
• A "valid" XML document must be well formed.
– In addition, it must conform to a document type definition.
• Two different document type definitions that can be used with XML:
1. DTD (Original Document Type Definition)
2. XML Schema (An XML-based alternative to DTD)
• A document type definition
– Defines the rules and the legal elements and attributes for an XML document.
Difference Between XML and HTML
• XML is not a replacement for HTML.
• XML and HTML were designed with different goals:
– XML was designed to describe data, with focus on what data is
– HTML was designed to display data, with focus on how data looks
• HTML is about displaying information,
– While XML is about carrying information.
Use of XML
• XML can be used to encode any structured information
• XML is good at representing
– Information that has an extensible, hierarchical format and requires
encoding of metadata.
XML Does Not DO Anything
• <note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
• XML document does not DO anything
• It is just information wrapped in tags.
– One must write a piece of s/w to send, receive or display it.
It has
Sender and receiver information,
A heading and a message body.
How Can XML be Used?
• XML Separates Data from HTML
• XML Simplifies Data Sharing
• XML Simplifies Platform Changes
• Internet Languages Written in XML
XML Delimiter Characters
• XML language has 4 special delimiters
Character Meaning
< Start of an XML markup tag
> End of an XML markup tag
& Start of an XML entity
; End of an XML entity
XML Syntax Rules
• All XML Elements Must Have a Closing Tag
• XML Tags are Case Sensitive
Example:
<message>This is incorrect</Message>
<message>This is correct</message>
• XML Elements Must be Properly Nested
• XML Documents Must Have a Root Element
• XML Attribute Values Must be Quoted
Empty XML Elements
• An element with no content is said to be empty.
• <element></element>
OR
• <element />
XML Attributes
• XML elements can have attributes, just like HTML.
• Attributes provide additional information about an element.
• Attributes often provide information that is not a part of the
data.
• XML Attribute value must be Quoted (single or double quotes)
<person gender="female">
XML Tree
• XML documents form a tree structure
– That starts at "the root" and branches to "the leaves".
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!
</body>
</note>
• First line is the XML declaration.
It defines the XML version
• Next line describes the
root element of the document.
<note>
• Next 4 lines describe
4 child elements of root
(to, from, heading, body)
• Last line defines the
end of the root element: </note>
Example
<bookstore>
  <book category="CHILDREN">
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>
<bookstore>
  <book category="CHILDREN">
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title>Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>
An XML element is everything from
(including) the element's start tag to
(including) the element's end tag.
An element can contain:
– other elements
– text
– attributes
– or a mix of all of the above...
XML Elements vs. Attributes
<person gender="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<gender>female</gender>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
• There are no rules about
when to use attributes or
when to use elements.
• In XML best advice is to avoid
them. Use elements instead.
XML Elements are Extensible
• XML elements can be extended to carry more information.
<note>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note>
MESSAGE
To: Tove
From: Jani
Don't forget me this weekend!
Extended without breaking applications
• Previous XML document added some extra information to it:
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Should the application break or crash?
No. 
Application should be able to find <to>, <from>, and <body> elements 
in the XML document and produce the same output.
One of the beauties
of XML, is that it can
be extended without
breaking
applications.
Best way of using XML
<note date="2008-01-10">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A date attribute is used in the first example:
<note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
A date element is used in the second example:
• An expanded date element is used in the third:
<note>
<date>
<year>2008</year>
<month>01</month>
<day>10</day>
</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Problems With Using Attributes
1. Attributes cannot contain multiple values (elements can)
2. Attributes cannot contain tree structures (elements can)
3. Attributes are not easily expandable (for future changes)
XML Namespaces
• XML Namespaces provide a method to avoid element name conflicts.
• This XML carries HTML table information:
• This XML carries information about a table (a piece of furniture):
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
Solving the Name Conflict Using a Prefix
• If these XML fragments were added together,
– There would be a name conflict.
• Both contain a <table> element,
– But the elements have different content and meaning.
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
In this example, 
there will be no conflict 
because the two <table> 
elements have different 
names.
Document Type Definition (DTD)
• An XML document with correct syntax is called "Well Formed".
• An XML document validated against a DTD is both "Well
Formed" and "Valid".
Document Type Definition (DTD)
• A DTD defines the structure and the legal elements and
attributes of an XML document.
• A DTD can be declared
– Inside an XML document or
– In an external file.
Example of DTD inside an XML File
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
Building Blocks of XML Documents
• Elements
• Attributes
• Entities
• PCDATA
• CDATA
• Elements are the main building blocks of both XML and HTML
documents.
<body>some text</body>
<message>some text</message>
Attributes
• Attributes provide extra information about elements.
<image src ="computer.gif" />
• The name of the element is "img".
• The name of the attribute is "src".
• The value of the attribute is "computer.gif".
• Since the element itself is empty it is closed by a " /".
Entities
• Some characters have a special meaning in XML,
– Like, the less than sign (<) that defines the start of an XML tag.
Entity References Character
&lt; <
&gt; >
&amp; &
&quot; "
&apos; '
PCDATA - Parsed Character DATA
• PCDATA is text that WILL be parsed by a parser.
• Text will be examined by the parser for entities and markup.
CDATA - Character DATA.
• CDATA means character data.
• CDATA is text that will NOT be parsed by a parser.
• Tags inside the text will NOT be treated as markup and
entities will not be expanded.
Declaring Elements
• General form
• Empty Elements
<!ELEMENT element-name category>
or
<!ELEMENT element-name (element-content)>
<!ELEMENT element-name EMPTY>
Example:
<!ELEMENT br EMPTY>
Declaring Attributes
Syntax:
<!ATTLIST element-name attribute-name attribute-type attribute-
value>
DTD example:
<!ATTLIST payment type CDATA "check">
XML example:
<payment type="check" />
Attribute Types
The attribute-type can be one of the following:
Type Description
CDATA The value is character data
(en1|en2|..) The value must be one from an enumerated list
ID The value is a unique id
IDREF The value is the id of another element
IDREFS The value is a list of other ids
NMTOKEN The value is a valid XML name
NMTOKENS The value is a list of valid XML names
ENTITY The value is an entity
ENTITIES The value is a list of entities
NOTATION The value is a name of a notation
xml: The value is a predefined xml value
The attribute-value can be one of the following:
Value Explanation
value The default value of the attribute
#REQUIRED The attribute is required
#IMPLIED The attribute is optional
#FIXED value The attribute value is fixed
DTD - Entities
• Entities are used to define shortcuts to special characters.
Syntax:
<!ENTITY entity-name "entity-value">
DTD Example:
<!ENTITY writer "Donald Duck.">
<!ENTITY copyright "Copyright W3Schools.">
XML example:
<author>&writer;&copyright;</author>
Why Use a DTD?
• Your application can use a standard DTD
– To verify that the data you receive from the outside world is valid.
• You can also use a DTD to verify your own data.
Example of DTD in an external DTD file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
"note.dtd"
If the DTD is declared in an external file, the <!DOCTYPE>
definition must contain a reference to the DTD file:
Example : TV Schedule DTD
<!DOCTYPE TVSCHEDULE [
<!ELEMENT TVSCHEDULE (CHANNEL+)>
<!ELEMENT CHANNEL (BANNER,DAY+)>
<!ELEMENT BANNER (#PCDATA)>
<!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)>
<!ELEMENT HOLIDAY (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT PROGRAMSLOT
(TIME,TITLE,DESCRIPTION?)>
<!ELEMENT TIME (#PCDATA)>
<!ELEMENT TITLE (#PCDATA)>
<!ELEMENT DESCRIPTION (#PCDATA)>
<!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED>
<!ATTLIST CHANNEL CHAN CDATA #REQUIRED>
<!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED>
<!ATTLIST TITLE RATING CDATA #IMPLIED>
<!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>
]>
Example : Newspaper Article DTD
<!DOCTYPE NEWSPAPER [
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE
(HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic
Press">
]>
Newspaper Article DTD
<!DOCTYPE NEWSPAPER [
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE
(HEADLINE,BYLINE,LEAD,BODY,NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPAPER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">
]>
XML Schema
Referred as XML Schema Definition (XSD)
An XML Schema describes the structure of an XML
document.
What You Should Already Know
• Before you continue, have a basic understanding of the
following:
– HTML
– XML
– A basic understanding of DTD
What is an XML Schema?
• An XML Schema
– Describes the structure of an XML document, just like a DTD.
• An XML document with correct syntax is called "Well Formed".
• An XML document validated against an XML Schema is both
"Well Formed" and "Valid".
What XML Schema Defines?
• 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
Why Use XML Schemas?
• XML Schemas Support Data Types
• XML Schemas use XML Syntax
• XML Schemas Secure Data Communication
• XML Schemas are Extensible
Why Use XML Schemas?
• Well-Formed XML document is not Enough
– 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 - The <schema> Element
General Form :
<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>
The <schema> element may contain some attributes.
Example
A Simple XML Document called "note.xml":
<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>
DTD file called "note.dtd"
That defines the elements of the above XML document
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
An XML Schema
• An XML Schema file "note.xsd"
– That defines the elements of the XML document above ("note.xml")
<?xml version="1.0"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
    targetNamespace = "http://www.w3schools.com"
xmlns = "http://www.w3schools.com"
elementFormDefault = "qualified">
<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>
Other elements (to, from, heading, body)
are simple types because they do not contain
other elements.
Note element is a complex
type because it contains other
elements.
• xmlns:xs = http://www.w3.org/2001/XMLSchema
– Indicates that the elements and data types used in the schema
come from the "http://www.w3.org/2001/XMLSchema" namespace.
• targetNamespace = http://www.w3schools.com
– Indicates that the elements defined by this schema (note, to, from,
heading, body) come from the "http://www.w3schools.com"
namespace.
• xmlns=http://www.w3schools.com
– indicates that the default namespace is "http://www.w3schools.com".
• elementFormDefault="qualified“
– indicates that any elements used by XML instance document which
were declared in this schema must be namespace qualified.
What is a Simple Element?
• A simple element is an XML element that can contain only text
– It cannot contain any other elements or attributes.
• Text can be of many different types.
– It can be one of the types included in XML Schema definition
(boolean, string, date, etc.), or
– It can be a custom type that you can define yourself.
• Syntax for defining a simple element is:
<xs:element name="xxx" type="yyy"/>
Most Common Types
• XML Schema has a lot of built-in data types.
• Most common types are:
 xs:string
 xs:decimal
 xs:integer
 xs:boolean
 xs:date (YYYY-MM-DD)
 xs:time (HH:MM:SS)
Default Values for Simple Elements
• A fixed value is automatically assigned to the element,
– You cannot specify another value.
• In the following example the fixed value is "red":
<xs:element name="color" 
    type="xs:string" fixed="red"/>
Fixed Values for Simple Elements
• A default value is automatically assigned to the element
– When no other value is specified.
• In the following example the default value is "red":
<xs:element name="color" 
    type="xs:string" default="red"/>
XSD Attributes
• Simple elements cannot have attributes.
• If an element has attributes,
– It is considered to be of a complex type.
• But the attribute itself is always declared as a simple type.
<xs:attribute name="xxx" type="yyy"/>
xxx is the name of the attribute
yyy specifies the data type of the attribute.
XML Document Structure
-
XML Document Structure
• An XML document consists of a number of discrete components
• Not all the sections of an XML document may be necessary,
– But their inclusion helps to make for a well-structured XML document
• A well-structured XML document can
– Easily be transported between systems and devices
Major portions of an XML document
• The major portions of an XML document include the following:
– The XML declaration
– The Document Type Declaration (DTD)
– The element data
– The attribute data
– The character data or XML content
XML Declaration
• XML Declaration is a definite way of stating exactly
– What the document contains.
• XML document can optionally have an XML declaration
– It must be the first statement of the XML document
• XML declaration is a processing instruction of the form
<?xml ...?>
Components of XML Declaration
Component Meaning
<?xml Starts the beginning of the processing instruction
Version= “xxx” Describes the specific version of XML being used
standalone= “xxx” Defines whether documents are allowed to contain
external markup declarations
encoding= “xxx” Indicates the character encoding that the document uses.
The default is “US-ASCII” but can be set to any value
Example :
Document Type Declaration (DTD)
• A DTD defines the structure and the legal elements and
attributes of an XML document.
• An application can use a DTD to verify that XML data is valid.
• If the DTD is declared inside the XML file, it must be wrapped
inside the <!DOCTYPE> definition:
• Document Type Declaration (DOCTYPE) gives a name to the
XML content
• A Document Type Declaration (DOCTYPE)
– Names the document type and
– Identifies the internal content
OOA
• OOA emphasis on
– Finding and describing the objects (or concepts in the problem
domain)
• OOD emphasis on
– Defining software What the system does (its static structure and
behavior),
• OOD focuses on
– How the system does it (it’s run-time implementation).
OOA
• During OOA, the most important purpose is
– To identify objects and describing them in a proper way.
• Objects should be identified with responsibilities.
• Responsibilities are the functions performed by the object.
– Each and every object has some type of responsibilities to be performed.
• When these responsibilities are collaborated the purpose of the system is
fulfilled.
OOD
• Second phase is OOD. During this phase
– Emphasis is given upon the requirements and their fulfillment.
• In this stage,
– The objects are collaborated according to their intended association.
• After the association is complete the design is also complete.
• Third phase is object oriented implementation.
– In this phase the design is implemented using object oriented languages like
Java, C++ etc.
UML
• OO design is transformed into UML diagrams according to the
requirement.
• Input from the OO analysis and design is the input to the UML diagrams.
• UML is a modeling language used to model s/w and non s/w systems.
• Although UML is used for non software systems
– Emphasis is on modeling object oriented software applications.
Conceptual model of UML
• A conceptual model can be defined as
– A model which is made of concepts and their relationships
• A conceptual model is the first step before drawing a UML diagram.
• It helps to
– Understand the entities in the real world and how they interact with each other.
• Conceptual model of UML can be mastered by learning the 3 major
elements:
1. UML building blocks
2. Rules to connect the building blocks
3. Common mechanisms of UML
UML building blocks
• Three building blocks of UML are:
– Things
– Relationships
– Diagrams
Object
• Object is a term used to represent a real world entity within
the system being modeled
• Objects has its own attributes and operations (methods).
– Consider the real world object “Car”
make = ford
model = escape
year = 2002
color = green
maximum speed = 130 mph
current speed = 50 mph
accelerate ()
decelerate ()
refuel ()
Network
• During the OOA phase object-modeling techniques are used
• To reflect the structure and behaviour of the system
– A range of models can be created using such objects

More Related Content

What's hot (20)

Design patterns difference between interview questions
Design patterns   difference between interview questionsDesign patterns   difference between interview questions
Design patterns difference between interview questions
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
object oriented methodologies
object oriented methodologiesobject oriented methodologies
object oriented methodologies
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Object modeling
Object modelingObject modeling
Object modeling
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
 
JDBC
JDBCJDBC
JDBC
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
Ajax
AjaxAjax
Ajax
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 

Similar to 02 well formed and valid documents (20)

00 introduction
00 introduction00 introduction
00 introduction
 
Xml
XmlXml
Xml
 
Xml
XmlXml
Xml
 
Xml passing in java
Xml passing in javaXml passing in java
Xml passing in java
 
XML
XMLXML
XML
 
BITM3730 10-31.pptx
BITM3730 10-31.pptxBITM3730 10-31.pptx
BITM3730 10-31.pptx
 
BITM3730 10-18.pptx
BITM3730 10-18.pptxBITM3730 10-18.pptx
BITM3730 10-18.pptx
 
Web Technology Part 4
Web Technology Part 4Web Technology Part 4
Web Technology Part 4
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
WT UNIT-2 XML.pdf
WT UNIT-2 XML.pdfWT UNIT-2 XML.pdf
WT UNIT-2 XML.pdf
 
XML
XMLXML
XML
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
BITM3730Week5.pptx
BITM3730Week5.pptxBITM3730Week5.pptx
BITM3730Week5.pptx
 
Xml iet 2015
Xml iet 2015Xml iet 2015
Xml iet 2015
 
XML
XMLXML
XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 
xml
xmlxml
xml
 
paper about xml
paper about xmlpaper about xml
paper about xml
 
Intro xml
Intro xmlIntro xml
Intro xml
 

More from Baskarkncet

More from Baskarkncet (19)

Unit_I.pptx
Unit_I.pptxUnit_I.pptx
Unit_I.pptx
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
 
Unit 1
Unit 1Unit 1
Unit 1
 
HCI
HCIHCI
HCI
 
03 x files
03 x files03 x files
03 x files
 
03 namespace
03 namespace03 namespace
03 namespace
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
11 deployment diagrams
11 deployment diagrams11 deployment diagrams
11 deployment diagrams
 
10 component diagram
10 component diagram10 component diagram
10 component diagram
 
09 package diagram
09 package diagram09 package diagram
09 package diagram
 
08 state diagram and activity diagram
08 state diagram and activity diagram08 state diagram and activity diagram
08 state diagram and activity diagram
 
07 interaction diagrams
07 interaction diagrams07 interaction diagrams
07 interaction diagrams
 
06 class diagrams
06 class diagrams06 class diagrams
06 class diagrams
 
05 use case
05 use case05 use case
05 use case
 
03 unified process
03 unified process03 unified process
03 unified process
 
02 uml
02 uml02 uml
02 uml
 
04 uml diagrams
04 uml diagrams04 uml diagrams
04 uml diagrams
 
01 introduction
01 introduction01 introduction
01 introduction
 

Recently uploaded

Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Risk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectRisk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectErbil Polytechnic University
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptbibisarnayak0
 
Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate productionChinnuNinan
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Ch10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfCh10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfChristianCDAM
 

Recently uploaded (20)

Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Risk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectRisk Management in Engineering Construction Project
Risk Management in Engineering Construction Project
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.ppt
 
Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate production
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Ch10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdfCh10-Global Supply Chain - Cadena de Suministro.pdf
Ch10-Global Supply Chain - Cadena de Suministro.pdf
 

02 well formed and valid documents

  • 1. UNIT I INTRODUCTION TO XML XML document structure – Well formed and valid documents – Namespaces – DTD – XML Schema – X-Files.
  • 2. Well formed and valid documents well-structured XML document can easily be transported b/w systems and devices
  • 3. Introduction • XML documents can be well formed, and they can also be valid. • Validity implies “well-formedness,” but not vice versa. • A valid XML document is a strict form of a well-formed XML document. • It’s like saying that a square is a rectangle, but not vice versa.
  • 4. Well-Formed Documents • An XML document is well formed – If it follows all syntax rules of XML. – If it does not includes inappropriate markup or characters that cannot be processed by XML parsers • An XML document can’t be partially well formed. • And, by definition, if a document is not well formed, it is not XML.
  • 5. Valid Documents • Property of “well-formedness” – A matter of making sure the XML document complies to syntactical rules • A well-formed XML document is considered valid only – If it contains a proper Document Type Declaration and – If the document obeys the constraints of that declaration • Constraints of the declaration will be expressed as – A DTD or – An XML Schema.
  • 6. Valid Vs Well-formed XML Document • Well-formed XML documents are designed for use without any constraints – Valid XML documents explicitly require these constraint mechanisms • Valid XML documents can take advantage of certain advanced features of XML – Those advanced features of XML are not available to merely well-formed documents due to their lack of a DTD or XML Schema. • Creation of well-formed XML is a simple process, – But the use of valid XML documents can greatly improve the quality of document processes
  • 7. Well Formed Document • Use our XML validator to syntax-check your XML. • An XML document with correct syntax is called "Well Formed". • Important Syntax rules : 1. XML documents must have a root element 2. XML elements must have a closing tag 3. XML tags are case sensitive 4. XML elements must be properly nested 5. XML attribute values must be quoted
  • 8. XML Errors Will Stop You • Errors in XML documents will stop your XML applications. • W3C XML specification states that – A program should stop processing an XML document if it finds an error. • The reason is that XML software should be small, fast, and compatible. • HTML browsers are allowed to display HTML documents with errors (like missing end tags). • With XML, errors are not allowed.
  • 9. Valid XML Documents • A "well formed" XML document is not the same as a "valid" XML document. • A "valid" XML document must be well formed. – In addition, it must conform to a document type definition. • Two different document type definitions that can be used with XML: 1. DTD (Original Document Type Definition) 2. XML Schema (An XML-based alternative to DTD) • A document type definition – Defines the rules and the legal elements and attributes for an XML document.
  • 10. Difference Between XML and HTML • XML is not a replacement for HTML. • XML and HTML were designed with different goals: – XML was designed to describe data, with focus on what data is – HTML was designed to display data, with focus on how data looks • HTML is about displaying information, – While XML is about carrying information.
  • 11. Use of XML • XML can be used to encode any structured information • XML is good at representing – Information that has an extensible, hierarchical format and requires encoding of metadata.
  • 12. XML Does Not DO Anything • <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> • XML document does not DO anything • It is just information wrapped in tags. – One must write a piece of s/w to send, receive or display it. It has Sender and receiver information, A heading and a message body.
  • 13. How Can XML be Used? • XML Separates Data from HTML • XML Simplifies Data Sharing • XML Simplifies Platform Changes • Internet Languages Written in XML
  • 14. XML Delimiter Characters • XML language has 4 special delimiters Character Meaning < Start of an XML markup tag > End of an XML markup tag & Start of an XML entity ; End of an XML entity
  • 15. XML Syntax Rules • All XML Elements Must Have a Closing Tag • XML Tags are Case Sensitive Example: <message>This is incorrect</Message> <message>This is correct</message> • XML Elements Must be Properly Nested • XML Documents Must Have a Root Element • XML Attribute Values Must be Quoted
  • 16. Empty XML Elements • An element with no content is said to be empty. • <element></element> OR • <element />
  • 17. XML Attributes • XML elements can have attributes, just like HTML. • Attributes provide additional information about an element. • Attributes often provide information that is not a part of the data. • XML Attribute value must be Quoted (single or double quotes) <person gender="female">
  • 18. XML Tree • XML documents form a tree structure – That starts at "the root" and branches to "the leaves". <?xml version="1.0" encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend! </body> </note> • First line is the XML declaration. It defines the XML version • Next line describes the root element of the document. <note> • Next 4 lines describe 4 child elements of root (to, from, heading, body) • Last line defines the end of the root element: </note>
  • 19. Example <bookstore>   <book category="CHILDREN">     <title>Harry Potter</title>     <author>J K. Rowling</author>     <year>2005</year>     <price>29.99</price>   </book>   <book category="WEB">     <title>Learning XML</title>     <author>Erik T. Ray</author>     <year>2003</year>     <price>39.95</price>   </book> </bookstore> <bookstore>   <book category="CHILDREN">     <title>Harry Potter</title>     <author>J K. Rowling</author>     <year>2005</year>     <price>29.99</price>   </book>   <book category="WEB">     <title>Learning XML</title>     <author>Erik T. Ray</author>     <year>2003</year>     <price>39.95</price>   </book> </bookstore> An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain: – other elements – text – attributes – or a mix of all of the above...
  • 20. XML Elements vs. Attributes <person gender="female"> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> <person> <gender>female</gender> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> • There are no rules about when to use attributes or when to use elements. • In XML best advice is to avoid them. Use elements instead.
  • 21. XML Elements are Extensible • XML elements can be extended to carry more information. <note> <to>Tove</to> <from>Jani</from> <body>Don't forget me this weekend!</body> </note> MESSAGE To: Tove From: Jani Don't forget me this weekend!
  • 22. Extended without breaking applications • Previous XML document added some extra information to it: <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Should the application break or crash? No.  Application should be able to find <to>, <from>, and <body> elements  in the XML document and produce the same output. One of the beauties of XML, is that it can be extended without breaking applications.
  • 23. Best way of using XML <note date="2008-01-10"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> A date attribute is used in the first example: <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> A date element is used in the second example:
  • 24. • An expanded date element is used in the third: <note> <date> <year>2008</year> <month>01</month> <day>10</day> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 25. Problems With Using Attributes 1. Attributes cannot contain multiple values (elements can) 2. Attributes cannot contain tree structures (elements can) 3. Attributes are not easily expandable (for future changes)
  • 26.
  • 27. XML Namespaces • XML Namespaces provide a method to avoid element name conflicts. • This XML carries HTML table information: • This XML carries information about a table (a piece of furniture): <table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table>
  • 28. Solving the Name Conflict Using a Prefix • If these XML fragments were added together, – There would be a name conflict. • Both contain a <table> element, – But the elements have different content and meaning. <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> In this example,  there will be no conflict  because the two <table>  elements have different  names.
  • 29. Document Type Definition (DTD) • An XML document with correct syntax is called "Well Formed". • An XML document validated against a DTD is both "Well Formed" and "Valid".
  • 30. Document Type Definition (DTD) • A DTD defines the structure and the legal elements and attributes of an XML document. • A DTD can be declared – Inside an XML document or – In an external file.
  • 31. Example of DTD inside an XML File <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>
  • 32. Building Blocks of XML Documents • Elements • Attributes • Entities • PCDATA • CDATA • Elements are the main building blocks of both XML and HTML documents. <body>some text</body> <message>some text</message>
  • 33. Attributes • Attributes provide extra information about elements. <image src ="computer.gif" /> • The name of the element is "img". • The name of the attribute is "src". • The value of the attribute is "computer.gif". • Since the element itself is empty it is closed by a " /".
  • 34. Entities • Some characters have a special meaning in XML, – Like, the less than sign (<) that defines the start of an XML tag. Entity References Character &lt; < &gt; > &amp; & &quot; " &apos; '
  • 35. PCDATA - Parsed Character DATA • PCDATA is text that WILL be parsed by a parser. • Text will be examined by the parser for entities and markup. CDATA - Character DATA. • CDATA means character data. • CDATA is text that will NOT be parsed by a parser. • Tags inside the text will NOT be treated as markup and entities will not be expanded.
  • 36. Declaring Elements • General form • Empty Elements <!ELEMENT element-name category> or <!ELEMENT element-name (element-content)> <!ELEMENT element-name EMPTY> Example: <!ELEMENT br EMPTY>
  • 37. Declaring Attributes Syntax: <!ATTLIST element-name attribute-name attribute-type attribute- value> DTD example: <!ATTLIST payment type CDATA "check"> XML example: <payment type="check" />
  • 38. Attribute Types The attribute-type can be one of the following: Type Description CDATA The value is character data (en1|en2|..) The value must be one from an enumerated list ID The value is a unique id IDREF The value is the id of another element IDREFS The value is a list of other ids NMTOKEN The value is a valid XML name NMTOKENS The value is a list of valid XML names ENTITY The value is an entity ENTITIES The value is a list of entities NOTATION The value is a name of a notation xml: The value is a predefined xml value
  • 39. The attribute-value can be one of the following: Value Explanation value The default value of the attribute #REQUIRED The attribute is required #IMPLIED The attribute is optional #FIXED value The attribute value is fixed
  • 40. DTD - Entities • Entities are used to define shortcuts to special characters. Syntax: <!ENTITY entity-name "entity-value"> DTD Example: <!ENTITY writer "Donald Duck."> <!ENTITY copyright "Copyright W3Schools."> XML example: <author>&writer;&copyright;</author>
  • 41. Why Use a DTD? • Your application can use a standard DTD – To verify that the data you receive from the outside world is valid. • You can also use a DTD to verify your own data.
  • 42. Example of DTD in an external DTD file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE note SYSTEM "Note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> "note.dtd" If the DTD is declared in an external file, the <!DOCTYPE> definition must contain a reference to the DTD file:
  • 43. Example : TV Schedule DTD <!DOCTYPE TVSCHEDULE [ <!ELEMENT TVSCHEDULE (CHANNEL+)> <!ELEMENT CHANNEL (BANNER,DAY+)> <!ELEMENT BANNER (#PCDATA)> <!ELEMENT DAY (DATE,(HOLIDAY|PROGRAMSLOT+)+)> <!ELEMENT HOLIDAY (#PCDATA)> <!ELEMENT DATE (#PCDATA)> <!ELEMENT PROGRAMSLOT (TIME,TITLE,DESCRIPTION?)> <!ELEMENT TIME (#PCDATA)> <!ELEMENT TITLE (#PCDATA)> <!ELEMENT DESCRIPTION (#PCDATA)> <!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED> <!ATTLIST CHANNEL CHAN CDATA #REQUIRED> <!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED> <!ATTLIST TITLE RATING CDATA #IMPLIED> <!ATTLIST TITLE LANGUAGE CDATA #IMPLIED> ]>
  • 44. Example : Newspaper Article DTD <!DOCTYPE NEWSPAPER [ <!ELEMENT NEWSPAPER (ARTICLE+)> <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)> <!ELEMENT HEADLINE (#PCDATA)> <!ELEMENT BYLINE (#PCDATA)> <!ELEMENT LEAD (#PCDATA)> <!ELEMENT BODY (#PCDATA)> <!ELEMENT NOTES (#PCDATA)> <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED> <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED> <!ATTLIST ARTICLE DATE CDATA #IMPLIED> <!ATTLIST ARTICLE EDITION CDATA #IMPLIED> <!ENTITY NEWSPAPER "Vervet Logic Times"> <!ENTITY PUBLISHER "Vervet Logic Press"> <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press"> ]>
  • 45. Newspaper Article DTD <!DOCTYPE NEWSPAPER [ <!ELEMENT NEWSPAPER (ARTICLE+)> <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)> <!ELEMENT HEADLINE (#PCDATA)> <!ELEMENT BYLINE (#PCDATA)> <!ELEMENT LEAD (#PCDATA)> <!ELEMENT BODY (#PCDATA)> <!ELEMENT NOTES (#PCDATA)> <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED> <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED> <!ATTLIST ARTICLE DATE CDATA #IMPLIED> <!ATTLIST ARTICLE EDITION CDATA #IMPLIED> <!ENTITY NEWSPAPER "Vervet Logic Times"> <!ENTITY PUBLISHER "Vervet Logic Press"> <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press"> ]>
  • 46. XML Schema Referred as XML Schema Definition (XSD) An XML Schema describes the structure of an XML document.
  • 47. What You Should Already Know • Before you continue, have a basic understanding of the following: – HTML – XML – A basic understanding of DTD
  • 48. What is an XML Schema? • An XML Schema – Describes the structure of an XML document, just like a DTD. • An XML document with correct syntax is called "Well Formed". • An XML document validated against an XML Schema is both "Well Formed" and "Valid".
  • 49. What XML Schema Defines? • 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
  • 50. Why Use XML Schemas? • XML Schemas Support Data Types • XML Schemas use XML Syntax • XML Schemas Secure Data Communication • XML Schemas are Extensible
  • 51. Why Use XML Schemas? • Well-Formed XML document is not Enough – 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.
  • 52. XSD - The <schema> Element General Form : <?xml version="1.0"?> <xs:schema> ... ... </xs:schema> The <schema> element may contain some attributes.
  • 53. Example A Simple XML Document called "note.xml": <?xml version="1.0"?> <note>   <to>Tove</to>   <from>Jani</from>   <heading>Reminder</heading>   <body>Don't forget me this weekend!</body> </note> DTD file called "note.dtd" That defines the elements of the above XML document <!ELEMENT note (to, from, heading, body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
  • 54. An XML Schema • An XML Schema file "note.xsd" – That defines the elements of the XML document above ("note.xml") <?xml version="1.0"?> <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"     targetNamespace = "http://www.w3schools.com" xmlns = "http://www.w3schools.com" elementFormDefault = "qualified"> <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> Other elements (to, from, heading, body) are simple types because they do not contain other elements. Note element is a complex type because it contains other elements.
  • 55. • xmlns:xs = http://www.w3.org/2001/XMLSchema – Indicates that the elements and data types used in the schema come from the "http://www.w3.org/2001/XMLSchema" namespace. • targetNamespace = http://www.w3schools.com – Indicates that the elements defined by this schema (note, to, from, heading, body) come from the "http://www.w3schools.com" namespace.
  • 56. • xmlns=http://www.w3schools.com – indicates that the default namespace is "http://www.w3schools.com". • elementFormDefault="qualified“ – indicates that any elements used by XML instance document which were declared in this schema must be namespace qualified.
  • 57. What is a Simple Element? • A simple element is an XML element that can contain only text – It cannot contain any other elements or attributes. • Text can be of many different types. – It can be one of the types included in XML Schema definition (boolean, string, date, etc.), or – It can be a custom type that you can define yourself. • Syntax for defining a simple element is: <xs:element name="xxx" type="yyy"/>
  • 58. Most Common Types • XML Schema has a lot of built-in data types. • Most common types are:  xs:string  xs:decimal  xs:integer  xs:boolean  xs:date (YYYY-MM-DD)  xs:time (HH:MM:SS)
  • 59. Default Values for Simple Elements • A fixed value is automatically assigned to the element, – You cannot specify another value. • In the following example the fixed value is "red": <xs:element name="color"      type="xs:string" fixed="red"/>
  • 60. Fixed Values for Simple Elements • A default value is automatically assigned to the element – When no other value is specified. • In the following example the default value is "red": <xs:element name="color"      type="xs:string" default="red"/>
  • 61. XSD Attributes • Simple elements cannot have attributes. • If an element has attributes, – It is considered to be of a complex type. • But the attribute itself is always declared as a simple type. <xs:attribute name="xxx" type="yyy"/> xxx is the name of the attribute yyy specifies the data type of the attribute.
  • 63. XML Document Structure • An XML document consists of a number of discrete components • Not all the sections of an XML document may be necessary, – But their inclusion helps to make for a well-structured XML document • A well-structured XML document can – Easily be transported between systems and devices
  • 64. Major portions of an XML document • The major portions of an XML document include the following: – The XML declaration – The Document Type Declaration (DTD) – The element data – The attribute data – The character data or XML content
  • 65. XML Declaration • XML Declaration is a definite way of stating exactly – What the document contains. • XML document can optionally have an XML declaration – It must be the first statement of the XML document • XML declaration is a processing instruction of the form <?xml ...?>
  • 66. Components of XML Declaration Component Meaning <?xml Starts the beginning of the processing instruction Version= “xxx” Describes the specific version of XML being used standalone= “xxx” Defines whether documents are allowed to contain external markup declarations encoding= “xxx” Indicates the character encoding that the document uses. The default is “US-ASCII” but can be set to any value Example :
  • 67. Document Type Declaration (DTD) • A DTD defines the structure and the legal elements and attributes of an XML document. • An application can use a DTD to verify that XML data is valid. • If the DTD is declared inside the XML file, it must be wrapped inside the <!DOCTYPE> definition: • Document Type Declaration (DOCTYPE) gives a name to the XML content • A Document Type Declaration (DOCTYPE) – Names the document type and – Identifies the internal content
  • 68.
  • 69. OOA • OOA emphasis on – Finding and describing the objects (or concepts in the problem domain) • OOD emphasis on – Defining software What the system does (its static structure and behavior), • OOD focuses on – How the system does it (it’s run-time implementation).
  • 70. OOA • During OOA, the most important purpose is – To identify objects and describing them in a proper way. • Objects should be identified with responsibilities. • Responsibilities are the functions performed by the object. – Each and every object has some type of responsibilities to be performed. • When these responsibilities are collaborated the purpose of the system is fulfilled.
  • 71. OOD • Second phase is OOD. During this phase – Emphasis is given upon the requirements and their fulfillment. • In this stage, – The objects are collaborated according to their intended association. • After the association is complete the design is also complete. • Third phase is object oriented implementation. – In this phase the design is implemented using object oriented languages like Java, C++ etc.
  • 72. UML • OO design is transformed into UML diagrams according to the requirement. • Input from the OO analysis and design is the input to the UML diagrams. • UML is a modeling language used to model s/w and non s/w systems. • Although UML is used for non software systems – Emphasis is on modeling object oriented software applications.
  • 73. Conceptual model of UML • A conceptual model can be defined as – A model which is made of concepts and their relationships • A conceptual model is the first step before drawing a UML diagram. • It helps to – Understand the entities in the real world and how they interact with each other. • Conceptual model of UML can be mastered by learning the 3 major elements: 1. UML building blocks 2. Rules to connect the building blocks 3. Common mechanisms of UML
  • 74. UML building blocks • Three building blocks of UML are: – Things – Relationships – Diagrams
  • 75.
  • 76. Object • Object is a term used to represent a real world entity within the system being modeled • Objects has its own attributes and operations (methods). – Consider the real world object “Car” make = ford model = escape year = 2002 color = green maximum speed = 130 mph current speed = 50 mph accelerate () decelerate () refuel ()
  • 77. Network • During the OOA phase object-modeling techniques are used • To reflect the structure and behaviour of the system – A range of models can be created using such objects