2. Agenda
Introduction to XML
Basic rules
Parsing XML
XML Namespaces
XML Schemas
XSLT Transformation
Where is XML applying? (examples)
3. Agenda
Introduction to XML
Basic rules
Parsing XML
XML Namespaces
XML Schemas
XSLT Transformation
Where is XML applying? (examples)
4. Origin of XML
SGML
1986
HTML 1.0 XML 1.0
1992 1998
HTML XHTML
4.01 1999 1.0 2000
XHTML
2.0 2010
5. XML Data Model (a tree)
1 root
2 title item item
name name
company company
3
model model
cost cost
6. Agenda
Introduction to XML
Basic rules
Parsing XML
XML Namespaces
XML Schemas
XSLT Transformation
Where is XML applying? (examples)
7. Basic rules
• All XML Elements Must Have a Closing
• XML Tags are Case Sensitive
• XML Elements Must be Properly Nested
• XML Attribute Values Must be Quoted
• XML Documents Must Have a Root Element
• Entity References
• White-space is Preserved in XML
8.
9. Agenda
Introduction to XML
Basic rules
Parsing XML
XML Namespaces
XML Schemas
XSLT Transformation
Where is XML applying? (examples)
10. Parsing XML
XML parser -- Reads in XML data, checks for
syntactic constraints, and makes data available
to an application. There are three 'generic'
parser APIs
– SAX Simple API to XML (event-based)
– DOM Document Object Model (object/tree based)
14. Agenda
Introduction to XML
Basic rules
Parsing XML
XML Namespaces
XML Schemas
XSLT Transformation
Where is XML applying? (examples)
15. Why namespaces?
HTML:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr> We have the conflict
</table> between two elements
(table). And parser
XML: doesn’t know how
<table> handle this situation.
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
16. Namespaces handle conflicts between
element names.
HTML:
<h:table xmlns:h="http://www.mysite.org/html>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td> We added name prefix to
</h:tr> each element (table). And
</h:table> declared they.
XML:
<x:table xmlns:x="http://www.mysite.org/xml>
<x:name>African Coffee Table</x:name>
<x:width>80</x:width>
<x:length>120</x:length>
</x:table>
17. Agenda
Introduction to XML
Basic rules
Parsing XML
XML Namespaces
XML Schemas
XSLT Transformation
Where is XML applying? (examples)
18. Defining language dialects
• Two ways of doing so:
– XML Document Type Declaration (DTD)– Part of core XML
spec.
– XML Schema – allows for stronger constraints on XML
documents.
• Adding dialect specifications implies two classes of
XML data:
– Well-formed An XML document that is syntactically
correct
– Valid An XML document that is both well-formed and
consistent with a specific DTD (or Schema)
19. DTD
<!ELEMENT root (title?, item*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT item (name, company, model, cost)>
<!ATTRIBUTE id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT cost (#PCDATA)>