SlideShare a Scribd company logo
1 of 22
Integrative Programming andTechnology
08/12/2015 1Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
How does an XML processor check your xml document?
There are two main checks that XML processors make:
1. Checking that your document is well-formed ( Syntax rule)
2. Checking that it's valid (syntax-check your XML either in XML DTD or
XSD)
DTD- DocumentType Definition
XSD-XMLSchema Definition
Why need XMLValidator
 Use our XML validator to syntax-check your XML.
 Errors in XML documents will stop your XML applications unlike HTML
browser
08/12/2015 2Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 An XML document with correct syntax is called "Well Formed".
 An XML document validated against a DTD is "Well Formed" and "Valid".
 The purpose of a DTD is to define the structure of an XML document and
a list of legal elements.
How you add a DTD to our XML document
1. DTDs can be separate documents (or )
2. They can be built into an XML document
using a special element named <!DOCTYPE>.
08/12/2015 3Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
An XML Document with a DTD (example4.xml)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="css1.css"?>
<!DOCTYPE document
[ <!ELEMENT document (heading, message)> <!ELEMENT
heading (#PCDATA)> <!ELEMENT message (#PCDATA)>
]>
<document>
<heading> Hello From XML </heading> <message>This is an
XML document! </message>
</document>
08/12/2015 4Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Valid XML Document with DTD (example.5.xml)
 The DOCTYPE declaration is a reference to an external DTD file "Note.dtd“
<?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>
 Note.dtd
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
08/12/2015 5Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
The DTD above is interpreted like this:
 !DOCTYPE note defines that the root element of the document is note
 !ELEMENT note defines that the note element contains four elements:
"to, from, heading, body"
 !ELEMENT to defines the to element to be of type "#PCDATA"
 !ELEMENT from defines the from element to be of type "#PCDATA"
 !ELEMENT heading defines the heading element to be of type "#PCDATA"
 !ELEMENT body defines the body element to be of type "#PCDATA“
Note
#PCDATA means parse-able text data.
When NOT to Use a Document Definition?
 When you are working with small XML files, creating document definitions
may be a waste of time.
08/12/2015 6Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 Another way of validatingXML documents: using XML schemas.
 The XML Schema language is also referred to as XML Schema Definition
(XSD), describes the structure of an XML document.
 defines the legal building blocks (elements and attributes) of an XML
document like DTD.
 defines which elements are child elements
 defines the number and order 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
08/12/2015 7Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
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 and namespaces
Creating XML Schemas by Using XML Schema-CreationTools
 HiT Software
 xmlArchitect
 XMLspy
 XML Ray
 MicrosoftVisual Studio .NET
08/12/2015 8Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSD Simple Element
 The syntax for defining a simple element
 Default and FixedValues for Simple Elements
XSD Attributes
 The syntax for defining an attribute
 Default and FixedValues for Attributes
 Optional and Required Attributes
XSD Complex Elements
 How to Define a Complex Element using XML Scheme
 XSD Empty Elements
XSD Indicators
Order indicators are:
 All
 Choice
 Sequence
08/12/2015 9Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSD Simple Element
 A simple element is an XML element that can contain only text.
 It cannot contain any other elements or attributes.
 XML Schema has a lot of built-in data types.The most common types are:
1. xs:string
2. xs:decimal
3. xs:integer
4. xs:boolean
5. xs:date
6. xs:time
The syntax for defining a simple element is:
<xs:element name="xxx" type="yyy"/>
Example
<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>
08/12/2015 10Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Default and FixedValues for Simple Elements
Simple elements may have a default value or a fixed value specified.
1. A default value is automatically assigned to the element when no
other value is specified.
<xs:element name="color" type="xs:string" default="red"/>
2. A fixed value is also automatically assigned to the element, and
you cannot specify another value.
<xs:element name="color" type="xs:string" fixed="red"/>
08/12/2015 11Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
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.
The syntax for defining an attribute is:
<xs : attribute name="xxx" type="yyy"/>
Example
<lastname lang="EN">Smith</lastname>
<xs:attribute name="lang" type="xs:string"/>
Default and FixedValues for Attributes
Attributes may have a default value or a fixed value specified.
<xs:attribute name="lang" type="xs:string" default="EN"/>
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Optional and Required Attributes
Attributes are optional by default.To specify that the attribute is required, use
the "use" attribute:
<xs:attribute name="lang" type="xs:string" use="required"/>
08/12/2015 12Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSD Complex Elements
 A complex element is an XML element that contains other elements and/or attributes.
 There are four kinds of complex elements:
Example:
1. A complex XML element, "product", which is empty:
<product pid="1345"/>
2. A complex XML element, "employee", which contains only other elements:
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
3. A complex XML element, "food", which contains only text:
<food type="dessert">Ice cream</food>
4. A complex XML element, "description", which contains both elements and text:
<description>
It happened on <date lang=“EN">03.03.99</date>
</description>
08/12/2015 13Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
How to Define a Complex Element using XML Scheme
 Complex XML element, "employee", which contains only other elements:
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
 The "employee" element can be declared directly by naming the element:
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
 An empty complex element cannot have contents, only attributes.
<product prodid="1345" />
 It is possible to declare the "product" element more compactly:
<xs:element name="product">
<xs:complexType>
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
08/12/2015 14Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 XSD Indicators
 How elements are to be used in documents with indicators.
 Order indicators are used to define the order of the elements.They are:
1. All
2. Choice
3. Sequence
All Indicator:
 The <all> indicator specifies that the child elements can appear in any order, and that each child
element must occur only once:
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
08/12/2015 15Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Choice Indicator:
 The <choice> indicator specifies that either one child element or another can occur:
<xs:element name="person">
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>
Sequence Indicator:
 The <sequence> indicator specifies that the child elements mustappear in a specific order:
<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>
08/12/2015 16Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XML Example (“note.xml”)
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XSD Example (“note.xsd”)
<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>
08/12/2015 17Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Example (shiporder.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<shiporder orderid="889923">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
</shiporder>
08/12/2015 18Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Example "shiporder.xsd":
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
08/12/2015 19Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 All modern browsers have a built-in XML parser.
 An XML parser converts an XML document into an XML DOM object -
which can then be manipulated with JavaScript.
Parse an XML Document
 The following code fragment parses an XML document into an XML DOM
object:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
08/12/2015 20Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XML DOM
 The XML DOM defines a standard way for accessing and manipulating
XML documents.
 The XML DOM views an XML document as a tree-structure.
 All elements can be accessed through the DOM tree.
 Their content (text and attributes) can be modified or deleted, and
new elements can be created.
 The elements, their text, and their attributes are all known as nodes.
The HTML DOM
 The HTML DOM defines a standard way for accessing and manipulating
HTML documents.
 All HTML elements can be accessed through the HTML DOM.
08/12/2015 21Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Load an XML File - Cross-browser
 parses an XML document ("note.xml") into an XML DOM object and then extracts some information from it with a JavaScript:
Example
<html>
<body>
<span id="to"></span>
<span id="from"></span>
<span id="message"></span>
<script>
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("to").innerHTML= xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML= xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML= xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
08/12/2015 22Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia

More Related Content

What's hot

Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01
Jotham Gadot
 
4 internet programming
4 internet programming4 internet programming
4 internet programming
soner_kavlak
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
Chaffey College
 

What's hot (20)

Xml presentation
Xml presentationXml presentation
Xml presentation
 
XML-Extensible Markup Language
XML-Extensible Markup Language XML-Extensible Markup Language
XML-Extensible Markup Language
 
Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and Design
 
02 well formed and valid documents
02 well formed and valid documents02 well formed and valid documents
02 well formed and valid documents
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Webservices
WebservicesWebservices
Webservices
 
Database, Lecture-1.ppt
Database, Lecture-1.pptDatabase, Lecture-1.ppt
Database, Lecture-1.ppt
 
4 internet programming
4 internet programming4 internet programming
4 internet programming
 
XML
XMLXML
XML
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Sgml
SgmlSgml
Sgml
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 

Similar to IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya

Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
Sudharsan S
 

Similar to IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya (20)

Xml schema
Xml schemaXml schema
Xml schema
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
XML Schema.pdf
XML Schema.pdfXML Schema.pdf
XML Schema.pdf
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
Xml11
Xml11Xml11
Xml11
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
 
Xml
XmlXml
Xml
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
XML notes.pptx
XML notes.pptxXML notes.pptx
XML notes.pptx
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
 
XML.ppt
XML.pptXML.ppt
XML.ppt
 
Xml viva questions
Xml viva questionsXml viva questions
Xml viva questions
 
Xml
XmlXml
Xml
 
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5   XMLM.FLORENCE DAYANA WEB DESIGN -Unit 5   XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
 
Xml 1
Xml 1Xml 1
Xml 1
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 

More from VijiPriya Jeyamani

More from VijiPriya Jeyamani (10)

Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
 
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
 
Dr. J. VijiPriya Information and Communication Technology Chapter 5,6
Dr. J. VijiPriya  Information and Communication Technology Chapter 5,6Dr. J. VijiPriya  Information and Communication Technology Chapter 5,6
Dr. J. VijiPriya Information and Communication Technology Chapter 5,6
 
Human Computer Interaction Chapter 2 Interaction and Interaction Design Basi...
Human Computer Interaction Chapter 2  Interaction and Interaction Design Basi...Human Computer Interaction Chapter 2  Interaction and Interaction Design Basi...
Human Computer Interaction Chapter 2 Interaction and Interaction Design Basi...
 
Human Computer Interaction Chapter 3 HCI in the Software Process and Design ...
Human Computer Interaction Chapter 3 HCI in the Software Process and  Design ...Human Computer Interaction Chapter 3 HCI in the Software Process and  Design ...
Human Computer Interaction Chapter 3 HCI in the Software Process and Design ...
 
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
 
Human Computer Interaction Chapter 5 Universal Design and User Support - Dr....
Human Computer Interaction Chapter 5 Universal Design and User Support -  Dr....Human Computer Interaction Chapter 5 Universal Design and User Support -  Dr....
Human Computer Interaction Chapter 5 Universal Design and User Support - Dr....
 
Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
 Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
 
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriyaInformation and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
 

Recently uploaded

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
hublikarsn
 

Recently uploaded (20)

PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 

IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya

  • 1. Integrative Programming andTechnology 08/12/2015 1Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 2. How does an XML processor check your xml document? There are two main checks that XML processors make: 1. Checking that your document is well-formed ( Syntax rule) 2. Checking that it's valid (syntax-check your XML either in XML DTD or XSD) DTD- DocumentType Definition XSD-XMLSchema Definition Why need XMLValidator  Use our XML validator to syntax-check your XML.  Errors in XML documents will stop your XML applications unlike HTML browser 08/12/2015 2Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 3.  An XML document with correct syntax is called "Well Formed".  An XML document validated against a DTD is "Well Formed" and "Valid".  The purpose of a DTD is to define the structure of an XML document and a list of legal elements. How you add a DTD to our XML document 1. DTDs can be separate documents (or ) 2. They can be built into an XML document using a special element named <!DOCTYPE>. 08/12/2015 3Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 4. An XML Document with a DTD (example4.xml) <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/css" href="css1.css"?> <!DOCTYPE document [ <!ELEMENT document (heading, message)> <!ELEMENT heading (#PCDATA)> <!ELEMENT message (#PCDATA)> ]> <document> <heading> Hello From XML </heading> <message>This is an XML document! </message> </document> 08/12/2015 4Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 5. Valid XML Document with DTD (example.5.xml)  The DOCTYPE declaration is a reference to an external DTD file "Note.dtd“ <?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>  Note.dtd <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> 08/12/2015 5Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 6. The DTD above is interpreted like this:  !DOCTYPE note defines that the root element of the document is note  !ELEMENT note defines that the note element contains four elements: "to, from, heading, body"  !ELEMENT to defines the to element to be of type "#PCDATA"  !ELEMENT from defines the from element to be of type "#PCDATA"  !ELEMENT heading defines the heading element to be of type "#PCDATA"  !ELEMENT body defines the body element to be of type "#PCDATA“ Note #PCDATA means parse-able text data. When NOT to Use a Document Definition?  When you are working with small XML files, creating document definitions may be a waste of time. 08/12/2015 6Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 7.  Another way of validatingXML documents: using XML schemas.  The XML Schema language is also referred to as XML Schema Definition (XSD), describes the structure of an XML document.  defines the legal building blocks (elements and attributes) of an XML document like DTD.  defines which elements are child elements  defines the number and order 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 08/12/2015 7Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 8. 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 and namespaces Creating XML Schemas by Using XML Schema-CreationTools  HiT Software  xmlArchitect  XMLspy  XML Ray  MicrosoftVisual Studio .NET 08/12/2015 8Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 9. XSD Simple Element  The syntax for defining a simple element  Default and FixedValues for Simple Elements XSD Attributes  The syntax for defining an attribute  Default and FixedValues for Attributes  Optional and Required Attributes XSD Complex Elements  How to Define a Complex Element using XML Scheme  XSD Empty Elements XSD Indicators Order indicators are:  All  Choice  Sequence 08/12/2015 9Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 10. XSD Simple Element  A simple element is an XML element that can contain only text.  It cannot contain any other elements or attributes.  XML Schema has a lot of built-in data types.The most common types are: 1. xs:string 2. xs:decimal 3. xs:integer 4. xs:boolean 5. xs:date 6. xs:time The syntax for defining a simple element is: <xs:element name="xxx" type="yyy"/> Example <lastname>Refsnes</lastname> <age>36</age> <dateborn>1970-03-27</dateborn> <xs:element name="lastname" type="xs:string"/> <xs:element name="age" type="xs:integer"/> <xs:element name="dateborn" type="xs:date"/> 08/12/2015 10Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 11. Default and FixedValues for Simple Elements Simple elements may have a default value or a fixed value specified. 1. A default value is automatically assigned to the element when no other value is specified. <xs:element name="color" type="xs:string" default="red"/> 2. A fixed value is also automatically assigned to the element, and you cannot specify another value. <xs:element name="color" type="xs:string" fixed="red"/> 08/12/2015 11Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 12. 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. The syntax for defining an attribute is: <xs : attribute name="xxx" type="yyy"/> Example <lastname lang="EN">Smith</lastname> <xs:attribute name="lang" type="xs:string"/> Default and FixedValues for Attributes Attributes may have a default value or a fixed value specified. <xs:attribute name="lang" type="xs:string" default="EN"/> <xs:attribute name="lang" type="xs:string" fixed="EN"/> Optional and Required Attributes Attributes are optional by default.To specify that the attribute is required, use the "use" attribute: <xs:attribute name="lang" type="xs:string" use="required"/> 08/12/2015 12Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 13. XSD Complex Elements  A complex element is an XML element that contains other elements and/or attributes.  There are four kinds of complex elements: Example: 1. A complex XML element, "product", which is empty: <product pid="1345"/> 2. A complex XML element, "employee", which contains only other elements: <employee> <firstname>John</firstname> <lastname>Smith</lastname> </employee> 3. A complex XML element, "food", which contains only text: <food type="dessert">Ice cream</food> 4. A complex XML element, "description", which contains both elements and text: <description> It happened on <date lang=“EN">03.03.99</date> </description> 08/12/2015 13Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 14. How to Define a Complex Element using XML Scheme  Complex XML element, "employee", which contains only other elements: <employee> <firstname>John</firstname> <lastname>Smith</lastname> </employee>  The "employee" element can be declared directly by naming the element: <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>  An empty complex element cannot have contents, only attributes. <product prodid="1345" />  It is possible to declare the "product" element more compactly: <xs:element name="product"> <xs:complexType> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:complexType> </xs:element> 08/12/2015 14Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 15.  XSD Indicators  How elements are to be used in documents with indicators.  Order indicators are used to define the order of the elements.They are: 1. All 2. Choice 3. Sequence All Indicator:  The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once: <xs:element name="person"> <xs:complexType> <xs:all> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:all> </xs:complexType> </xs:element> 08/12/2015 15Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 16. Choice Indicator:  The <choice> indicator specifies that either one child element or another can occur: <xs:element name="person"> <xs:complexType> <xs:choice> <xs:element name="employee" type="employee"/> <xs:element name="member" type="member"/> </xs:choice> </xs:complexType> </xs:element> Sequence Indicator:  The <sequence> indicator specifies that the child elements mustappear in a specific order: <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> 08/12/2015 16Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 17. XML Example (“note.xml”) <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> XSD Example (“note.xsd”) <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> 08/12/2015 17Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 18. Example (shiporder.xml): <?xml version="1.0" encoding="ISO-8859-1"?> <shiporder orderid="889923"> <orderperson>John Smith</orderperson> <shipto> <name>Ola Nordmann</name> <address>Langgt 23</address> <city>4000 Stavanger</city> <country>Norway</country> </shipto> </shiporder> 08/12/2015 18Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 19. Example "shiporder.xsd": <?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="shiporder"> <xs:complexType> <xs:sequence> <xs:element name="orderperson" type="xs:string"/> <xs:element name="shipto"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="orderid" type="xs:string" use="required"/> </xs:complexType> </xs:element> </xs:schema> 08/12/2015 19Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 20.  All modern browsers have a built-in XML parser.  An XML parser converts an XML document into an XML DOM object - which can then be manipulated with JavaScript. Parse an XML Document  The following code fragment parses an XML document into an XML DOM object: if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","books.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; 08/12/2015 20Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 21. XML DOM  The XML DOM defines a standard way for accessing and manipulating XML documents.  The XML DOM views an XML document as a tree-structure.  All elements can be accessed through the DOM tree.  Their content (text and attributes) can be modified or deleted, and new elements can be created.  The elements, their text, and their attributes are all known as nodes. The HTML DOM  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  All HTML elements can be accessed through the HTML DOM. 08/12/2015 21Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 22. Load an XML File - Cross-browser  parses an XML document ("note.xml") into an XML DOM object and then extracts some information from it with a JavaScript: Example <html> <body> <span id="to"></span> <span id="from"></span> <span id="message"></span> <script> if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","note.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("to").innerHTML= xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML= xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTML= xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue; </script> </body> </html> 08/12/2015 22Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia