SlideShare a Scribd company logo
1 of 40
Download to read offline
1 © 2001-2003 Marty Hall, Larry Brown http://www.corewebprogramming.com
core
programming
Introduction to XML
XML2 www.corewebprogramming.com
Agenda
• XML overview
• XML components
• Document Type Definition
• Specifying data elements (tags)
• Defining attributes and entities
• A look at XML schema
XML3 www.corewebprogramming.com
XML Overview
• When people refer to XML, they typically are
referring to XML and related technologies
HTML
DOM
JDOM
W3C
SGMLXSLT
XQL
XML
SAX
XML4 www.corewebprogramming.com
XML Resources
• XML 1.0 Specification
– http://www.w3.org/TR/REC-xml
• WWW consortium’s Home Page on XML
– http://www.w3.org/XML/
• Sun Page on XML and Java
– http://java.sun.com/xml/
• Apache XML Project
– http://xml.apache.org/
• XML Resource Collection
– http://xml.coverpages.org/
• O’Reilly XML Resource Center
– http://www.xml.com/
XML5 www.corewebprogramming.com
XML Overview
• EXtensible Markup Language (XML) is a
meta-language that describes the content of
the document (self-describing data)
• XML does not specify the tag set or
grammar of the language
– Tag Set – markup tags that have meaning to a language
processor
– Grammar – defines correct usage of a language’s tag
Java = Portable Programs
XML = Portable Data
XML6 www.corewebprogramming.com
Applications of XML
• Configuration files
– Used extensively in J2EE architectures
• Media for data interchange
– A better alternative to proprietary data formats
• B2B transactions on the Web
– Electronic business orders (ebXML)
– Financial Exchange (IFX)
– Messaging exchange (SOAP)
XML7 www.corewebprogramming.com
XML versus HTML
• XML fundamentally separates content (data
and language) from presentation; HTML
specifies the presentation
• HTML explicitly defines a set of legal tags as
well as the grammar (intended meaning)
<TABLE> … </TABLE>
• XML allows any tags or grammar to be used
(hence, eXtensible)
<BOOK> … </BOOK>
– Note: Both are based on Standard Generalized Markup
Language (SGML)
XML8 www.corewebprogramming.com
Simple XML Example
<?xml version="1.0"?>
<authors>
<name>
<firstname>Larry</firstname>
<lastname>Brown</lastname>
</name>
<name>
<firstname>Marty</firstname>
<lastname>Hall</lastname>
</name>
...
</authors>
XML9 www.corewebprogramming.com
XML Components
• Prolog
– Defines the xml version, entity definitions, and
DOCTYPE
• Components of the document
– Tags and attributes
– CDATA (character data)
– Entities
– Processing instructions
– Comments
XML10 www.corewebprogramming.com
XML Prolog
• XML Files always start with a prolog
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
– The version of XML is required
– The encoding identifies character set (default UTF-8)
– The value standalone identifies if an external document is
referenced for DTD or entity definition
– Note: the prolog can contain entities and DTD definitions
XML11 www.corewebprogramming.com
Prolog Example
<?xml version="1.0" standalone="yes"?>
<DOCTYPE authors [
<!ELEMENT authors (name)*>
<!ELEMENT name (firstname, lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
]>
<authors>
<name>
<firstname>James</firstname>
<lastname>Gosling</lastname>
</name>
...
</authors>
XML12 www.corewebprogramming.com
XML DOCTYPE
• Document Type Declarations
– Specifies the location of the DTD defining the syntax and
structure of elements in the document
– Common forms:
<!DOCTYPE root [DTD]>
<!DOCTYPE root SYSTEM URL>
<!DOCTYPE root PUBLIC FPI-identifier URL>
– The root identifies the starting element (root element) of
the document
– The DTD can be external to the XML document, referenced
by a SYSTEM or PUBLIC URL
• SYSTEM URL refers to a private DTD
– Located on the local file system or HTTP server
• PUBLIC URL refers to a DTD intended for public use
XML13 www.corewebprogramming.com
DOCTYPE Examples
<!DOCTYPE book "DTDs/CWP.dtd">
<!DOCTYPE book SYSTEM
"http://www.corewebprogramming.com/DTDs/CWP.dtd">
DTD located in subdirectory
below XML document
DTD located HTTP server:
www.corewebprogramming.com
Book must be the root element
of the XML document
XML14 www.corewebprogramming.com
XML DOCTYPE, cont.
• Specifying a PUBLIC DTD
<!DOCTYPE root PUBLIC FPI-identifier URL>
– The Formal Public Identifier (FPI) has four parts:
1. Connection of DTD to a formal standard
- if defining yourself
+ nonstandards body has approved the DTD
ISO if approved by formal standards committee
2. Group responsible for the DTD
3. Description and type of document
4. Language used in the DTD
XML15 www.corewebprogramming.com
PUBLIC DOCTYPE Examples
<!DOCTYPE Book
PUBLIC "-//W3C//DTD XHMTL 1.0 Transistional//EN"
"http://www.w3.org/TR?xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCYTPE CWP
PUBLIC "-//Prentice Hall//DTD Core Series 1.0//EN"
"http://www.prenticehall.com/DTD/Core.dtd">
XML16 www.corewebprogramming.com
XML Comments
• Comments are the same as HTML
comments
<!-- This is an XML and HTML comment -->
XML17 www.corewebprogramming.com
Processing Instructions
• Application-specific instruction to the XML
processor
<?processor-instruction?>
• Example
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xml" href="orders.xsl" ?>
<orders>
<order>
<count>37</count>
<price>49.99</price>
<book>
<isbn>0130897930</isbn>
<title>Core Web Programming Second Edition</title>
<authors>
<author>Marty Hall</author>
<author>Larry Brown</author>
</authors>
</book>
</order>
</orders>
XML18 www.corewebprogramming.com
XML Root Element
• Required for XML-aware applications to
recognize beginning and end of document
• Example
<?xml version="1.0" ?>
<book>
<title>Core Web Programming</title>
<contents>
<chapter number="1">
Designing Web Pages with HTML
</chapter>
<chapter number="2">
Block-level Elements in HTML 4.0
</chapter>
<chapter number="3">
Text-level Elements in HTML 4.0
</chapter>
...
</contents>
</book>
XML19 www.corewebprogramming.com
XML Tags
• Tag names:
– Case sensitive
– Start with a letter or underscore
– After first character, numbers, - and . are allowed
– Cannot contain whitespaces
– Avoid use of colon expect for indicating
namespaces
• For a well-formed XML documents
– Every tag must have an end tag
<elementOne> … </elementOne>
<elementTwo />
– All tags are completely nested (tag order cannot be
mixed)
XML20 www.corewebprogramming.com
XML Tags, cont.
• Tags can also have attributes
<message to="Gates@microsoft.com" from="Gosling@sun.com">
<priority/>
<text>We put the . in .com.
What did you do?
</text>
</message>
XML21 www.corewebprogramming.com
XML Attributes
• Element Attributes
– Attributes provide metadata for the element
– Every attribute must be enclosed in "" with no commas in
between
– Same naming conventions as elements
XML22 www.corewebprogramming.com
Document Entities
• Entities refer to a data item, typically text
– General entity references start with & and end with ;
– The entity reference is replaced by it’s true value when
parsed
– The characters < > & ' " require entity references to
avoid conflicts with the XML application (parser)
&lt; &gt; &amp; &quot; &apos;
• Entities are user definable
<?xml version="1.0" standalone="yes" ?>
<!DOCTYPE book [
<!ELEMENT book (title)>
<!ELEMENT title (#PCDATA)>
<!ENTITY COPYRIGHT "2001, Prentice Hall">
]>
<book>
<title>Core Web Programming, &COPYRIGHT;</title>
</book>
XML23 www.corewebprogramming.com
Document Entities (Aside)
• CDATA (character data) is not parsed
<?xml version="1.0" encoding="ISO-8859-1"?>
<server>
<port status="accept">
<![CDATA[8001 <= port < 9000]]>
</port>
</server>
XML24 www.corewebprogramming.com
Well-Formed versus Valid
• An XML document can be well-formed if it
follows basic syntax rules
• An XML document is valid if its structure
matches a Document Type Definition (DTD)
XML25 www.corewebprogramming.com
Document Type Definition
(DTD)
• Defines Structure of the Document
– Allowable tags and their attributes
– Attribute values constraints
– Nesting of tags
– Number of occurrences for tags
– Entity definitions
XML26 www.corewebprogramming.com
DTD Example
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!ELEMENT perennials (daylily)*>
<!ELEMENT daylily (cultivar, award*, bloom, cost)+>
<!ATTLIST daylily
status (in-stock | limited | sold-out) #REQUIRED>
<!ELEMENT cultivar (#PCDATA)>
<!ELEMENT award (name, year)>
<!ELEMENT name (#PCDATA)>
<!ATTLIST name note CDATA #IMPLIED>
<!ELEMENT year (#PCDATA)>
<!ELEMENT bloom (#PCDATA)>
<!ATTLIST bloom code (E | EM | M | ML | L | E-L) #REQUIRED>
<!ELEMENT cost (#PCDATA)>
<!ATTLIST cost discount CDATA #IMPLIED>
<!ATTLIST cost currency (US | UK | CAN) "US">
XML27 www.corewebprogramming.com
Defining Elements
• <!ELEMENT name definition/type>
<!ELEMENT daylily (cultivar, award*, bloom, cost)+>
<!ELEMENT cultivar (#PCDATA)>
<!ELEMENT id (#PCDATA | catalog_id)>
• Types
– ANY Any well-formed XML data
– EMPTY Element cannot contain any text or child elements
– PCDATA Character data only (should not contain markup)
– elements List of legal child elements (no character data)
– mixed May contain character data and/or child elements
(cannot constrain order and number of child elements)
XML28 www.corewebprogramming.com
Defining Elements, cont.
• Cardinality
– [none] Default (one and only one instance)
– ? 0, 1
– * 0, 1, …, N
– + 1, 2, …, N
• List Operators
– , Sequence (in order)
– | Choice (one of several)
XML29 www.corewebprogramming.com
Grouping Elements
• Set of elements can be grouped within
parentheses
– (Elem1?, Elem2?)+
• Elem1 can occur 0 or 1 times followed by 0 or 1 occurrences of
Elem2
• The group (sequence) must occur 1 or more times
• OR
– ((Elem1, Elem2) | Elem3)*
• Either the group of Elem1, Elem2 is present (in order) or Elem3
is present, 0 or more times
XML30 www.corewebprogramming.com
Element Example
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE Person [
<!ELEMENT Person ( (Mr|Ms|Miss)?, FirstName,
MiddleName*, LastName, (Jr|Sr)? )>
<!ELEMENT FirstName (#PCDATA)>
<!ELEMENT MiddleName (#PCDATA)>
<!ELEMENT LastName (#PCDATA)>
<!ELEMENT Mr EMPTY>
<!ELEMENT Ms EMPTY>
...
<!ELEMENT Sr EMPTY>
]>
<Person>
<Mr/>
<FirstName>Lawrence</FirstName>
<LastName>Brown</LastName>
</Person>
XML31 www.corewebprogramming.com
Defining Attributes
• <!ATTLIST element attrName type modifier>
• Examples
<!ELEMENT Customer (#PCDATA )>
<!ATTLIST Customer id CDATA #IMPLIED>
<!ELEMENT Product (#PCDATA )>
<!ATTLIST Product
cost CDATA #FIXED "200"
id CDATA #REQUIRED>
XML32 www.corewebprogramming.com
Attribute Types
• CDATA
– Essentially anything; simply unparsed data
<!ATTLIST Customer id CDATA #IMPLIED>
• Enumeration
– attribute (value1|value2|value3) [Modifier]
• Eight other attribute types
– ID, IDREF, NMTOKEN, NMTOKENS, ENTITY,
ENTITIES, NOTATION
XML33 www.corewebprogramming.com
Attribute Modifiers
• #IMPLIED
– Attribute is not required
<!ATTLIST cost discount CDATA #IMPLIED>
• #REQUIRED
– Attribute must be present
<!ATTLIST account balance CDATA #REQUIRED>
• #FIXED "value"
– Attribute is present and always has this value
<!ATTLIST interpreter language CDATA #FIXED "EN">
• Default value (applies to enumeration)
<!ATTLIST car color (red | white | blue) "white" )
XML34 www.corewebprogramming.com
Defining Entities
• <!ENTITY name "replacement">
<!ENTITY &amp; "&">
<!ENTITY copyright "Copyright 2001">
XML35 www.corewebprogramming.com
Limitations of DTDs
• DTD itself is not in XML format – more work
for parsers
• Does not express data types (weak data
typing)
• No namespace support
• Document can override external DTD
definitions
• No DOM support
• XML Schema is intended to resolve these
issues but … DTDs are going to be around
for a while
XML36 www.corewebprogramming.com
XML Schema
• W3C recommendation released May 2001
– http://www.w3.org/TR/xmlschema-0/
– http://www.w3.org/TR/xmlschema-1/
– http://www.w3.org/TR/xmlschema-2/
– Depends on following specifications
• XML-Infoset, XML-Namespaces, XPath
• Benefits:
– Standard and user-defined data types
– Express data types as patterns
– Higher degree of type checking
– Better control of occurrences
• Clearly the future … but limited support
XML37 www.corewebprogramming.com
XML Schema, Example
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="perennials" type="PerennialType"/>
<xsd:complexType name="PerennialType" >
<xsd:element name=daylily" type="DaylilyType"
maxOccurs="unbounded"/>
</xsd:complexType>
<xsd:complexType name="DaylilyType" >
<xsd:sequence>
<xsd:element name="cultivar" type="xsd:string"/>
<xsd:element name="award" type="AwardType“
maxOccurs="unbounded"/>
<xsd:element name="bloom" type="xsd:string"/>
<xsd:element name="cost" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="status" type="StatusType“
use="required"/>
</xsd:complexType>
XML38 www.corewebprogramming.com
XML Schema, Example, cont.
<xsd:simpleType name="StatusType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="in-stock"/>
<xsd:enumeration value="limited"/>
<xsd:enumeration value="sold-out"/>
</xsd:restriction>
</xsd:simpleType>
...
</xsd:schema>
XML39 www.corewebprogramming.com
Summary
• XML is a self-describing meta data
• DOCTYPE defines the root element and
location of DTD
• Document Type Definition (DTD) defines the
grammar of the document
– Required to validate the document
– Constrains grouping and cardinality of elements
• DTD processing is expensive
• Schema uses XML to specify the grammar
– More complex to express but easier to process
40 © 2001-2003 Marty Hall, Larry Brown http://www.corewebprogramming.com
core
programming
Questions?

More Related Content

What's hot (20)

03 x files
03 x files03 x files
03 x files
 
XML Technologies
XML TechnologiesXML Technologies
XML Technologies
 
XML
XMLXML
XML
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTD
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Xml
XmlXml
Xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
fundamentals of XML
fundamentals of XMLfundamentals of XML
fundamentals of XML
 
DTD
DTDDTD
DTD
 
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XMLFergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml
Xml Xml
Xml
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
XML for beginners
XML for beginnersXML for beginners
XML for beginners
 
DTD
DTDDTD
DTD
 
XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
 
Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 

Viewers also liked

Pre-Cal 30S December 18, 2008
Pre-Cal 30S December 18, 2008Pre-Cal 30S December 18, 2008
Pre-Cal 30S December 18, 2008Darren Kuropatwa
 
Goma De Mascar
Goma De MascarGoma De Mascar
Goma De MascarCaro Lina
 
21502 Vic For Learners
21502 Vic For Learners21502 Vic For Learners
21502 Vic For LearnersHilda Cove
 
Sangrado digestivo alto no varicial
Sangrado digestivo alto no varicialSangrado digestivo alto no varicial
Sangrado digestivo alto no varicialLuis Fernando
 
How the law protects investment in technology - trade secrets, patents, desig...
How the law protects investment in technology - trade secrets, patents, desig...How the law protects investment in technology - trade secrets, patents, desig...
How the law protects investment in technology - trade secrets, patents, desig...Jane Lambert
 
Linfocitos Th1 Y Th2
Linfocitos Th1 Y Th2Linfocitos Th1 Y Th2
Linfocitos Th1 Y Th2Luis Fernando
 
What is Good Mentoring?
What is Good Mentoring?What is Good Mentoring?
What is Good Mentoring?Sramana Mitra
 
PTH Solutions Inc. Company Synopsis 2011
PTH Solutions Inc.  Company Synopsis 2011PTH Solutions Inc.  Company Synopsis 2011
PTH Solutions Inc. Company Synopsis 2011Peter Pham
 
Leah Eustace AFP Toronto Congress 2008 Compressed
Leah Eustace AFP Toronto Congress 2008 CompressedLeah Eustace AFP Toronto Congress 2008 Compressed
Leah Eustace AFP Toronto Congress 2008 CompressedGood Works
 
Hill Claims Services Presentation Linkedin Ppt
Hill Claims Services Presentation Linkedin PptHill Claims Services Presentation Linkedin Ppt
Hill Claims Services Presentation Linkedin Pptkenbaker
 
Waiting for Medicare’s Second Stage
Waiting for Medicare’s Second StageWaiting for Medicare’s Second Stage
Waiting for Medicare’s Second StageOmar Ha-Redeye
 
Mandating Open Access - Wellcome Trust
Mandating Open Access - Wellcome TrustMandating Open Access - Wellcome Trust
Mandating Open Access - Wellcome TrustWellcome Library
 
Largestship
LargestshipLargestship
LargestshipMihaela
 
Shall I run away?
Shall I run away?Shall I run away?
Shall I run away?Gabor Szabo
 

Viewers also liked (20)

Pre-Cal 30S December 18, 2008
Pre-Cal 30S December 18, 2008Pre-Cal 30S December 18, 2008
Pre-Cal 30S December 18, 2008
 
Goma De Mascar
Goma De MascarGoma De Mascar
Goma De Mascar
 
21502 Vic For Learners
21502 Vic For Learners21502 Vic For Learners
21502 Vic For Learners
 
Sangrado digestivo alto no varicial
Sangrado digestivo alto no varicialSangrado digestivo alto no varicial
Sangrado digestivo alto no varicial
 
How the law protects investment in technology - trade secrets, patents, desig...
How the law protects investment in technology - trade secrets, patents, desig...How the law protects investment in technology - trade secrets, patents, desig...
How the law protects investment in technology - trade secrets, patents, desig...
 
Linfocitos Th1 Y Th2
Linfocitos Th1 Y Th2Linfocitos Th1 Y Th2
Linfocitos Th1 Y Th2
 
Pae hemorragia digestiva alta
Pae hemorragia digestiva altaPae hemorragia digestiva alta
Pae hemorragia digestiva alta
 
What is Good Mentoring?
What is Good Mentoring?What is Good Mentoring?
What is Good Mentoring?
 
Chapter2
Chapter2Chapter2
Chapter2
 
Um par de_sapato_velho
Um par de_sapato_velhoUm par de_sapato_velho
Um par de_sapato_velho
 
PTH Solutions Inc. Company Synopsis 2011
PTH Solutions Inc.  Company Synopsis 2011PTH Solutions Inc.  Company Synopsis 2011
PTH Solutions Inc. Company Synopsis 2011
 
Unit 4
Unit 4Unit 4
Unit 4
 
Leah Eustace AFP Toronto Congress 2008 Compressed
Leah Eustace AFP Toronto Congress 2008 CompressedLeah Eustace AFP Toronto Congress 2008 Compressed
Leah Eustace AFP Toronto Congress 2008 Compressed
 
Hill Claims Services Presentation Linkedin Ppt
Hill Claims Services Presentation Linkedin PptHill Claims Services Presentation Linkedin Ppt
Hill Claims Services Presentation Linkedin Ppt
 
Unit 3
Unit 3Unit 3
Unit 3
 
Waiting for Medicare’s Second Stage
Waiting for Medicare’s Second StageWaiting for Medicare’s Second Stage
Waiting for Medicare’s Second Stage
 
Mandating Open Access - Wellcome Trust
Mandating Open Access - Wellcome TrustMandating Open Access - Wellcome Trust
Mandating Open Access - Wellcome Trust
 
Largestship
LargestshipLargestship
Largestship
 
Shall I run away?
Shall I run away?Shall I run away?
Shall I run away?
 
Négy Gyertya
Négy GyertyaNégy Gyertya
Négy Gyertya
 

Similar to 23xml (20)

Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
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
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
XML
XMLXML
XML
 
XML notes.pptx
XML notes.pptxXML notes.pptx
XML notes.pptx
 
Xml
XmlXml
Xml
 
Data interchange integration, HTML XML Biological XML DTD
Data interchange integration, HTML XML Biological XML DTDData interchange integration, HTML XML Biological XML DTD
Data interchange integration, HTML XML Biological XML DTD
 
XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
 
Xml 1
Xml 1Xml 1
Xml 1
 
XHTML
XHTMLXHTML
XHTML
 
Jdom how it works & how it opened the java process
Jdom how it works & how it opened the java processJdom how it works & how it opened the java process
Jdom how it works & how it opened the java process
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 

More from Adil Jafri

Csajsp Chapter5
Csajsp Chapter5Csajsp Chapter5
Csajsp Chapter5Adil Jafri
 
Programming Asp Net Bible
Programming Asp Net BibleProgramming Asp Net Bible
Programming Asp Net BibleAdil Jafri
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming ClientsAdil Jafri
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran TochAdil Jafri
 
Csajsp Chapter10
Csajsp Chapter10Csajsp Chapter10
Csajsp Chapter10Adil Jafri
 
Flashmx Tutorials
Flashmx TutorialsFlashmx Tutorials
Flashmx TutorialsAdil Jafri
 
Java For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand EjbJava For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand EjbAdil Jafri
 
Csajsp Chapter12
Csajsp Chapter12Csajsp Chapter12
Csajsp Chapter12Adil Jafri
 
Flash Tutorial
Flash TutorialFlash Tutorial
Flash TutorialAdil Jafri
 

More from Adil Jafri (20)

Csajsp Chapter5
Csajsp Chapter5Csajsp Chapter5
Csajsp Chapter5
 
Php How To
Php How ToPhp How To
Php How To
 
Php How To
Php How ToPhp How To
Php How To
 
Owl Clock
Owl ClockOwl Clock
Owl Clock
 
Phpcodebook
PhpcodebookPhpcodebook
Phpcodebook
 
Phpcodebook
PhpcodebookPhpcodebook
Phpcodebook
 
Programming Asp Net Bible
Programming Asp Net BibleProgramming Asp Net Bible
Programming Asp Net Bible
 
Tcpip Intro
Tcpip IntroTcpip Intro
Tcpip Intro
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming Clients
 
Jsp Tutorial
Jsp TutorialJsp Tutorial
Jsp Tutorial
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
Csajsp Chapter10
Csajsp Chapter10Csajsp Chapter10
Csajsp Chapter10
 
Javascript
JavascriptJavascript
Javascript
 
Flashmx Tutorials
Flashmx TutorialsFlashmx Tutorials
Flashmx Tutorials
 
Java For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand EjbJava For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand Ejb
 
Html Css
Html CssHtml Css
Html Css
 
Digwc
DigwcDigwc
Digwc
 
Csajsp Chapter12
Csajsp Chapter12Csajsp Chapter12
Csajsp Chapter12
 
Html Frames
Html FramesHtml Frames
Html Frames
 
Flash Tutorial
Flash TutorialFlash Tutorial
Flash Tutorial
 

Recently uploaded

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 

23xml

  • 1. 1 © 2001-2003 Marty Hall, Larry Brown http://www.corewebprogramming.com core programming Introduction to XML
  • 2. XML2 www.corewebprogramming.com Agenda • XML overview • XML components • Document Type Definition • Specifying data elements (tags) • Defining attributes and entities • A look at XML schema
  • 3. XML3 www.corewebprogramming.com XML Overview • When people refer to XML, they typically are referring to XML and related technologies HTML DOM JDOM W3C SGMLXSLT XQL XML SAX
  • 4. XML4 www.corewebprogramming.com XML Resources • XML 1.0 Specification – http://www.w3.org/TR/REC-xml • WWW consortium’s Home Page on XML – http://www.w3.org/XML/ • Sun Page on XML and Java – http://java.sun.com/xml/ • Apache XML Project – http://xml.apache.org/ • XML Resource Collection – http://xml.coverpages.org/ • O’Reilly XML Resource Center – http://www.xml.com/
  • 5. XML5 www.corewebprogramming.com XML Overview • EXtensible Markup Language (XML) is a meta-language that describes the content of the document (self-describing data) • XML does not specify the tag set or grammar of the language – Tag Set – markup tags that have meaning to a language processor – Grammar – defines correct usage of a language’s tag Java = Portable Programs XML = Portable Data
  • 6. XML6 www.corewebprogramming.com Applications of XML • Configuration files – Used extensively in J2EE architectures • Media for data interchange – A better alternative to proprietary data formats • B2B transactions on the Web – Electronic business orders (ebXML) – Financial Exchange (IFX) – Messaging exchange (SOAP)
  • 7. XML7 www.corewebprogramming.com XML versus HTML • XML fundamentally separates content (data and language) from presentation; HTML specifies the presentation • HTML explicitly defines a set of legal tags as well as the grammar (intended meaning) <TABLE> … </TABLE> • XML allows any tags or grammar to be used (hence, eXtensible) <BOOK> … </BOOK> – Note: Both are based on Standard Generalized Markup Language (SGML)
  • 8. XML8 www.corewebprogramming.com Simple XML Example <?xml version="1.0"?> <authors> <name> <firstname>Larry</firstname> <lastname>Brown</lastname> </name> <name> <firstname>Marty</firstname> <lastname>Hall</lastname> </name> ... </authors>
  • 9. XML9 www.corewebprogramming.com XML Components • Prolog – Defines the xml version, entity definitions, and DOCTYPE • Components of the document – Tags and attributes – CDATA (character data) – Entities – Processing instructions – Comments
  • 10. XML10 www.corewebprogramming.com XML Prolog • XML Files always start with a prolog <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> – The version of XML is required – The encoding identifies character set (default UTF-8) – The value standalone identifies if an external document is referenced for DTD or entity definition – Note: the prolog can contain entities and DTD definitions
  • 11. XML11 www.corewebprogramming.com Prolog Example <?xml version="1.0" standalone="yes"?> <DOCTYPE authors [ <!ELEMENT authors (name)*> <!ELEMENT name (firstname, lastname)> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname (#PCDATA)> ]> <authors> <name> <firstname>James</firstname> <lastname>Gosling</lastname> </name> ... </authors>
  • 12. XML12 www.corewebprogramming.com XML DOCTYPE • Document Type Declarations – Specifies the location of the DTD defining the syntax and structure of elements in the document – Common forms: <!DOCTYPE root [DTD]> <!DOCTYPE root SYSTEM URL> <!DOCTYPE root PUBLIC FPI-identifier URL> – The root identifies the starting element (root element) of the document – The DTD can be external to the XML document, referenced by a SYSTEM or PUBLIC URL • SYSTEM URL refers to a private DTD – Located on the local file system or HTTP server • PUBLIC URL refers to a DTD intended for public use
  • 13. XML13 www.corewebprogramming.com DOCTYPE Examples <!DOCTYPE book "DTDs/CWP.dtd"> <!DOCTYPE book SYSTEM "http://www.corewebprogramming.com/DTDs/CWP.dtd"> DTD located in subdirectory below XML document DTD located HTTP server: www.corewebprogramming.com Book must be the root element of the XML document
  • 14. XML14 www.corewebprogramming.com XML DOCTYPE, cont. • Specifying a PUBLIC DTD <!DOCTYPE root PUBLIC FPI-identifier URL> – The Formal Public Identifier (FPI) has four parts: 1. Connection of DTD to a formal standard - if defining yourself + nonstandards body has approved the DTD ISO if approved by formal standards committee 2. Group responsible for the DTD 3. Description and type of document 4. Language used in the DTD
  • 15. XML15 www.corewebprogramming.com PUBLIC DOCTYPE Examples <!DOCTYPE Book PUBLIC "-//W3C//DTD XHMTL 1.0 Transistional//EN" "http://www.w3.org/TR?xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCYTPE CWP PUBLIC "-//Prentice Hall//DTD Core Series 1.0//EN" "http://www.prenticehall.com/DTD/Core.dtd">
  • 16. XML16 www.corewebprogramming.com XML Comments • Comments are the same as HTML comments <!-- This is an XML and HTML comment -->
  • 17. XML17 www.corewebprogramming.com Processing Instructions • Application-specific instruction to the XML processor <?processor-instruction?> • Example <?xml version="1.0" ?> <?xml-stylesheet type="text/xml" href="orders.xsl" ?> <orders> <order> <count>37</count> <price>49.99</price> <book> <isbn>0130897930</isbn> <title>Core Web Programming Second Edition</title> <authors> <author>Marty Hall</author> <author>Larry Brown</author> </authors> </book> </order> </orders>
  • 18. XML18 www.corewebprogramming.com XML Root Element • Required for XML-aware applications to recognize beginning and end of document • Example <?xml version="1.0" ?> <book> <title>Core Web Programming</title> <contents> <chapter number="1"> Designing Web Pages with HTML </chapter> <chapter number="2"> Block-level Elements in HTML 4.0 </chapter> <chapter number="3"> Text-level Elements in HTML 4.0 </chapter> ... </contents> </book>
  • 19. XML19 www.corewebprogramming.com XML Tags • Tag names: – Case sensitive – Start with a letter or underscore – After first character, numbers, - and . are allowed – Cannot contain whitespaces – Avoid use of colon expect for indicating namespaces • For a well-formed XML documents – Every tag must have an end tag <elementOne> … </elementOne> <elementTwo /> – All tags are completely nested (tag order cannot be mixed)
  • 20. XML20 www.corewebprogramming.com XML Tags, cont. • Tags can also have attributes <message to="Gates@microsoft.com" from="Gosling@sun.com"> <priority/> <text>We put the . in .com. What did you do? </text> </message>
  • 21. XML21 www.corewebprogramming.com XML Attributes • Element Attributes – Attributes provide metadata for the element – Every attribute must be enclosed in "" with no commas in between – Same naming conventions as elements
  • 22. XML22 www.corewebprogramming.com Document Entities • Entities refer to a data item, typically text – General entity references start with & and end with ; – The entity reference is replaced by it’s true value when parsed – The characters < > & ' " require entity references to avoid conflicts with the XML application (parser) &lt; &gt; &amp; &quot; &apos; • Entities are user definable <?xml version="1.0" standalone="yes" ?> <!DOCTYPE book [ <!ELEMENT book (title)> <!ELEMENT title (#PCDATA)> <!ENTITY COPYRIGHT "2001, Prentice Hall"> ]> <book> <title>Core Web Programming, &COPYRIGHT;</title> </book>
  • 23. XML23 www.corewebprogramming.com Document Entities (Aside) • CDATA (character data) is not parsed <?xml version="1.0" encoding="ISO-8859-1"?> <server> <port status="accept"> <![CDATA[8001 <= port < 9000]]> </port> </server>
  • 24. XML24 www.corewebprogramming.com Well-Formed versus Valid • An XML document can be well-formed if it follows basic syntax rules • An XML document is valid if its structure matches a Document Type Definition (DTD)
  • 25. XML25 www.corewebprogramming.com Document Type Definition (DTD) • Defines Structure of the Document – Allowable tags and their attributes – Attribute values constraints – Nesting of tags – Number of occurrences for tags – Entity definitions
  • 26. XML26 www.corewebprogramming.com DTD Example <?xml version="1.0" encoding="ISO-8859-1" ?> <!ELEMENT perennials (daylily)*> <!ELEMENT daylily (cultivar, award*, bloom, cost)+> <!ATTLIST daylily status (in-stock | limited | sold-out) #REQUIRED> <!ELEMENT cultivar (#PCDATA)> <!ELEMENT award (name, year)> <!ELEMENT name (#PCDATA)> <!ATTLIST name note CDATA #IMPLIED> <!ELEMENT year (#PCDATA)> <!ELEMENT bloom (#PCDATA)> <!ATTLIST bloom code (E | EM | M | ML | L | E-L) #REQUIRED> <!ELEMENT cost (#PCDATA)> <!ATTLIST cost discount CDATA #IMPLIED> <!ATTLIST cost currency (US | UK | CAN) "US">
  • 27. XML27 www.corewebprogramming.com Defining Elements • <!ELEMENT name definition/type> <!ELEMENT daylily (cultivar, award*, bloom, cost)+> <!ELEMENT cultivar (#PCDATA)> <!ELEMENT id (#PCDATA | catalog_id)> • Types – ANY Any well-formed XML data – EMPTY Element cannot contain any text or child elements – PCDATA Character data only (should not contain markup) – elements List of legal child elements (no character data) – mixed May contain character data and/or child elements (cannot constrain order and number of child elements)
  • 28. XML28 www.corewebprogramming.com Defining Elements, cont. • Cardinality – [none] Default (one and only one instance) – ? 0, 1 – * 0, 1, …, N – + 1, 2, …, N • List Operators – , Sequence (in order) – | Choice (one of several)
  • 29. XML29 www.corewebprogramming.com Grouping Elements • Set of elements can be grouped within parentheses – (Elem1?, Elem2?)+ • Elem1 can occur 0 or 1 times followed by 0 or 1 occurrences of Elem2 • The group (sequence) must occur 1 or more times • OR – ((Elem1, Elem2) | Elem3)* • Either the group of Elem1, Elem2 is present (in order) or Elem3 is present, 0 or more times
  • 30. XML30 www.corewebprogramming.com Element Example <?xml version="1.0" standalone="yes"?> <!DOCTYPE Person [ <!ELEMENT Person ( (Mr|Ms|Miss)?, FirstName, MiddleName*, LastName, (Jr|Sr)? )> <!ELEMENT FirstName (#PCDATA)> <!ELEMENT MiddleName (#PCDATA)> <!ELEMENT LastName (#PCDATA)> <!ELEMENT Mr EMPTY> <!ELEMENT Ms EMPTY> ... <!ELEMENT Sr EMPTY> ]> <Person> <Mr/> <FirstName>Lawrence</FirstName> <LastName>Brown</LastName> </Person>
  • 31. XML31 www.corewebprogramming.com Defining Attributes • <!ATTLIST element attrName type modifier> • Examples <!ELEMENT Customer (#PCDATA )> <!ATTLIST Customer id CDATA #IMPLIED> <!ELEMENT Product (#PCDATA )> <!ATTLIST Product cost CDATA #FIXED "200" id CDATA #REQUIRED>
  • 32. XML32 www.corewebprogramming.com Attribute Types • CDATA – Essentially anything; simply unparsed data <!ATTLIST Customer id CDATA #IMPLIED> • Enumeration – attribute (value1|value2|value3) [Modifier] • Eight other attribute types – ID, IDREF, NMTOKEN, NMTOKENS, ENTITY, ENTITIES, NOTATION
  • 33. XML33 www.corewebprogramming.com Attribute Modifiers • #IMPLIED – Attribute is not required <!ATTLIST cost discount CDATA #IMPLIED> • #REQUIRED – Attribute must be present <!ATTLIST account balance CDATA #REQUIRED> • #FIXED "value" – Attribute is present and always has this value <!ATTLIST interpreter language CDATA #FIXED "EN"> • Default value (applies to enumeration) <!ATTLIST car color (red | white | blue) "white" )
  • 34. XML34 www.corewebprogramming.com Defining Entities • <!ENTITY name "replacement"> <!ENTITY &amp; "&"> <!ENTITY copyright "Copyright 2001">
  • 35. XML35 www.corewebprogramming.com Limitations of DTDs • DTD itself is not in XML format – more work for parsers • Does not express data types (weak data typing) • No namespace support • Document can override external DTD definitions • No DOM support • XML Schema is intended to resolve these issues but … DTDs are going to be around for a while
  • 36. XML36 www.corewebprogramming.com XML Schema • W3C recommendation released May 2001 – http://www.w3.org/TR/xmlschema-0/ – http://www.w3.org/TR/xmlschema-1/ – http://www.w3.org/TR/xmlschema-2/ – Depends on following specifications • XML-Infoset, XML-Namespaces, XPath • Benefits: – Standard and user-defined data types – Express data types as patterns – Higher degree of type checking – Better control of occurrences • Clearly the future … but limited support
  • 37. XML37 www.corewebprogramming.com XML Schema, Example <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="perennials" type="PerennialType"/> <xsd:complexType name="PerennialType" > <xsd:element name=daylily" type="DaylilyType" maxOccurs="unbounded"/> </xsd:complexType> <xsd:complexType name="DaylilyType" > <xsd:sequence> <xsd:element name="cultivar" type="xsd:string"/> <xsd:element name="award" type="AwardType“ maxOccurs="unbounded"/> <xsd:element name="bloom" type="xsd:string"/> <xsd:element name="cost" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="status" type="StatusType“ use="required"/> </xsd:complexType>
  • 38. XML38 www.corewebprogramming.com XML Schema, Example, cont. <xsd:simpleType name="StatusType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="in-stock"/> <xsd:enumeration value="limited"/> <xsd:enumeration value="sold-out"/> </xsd:restriction> </xsd:simpleType> ... </xsd:schema>
  • 39. XML39 www.corewebprogramming.com Summary • XML is a self-describing meta data • DOCTYPE defines the root element and location of DTD • Document Type Definition (DTD) defines the grammar of the document – Required to validate the document – Constrains grouping and cardinality of elements • DTD processing is expensive • Schema uses XML to specify the grammar – More complex to express but easier to process
  • 40. 40 © 2001-2003 Marty Hall, Larry Brown http://www.corewebprogramming.com core programming Questions?