Title: XML EXtensible Markup Language
1XMLEXtensible Markup Language
- XML is designed to describe data and to focus on
what data is. HTML is designed to display data
and to focus on how data looks. - XML is created to structure, store, and to send
information - XML tags are not predefined. You must define your
own tags - XML uses a DTD or an XML Schema to describe the
data
2XML an example
- XML was created to structure, store, and to send
information - An Example
- ltnote date10/30/2007gt
- lttogtChucklt/togt
- ltfromgtJudylt/fromgt
- ltheadinggtReminderlt/headinggt
- ltbodygtDont forget me this weekend!lt/bodygt
- lt/notegt
- The above is just pure information wrapped in XML
tags. Someone must write a piece of software to
send, receive or display it.
3How can XML be Used?
- XML can separate data from HTML
- With XML, data is stored in separate XML files
- XML is used to exchange data
- XML and B2B. With XML, financial information can
be exchanged over the Internet - XML can be used to share data
- XML can be used to store data
- XML can be used to create new languages
- All future applications will exchange their data
in XML
4XML Syntax Rules
- lt?xml version1.0 encodingISO-8859-1 ?gt
- ltnotegt
- lttogtChucklt/togt
- ltfromgtJudylt/fromgt
- ltheadinggtReminderlt/headinggt
- ltbodygtDont forget me this weekend!lt/bodygt
- lt/notegt
- The first line the XML declaration defines
the XML version and the character encoding - The next line describes the root element
- The next 4 lines describe 4 child elements of the
root - The last line defines the end of the root element
5XML Syntax (continued)
- All XML elements must have a closing tag
- The XML declaration is not a part of the XML
document. It is not an XML element, and it should
not have a closing tag - XML tags are case sensitive
- XML elements must be properly nested
- XML documents must have a root element
- XML attribute values must be quoted
- With XML, white space is preserved
- The syntax for writing comments in XML is similar
to HTML - lt!-- This is a XML comment --gt
6- XML (EXtensible Markup Language)
- Introduction to XML
- What is HTML
- What is XML
- XML Syntax
- Elements must have a closing tag
- Elements must be properly nested
ltbookgt lttitlegtXML (Extensible Markup
Languagelt/titlegt ltprod id"33-657"
media"paper"gtlt/prodgt ltchaptergtIntroduction to
XML ltparagtWhat is HTMLlt/paragt ltparagtWhat is
XMLlt/paragt lt/chaptergt ltchaptergtXML Syntax
ltparagtElements must have a closing
taglt/paragt ltparagtElements must be properly
nestedlt/paragt lt/chaptergt lt/bookgt
7XML Elements
- XML elements are related as parents and children
- An XML element can have element content, mixed
content, simple content, or empty content - An element can have attributes
- XML documents often have a corresponding
database, in which fields exist corresponding to
elements in the XML document. A good practice is
to use the naming rules of your database for the
elements in the XML documents
8XML Attributes
- Attributes are used to provide additional
information, which is not relevant to the data,
about elements - Try to avoid using attributes.
ltnotegt ltdategt ltdaygt10lt/daygt
ltmonthgt30lt/monthgt ltyeargt2007lt/yeargt lttogtC
hucklt/togt ltfromgtJudylt/fromgt ltheadinggtReminderlt/hea
dinggt ltbodygtDont forget me this
weekend!lt/bodygt lt/notegt
ltnote date10/30/2007gt lttogtChucklt/togt ltfromgtJudy
lt/fromgt ltheadinggtReminderlt/headinggt ltbodygtDont
forget me this weekend!lt/bodygt lt/notegt
9XML Validation
- XML with correct syntax is Well Formed XML
- XML validated against a DTD is Valid XML
- A valid XML document is a Well Formed XML
document, which also conforms to the rules of a
DTD - XML DTD
- A DTD defines the legal elements of an XML
document - A DTD is used to define the document structure
with a list of legal elements - XML Schema
- An XML based alternative to DTD
10Displaying XML Files
- XSL (eXtensible Stylesheet Language) is far more
sophisticated than CSS - Examples
11XML Namespaces
- The XML namespace attribute is placed in the
start tag of an element and has the following
syntax. The syntax is - xmlnsnamespace-prefix"namespaceURI
- where namespaceURI provides the namespace a
unique name
lthtable xmlnsh"http//www.w3.org/TR/html4/"gt lt
htrgt lthtdgtAppleslt/htdgtlthtdgtBananaslt/htdgt lt/
htrgt lt/htablegt
ltftable xmlnsf"http//www.w3schools.com/furnitu
re"gt ltfnamegtAfrican Coffee Tablelt/fnamegt ltfwi
dthgt80lt/fwidthgt ltflengthgt120lt/flengthgt lt/ftab
legt
12XML CDATA
- Text inside a CDATA section will be ignored by
the parser - A CDATA section starts with lt!CDATA and ends
with gt
ltscriptgt lt!CDATA function matchwo(a,b) if
(a lt b a lt 0) then return 1 else
return 0 gt lt/scriptgt
13XML Encoding
- To let your XML parser understand foreign
characters, you should save your XML documents as
Unicode - Windows 2000 Notepad can save files as Unicode
using UTF-16 encoding - You will get error message
- if your file was save as Unicode/UTF-16 but the
encoding attribute specified a single-byte
encoding like Windows-1252, ISO-8859-1 or UTF-8 - If your document was saved with single-byte
encoding, but the encoding attribute specified a
double-byte encoding like UTF-16
14XML Editors
- XML Editors will help you to write error-free XML
documents, validate your XML against a DTD or a
schema, and force you to stick to a valid XML
structure. - XML Schema to define XML structures and data
types - XSLT to transform XML data
- SOAP to exchange XML data between applications
- WSDL to describe web services
- RDF to describe web resources
- XPath and XQuery to access XML data
- SMIL to define graphics
- Example Altova XMLSpy