Emerging Technology
Fall Semester, 2004 Xml |
||
---|---|---|
© 2004, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 13-Sep-04 |
CS 683 Emerging Technologies Fall Semester, 2004 Doc 8 XML
Copyright ©, All rights reserved. 2004 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http://www.opencontent.org/opl.shtml) license defines the copyright on this document.
CS 683 Fall 04 | Doc 8, Xml Slide # 2 |
Sun's XML site
World Wide Web Consortium (W3C)
XML.com
Learning XML , Erik Ray, O'Reilly, 2001
CS 683 Fall 04 | Doc 8, Xml Slide # 3 |
XML creators wanted
Key differences from HTML
CS 683 Fall 04 | Doc 8, Xml Slide # 4 |
XML is about
<?xml version="1.0" ?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG>
From http://www.w3schools.com/xsl/default.asp example
CS 683 Fall 04 | Doc 8, Xml Slide # 5 |
Defining the XML tags
Creating documents using XML tags
Displaying or processing the documents
Creating XML tags requires thinking about
CS 683 Fall 04 | Doc 8, Xml Slide # 6 |
Which is better?
<Paragraph> This is a short paragraph. It will be used as an XML example </Paragraph>
<Paragraph> <Sentence> This is a short paragraph. </Sentence> <Sentence> It will be used as an XML example </Sentence> </Paragraph>
<Paragraph> <Author>Roger Whitney</Author> <DateCreated>July 20, 2001</DateCreated> <Title>XML Example</Title> <Sentence> This is a short paragraph. </Sentence> <Sentence> It will be used as an XML example </Sentence> </Paragraph>
CS 683 Fall 04 | Doc 8, Xml Slide # 7 |
XML 1.0 spec
XLinks
Linking documents together
Namespaces
Namespaces for tags.
XHTML
XML version of HTML
MathML
Used to describe math equations
CS 683 Fall 04 | Doc 8, Xml Slide # 8 |
Document Type Definitions (DTDs)
Defines legal tags for a document
XML Scheme
Defines data types in XML
XPath
XPointer
XML Query Language (XQL)
XML Stylesheet Language (XSL)
XSL Transformation Language (XSLT)
Cascading Style Sheets (CSS)
Extensible Stylesheet Language for Formatting Objects (XSL-FO)
CS 683 Fall 04 | Doc 8, Xml Slide # 9 |
Document Object Model (DOM)
Simple API for XML (SAX)
XML Information Set
XML Fragment Interchange
XML-RPC
Simple Object Access Protocol (SOAP)
CS 683 Fall 04 | Doc 8, Xml Slide # 10 |
<!-- A simple XML document with comment --> <greetings> Hello World! </greetings>
CS 683 Fall 04 | Doc 8, Xml Slide # 11 |
A piece of text that describes a unit of data
Tags are surrounded by angle brackets (< and >)
Tags are case sensitive
<GREETINGS> <greetings> <Greetings>
Qualifier in an XML tag
<slide title="XML Slide"> <slide title="Who's on First"> <name position='First'>
Value of the attribute must be quoted
Can use either single or double quotes
CS 683 Fall 04 | Doc 8, Xml Slide # 12 |
Unit of XML data, delimited by tags
<greetings>Hello World!</greetings>
<name> <firstName>John</firstName> <lastName>Fowler</lastName> </name>
Elements can be nested inside other elements
Tags and comments in an XML document
Anything that is not markup in a document
An XML structure in which one or more elements contains text intermixed with subelements
CS 683 Fall 04 | Doc 8, Xml Slide # 13 |
<greetings> <from> <nnammee> <firstName>Roger</firstName> <lastName>Whitney</lastName> </nnammee> </from> <to> <name> <firstName>John</firstName> <lastName>Fowler</lastName> </name> </to> <message> How are you? </message> </greetings>
Is that a typo or a legal tag?
How would we know?
CS 683 Fall 04 | Doc 8, Xml Slide # 14 |
XML document that satisfies basic XML structure
XML document that is well-formed and
Specifies which tags are legal
A Document Type Definition (DTD) is use to specify
CS 683 Fall 04 | Doc 8, Xml Slide # 15 |
Optional Prolog
Root Element
<?xml version="1.0" ?> <!-- A simple XML document with comment --> <greetings> Hello World! </greetings>
CS 683 Fall 04 | Doc 8, Xml Slide # 16 |
For well-formed documents the prolog
Prolog has optional three attributes:
<?xml version="1.0" encoding='US-ASCII' standalone='yes' ?>
<?xml version="1.0" encoding='iso-8859-1' standalone=no ?>
CS 683 Fall 04 | Doc 8, Xml Slide # 17 |
Comments can be placed nearly anywhere outside of tags
Comments can not come before <?xml version="1.0" ?>
<?xml version="1.0" ?> <!-- Another comment --> <greetings> <from>Roger<!-- Legal comment --></from> <to>John</to> <message>Hi</message> </greetings> <!-- Comments at the end -->
CS 683 Fall 04 | Doc 8, Xml Slide # 18 |
Each XML Document has a single root element
<?xml version="1.0" ?> <greetings> <from>Roger</from> <to>John</to> <message>Hi</message> </greetings>
<?xml version="1.0" ?> <from>Roger</from> <to>John</to> <message>Hi</message>
CS 683 Fall 04 | Doc 8, Xml Slide # 19 |
Legal |
Illegal |
<greetings> <from>Roger</from> <to>John</to> <message>Hi</message> </greetings> |
<body> <p>Hello world <p>How are you? </body> |
<greetings></greetings>
<greetings/>
CS 683 Fall 04 | Doc 8, Xml Slide # 20 |
Legal |
Illegal |
<tag name='sam'> |
<tag name=sam> |
<b><center>Bad XML, but ok HTML</b></center>
CS 683 Fall 04 | Doc 8, Xml Slide # 21 |
Are the following the same?
<greetings> Hello World! </greetings>
<greetings>Hello World!</greetings>
CS 683 Fall 04 | Doc 8, Xml Slide # 22 |
For some applications white space may be important
XML parsers are to pass white space to applications
The application decides if the white space in important
CS 683 Fall 04 | Doc 8, Xml Slide # 23 |
What happens if we need to use < inside an element?
This is illegal XML
<paragraph> Everyone knows that 5 < 10 & 1 > 0. </paragraph>
Need to encode the < and & symbols
<paragraph> Everyone knows that 5 < 10 & 1 > 0. </paragraph>
You can used a CDATA section
<paragraph><![CDATA[ Everyone know that 5 < 10 & 1 > 0. ]]> </paragraph>
Standard element content can not contain:
< ]]> &CS 683 Fall 04 | Doc 8, Xml Slide # 24 |
Entity |
Character |
< |
< |
> |
> |
& |
& |
' |
' |
" |
" |
XML allows you do define your own entities
CS 683 Fall 04 | Doc 8, Xml Slide # 25 |
XML document that is well-formed and
Specifies which tags are legal
A Document Type Definition (DTD) is use to specify
<?xml version="1.0" ?> <!DOCTYPE greetings [ <!ELEMENT greetings (#PCDATA)>]> <greetings> Hello World! </greetings>
Copyright ©, All rights reserved.
2004 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.