Beruflich Dokumente
Kultur Dokumente
Introduction to XML
What Is XML? XML is a text-based markup language that is fast becoming the standard for data interchange on the Web. As with HTML, you identify data using tags (identifiers enclosed in angle brackets, like this: <...>). Collectively, the tags are known as "markup".
XML Vocabularies
Scientific vocabularies (CML) business vocabularies (EDI) Legal vocabularies (Extensible form description language) medical vocabularies (HL7) computer vocabularies channel definition format (CDF) structured graph format (SGF) Bean markup language (BML) open s/w description (OSD) xml metadata interchange (XMI) call policy markup language
Here is an example of some XML data you might use for a messaging application:
<message> <to>you@yourAddress.com</to> <from>me@myAddress.com</from> <subject>XML Is Really Cool</subject> <text> How many ways is XML cool? Let me count the ways... </text> </message>
Empty Tags
One really big difference between XML and HTML is that an XML document is always constrained to be well formed. Sometimes, though, it makes sense to have a tag that stands by itself. For example, you might want to add a "flag" tag that marks message as important. <message to="you@yourAddress.com" from="me@myAddress.com" subject="XML Is Really Cool"> <flag/> <text> How many ways is XML cool? Let me count the ways... </text> </message>
Processing Instructions
An XML file can also contain processing instructions that give commands or information to an application that is processing the XML data. Processing instructions have the following format: <?target instructions?>
Basic Standards
SAX Simple API for XML DOM Document Object Model DTD Document Type Definition Namespaces The namespace standard lets you write an XML document that uses two or more sets of XML tags XSL Extensible Stylesheet Language XSLT (+XPATH) Extensible Stylesheet Language for Transformations
Schema Standards
A DTD makes it possible to validate the structure of relatively simple XML documents, but that's as far as it goes.
DTD
Validation
XML
DTC Declarations
Element type declarations Attribute-list declarations Entity declarations Notation declarations Processing declarations Comments Parameter entity references
A Simple Example
<!Element foo (A,(B,C))> <!Element foo (A,B?,C)> <!Element foo (A?,(B,C)| D),E?)> <!Element foo ((A,B)|(C,D))> <!ELEMENT foo (A,(B,C)*,D+)>
<?xml version="1.0" standalone="yes" ?> <!DOCTYPE COLLECTION [ <!ELEMENT Collection (CD)+> <!ELEMENT CD (#PCDATA)> ] > <Collection> <CD>Devotional Songs by Pankaj</CD> <CD>Kajal by Pankaj</CD> <CD>Classical Songs by Pankaj</CD> </Collection>
Attribute List
In a valid XML document you must also explicitly declare all attributes that you might intend to use with the documents elements. You define this by using a type of DTD markup known as an attribute-list declaration. This declaration does the following Defines the names of the attributes associated with that element Specifies the data type of each attribute Specifies for each attribute whether that attribute is required.
eg.(IDREF)
<Employees> <employee ID="1001"> <ename>Ramesh</ename> <job>Clerk</job> <hiredate>12-4-1999</hiredate> <mgr IDREF="1002"/> <sal>7000/-</sal> <comm>300/-</comm> <deptno>10</deptno> </employee> <employee ID="1002"> <ename>Mohan</ename> <job>Manager</job> <hiredate>12-4-1997</hiredate> <mgr IDREF="1002"/> <sal>12000/-</sal>
<?xml version="1.0" standalone="yes" ?> <!DOCTYPE VideoLibrary [ <!ELEMENT Film (Title, Class, (Hero | Director | Heroine)) +> <!ATTLIST Film Color CDATA #IMPLIED Language CDATA #FIXED "Hindi" Year CDATA #REQUIRED> <!ELEMENT Title (#PCDATA)> <!ELEMENT Class (#PCDATA)> <!ELEMENT Hero (#PCDATA)> <!ELEMENT Heroine (#PCDATA)> <!ELEMENT Director (#PCDATA)> ] > <VideoLibrary> <Film Year = "1994">Hum Aapke Hain Kaun</Film> <Class>Love Story</Class> <Heroine>Madhuri Dixit</Heroine> </VideoLibrary>
entity
predefined entities character < > & ' " entityref < > & ' "
general entities
DTD Syntax
<!ENTITY ent-name "replacement text">
XML Usage
&ent-name;
external entities
<!ENTITY ent-name SYSTEM "URL"> <!ENTITY ent-name SYSTEM "file.gif" NDATA gif>
parameter entity
<!ENTITY % ent-name "age CDATA #IMPLIED weight CDATA #IMPLIED height CDATA #REQUIRED > using parameter entity <!ATTLIST ele-name %ent-name attr-name CDATA #REQUIRED>
conditional section
<![INCLUDE [<!element ele-name (#PCDATA)> <!ATTLIST ele-name attr-name CDATA #REQUIRED> ]]> <![IGNORE [<!element ele-name (#PCDATA)> <!ATTLIST ele-name attr-name CDATA #REQUIRED> ]]>
Exercises - ????
DTD for Visiting Card - Is it OK?
<!DOCTYPE VisitngCard [ <!ELEMENT VisitingCard (Name+, Designation+, Group+, Address) > <!ELEMENT Name (#PCDATA) > <!ELEMENT Designation (#PCDATA) > <!ELEMENT Gruoup(#PCDATA) > <!ELEMENT Address(#PCDATA) > ]>