Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Programming Introduction to XML ITC570 1. L EARNING O BJECTIVES  Be able to:  Understand XML technologies and their roles.  Understand different.

Similar presentations


Presentation on theme: "XML Programming Introduction to XML ITC570 1. L EARNING O BJECTIVES  Be able to:  Understand XML technologies and their roles.  Understand different."— Presentation transcript:

1 XML Programming Introduction to XML ITC570 1

2 L EARNING O BJECTIVES  Be able to:  Understand XML technologies and their roles.  Understand different components of an XML document.  Create a well-form XML document. 2

3 3 XML stands for eXtensible Markup Language HTML is used to mark up text so it can be displayed to users XML is used to mark up data so it can be processed by computers HTML describes both structure (e.g.,, ) and appearance (e.g.,, ) XML describes only content, or “meaning” HTML uses a fixed, unchangeable set of tags In XML, you make up your own tags

4  HTML and XML look similar, because they are both SGML languages (SGML = Standard Generalized Markup Language)  Both HTML and XML use elements enclosed in tags (e.g. This is an element )  Both use tag attributes (e.g., )  Both use entities (<, >, &, ", &apos; )  More precisely,  HTML is defined in SGML  XML is a (very small) subset of SGML 4

5  HTML is for humans  HTML describes web pages  You don’t want to see error messages about the web pages you visit  Browsers ignore and/or correct as many HTML errors as they can, so HTML is often sloppy  XML is for computers  XML describes data  The rules are strict and errors are not allowed In this way, XML is like a programming language  Current versions of most browsers can display XML However, browser support of XML is spotty at best 5

6 6 7/14/97 North Place, NX USA High Temp: 103 Low Temp: 70 Morning: Partly cloudy, Hazy Afternoon: Sunny & hot Evening: Clear and Cooler From: XML: A Primer, by Simon St. Laurent

7 S OME TECHNOLOGIES WE MAY COVER 7 HTML Java HTML Forms JavaScript XHTML & CSS But underneath... HTTP TCP/IP Sockets maybe RMI Java servlets JSP PerlPHP SQL XML DTD XML Schemas RELAX NG XSL XSLT XPath CSS Java SAX DOM JAXP Java JDBC Apache Tomcat Ajax

8 W HY XML?  Distributed applications need to share data.  plain text  structure and the meaning of the data are tightly defined.  Delivery of data to multi-devices  Separation of data and presentation. 8

9 XML D OCUMENT – AN E XAMPLE Harry Potter and the Sorcerer’s Stone J.K Rowling … 9 bookshop book title book author initialssurname price value

10  DTD (Document Type Definition) and XML Schemas are used to define legal XML tags and their attributes for particular purposes  CSS (Cascading Style Sheets) describe how to display HTML or XML in a browser  XSLT (eXtensible Stylesheet Language Transformations) and XPath are used to translate from one form of XML to another  DOM (Document Object Model), SAX (Simple API for XML, and JAXP (Java API for XML Processing) are all APIs for XML parsing 10

11 XML P ARSER  Required to read and manipulate XML documents.  Read the XML documents as a plain text and transform it into a data structure, typically tree, in the memory.  The applications, such as web browser, access the data structure and process the data according to their objectives.  Example: msxml 11

12 XML D OCUMENT – B ASIC C OMPONENTS  Elements.  Attributes.  Character and Entity References.  Character Data (CDATA).  Processing Instruction.  Comments. 12

13 E LEMENTS 13 Root Element (compulsory) Branch Elements Leaf Element bookshop book title book author initialssurname price value attribute

14 E LEMENT  The basic building block of XML markups.  It may contains:  Text, Other elements (child elements)  Attributes, Character Data, Other markup, eg comments  Delimited with a start-tag and an end-tag.  Element can be empty.  The end-tag CANNOT be omitted as in HTML.  Each tag must consist a valid element type name. 14

15 E LEMENT ’ S N AME  Element’s Name (Tag’s name) is CASE SENSITIVE.     Trailing space is legal but will be ignored  = 15

16 E MPTY E LEMENT  Has no content.  May be associated with attribute.  Example: can be abbreviated into 16

17 XML D OCUMENT – B ASIC C OMPONENTS  Elements.  Attributes.  Character and Entity References.  Character Data (CDATA).  Processing Instruction.  Comments. 17

18 A TTRIBUTES  Information regarding the element. “If elements are ‘nouns’ of XML then attributes are its ‘adjective’.  18 Harry Potter

19 A TTRIBUTES VS E LEMENT  Determine by the semantic contents.  Attributes are characteristics of an element. 19 Harry Potter

20 XML D OCUMENT – B ASIC C OMPONENTS  Elements.  Attributes.  Character and Entity References.  Character Data (CDATA).  Processing Instruction.  Comments. 20

21 C HARACTER R EFERENCES  Use to display characters that are not supported by the input device (keyboard).  entering £ using US-ASCII keyboard.  Format: &#NNNNN; or &#xXXXX;  N decimal  X hexadecimal  Example: $ => $ OR &#x24 21

22 E NTITY R EFERENCES  Entities may be defined and used for:  Representing character used in mark-up &lt == “<“ &amp == “&”  String &IR == Information Retrieval  Predefined entities: &lt, &gt, &quot, etc 22

23 XML D OCUMENT – B ASIC C OMPONENTS  Elements.  Attributes.  Character and Entity References.  Character Data (CDATA).  Processing Instruction.  Comments. 23

24 C HARACTER D ATA  To escape blocks of text containing characters which would otherwise be recognized as markup.   Hello, world! ]]> 24

25 C HARACTER D ATA (2) &Warn;- &Disclaimer;&lt;&copy 2001; &PM; &gt> 25

26 XML D OCUMENT – B ASIC C OMPONENTS  Elements.  Attributes.  Character and Entity References.  Character Data (CDATA).  Processing Instruction.  Comments. 26

27 P ROCESSING I NSTRUCTION (PI)  Processing instructions (PIs) allow documents to contain instructions for applications.   Target is used to identify the application or other object to which the PI is directed.  27

28 XML D OCUMENT – B ASIC C OMPONENTS  Elements.  Attributes.  Character and Entity References.  Character Data (CDATA).  Processing Instruction.  Comments. 28

29 C OMMENTS  Syntax:  Comments cannot be used within element tags. … some content … >  Comments may never be nested. like this --> 29

30  Names (as used for tags and attributes) must begin with a letter or underscore, and can consist of:  Letters, both Roman (English) and foreign  Digits, both Roman and foreign. (dot) - (hyphen) _ (underscore) : (colon) should be used only for namespaces  Combining characters and extenders (not used in English) 30

31  Start with  XML is case sensitive  You must have exactly one root element that encloses all the rest of the XML  Every element must have a closing tag  Elements must be properly nested  Attribute values must be enclosed in double or single quotation marks  There are only five pre declared entities 31

32 This is the great American novel. It was a dark and stormy night. Suddenly, a shot rang out! 32

33  An XML document represents a hierarchy; a hierarchy is a tree 33 novel foreword chapter number="1" paragraph This is the great American novel. It was a dark and stormy night. Suddenly, a shot rang out!

34  You can make up your own XML tags and attributes, but... ...any program that uses the XML must know what to expect!  A DTD (Document Type Definition) defines what tags are legal and where they can occur in the XML  An XML document does not require a DTD  XML is well-structured if it follows the rules given earlier  In addition, XML is valid if it declares a DTD and conforms to that DTD  A DTD can be included in the XML, but is typically a separate document  Errors in XML documents will stop XML programs  Some alternatives to DTDs are XML Schemas and RELAX NG 34

35  An element may contain other elements, plain text, or both  An element containing only text: David Matuszek  An element ( ) containing only elements: David Matuszek  An element containing both: CIT597 10:30-12:00 MW  An element that contains both text and other elements is said to have mixed content  Mixed content is legal, but bad  Mixed content makes it much harder to define valid XML  Mixed content is more complicated to use in a program  Mixed content adds no power to XML--it is never needed for anything 35

36 36 7/14/97 North Place NX USA 103 70 Morning Partly cloudy, Hazy Afternoon Sunny & hot Evening Clear and Cooler

37  XML is designed to be processed by computer programs, not to be displayed to humans  Nevertheless, almost all current browsers can display XML documents  They don’t all display it the same way  They may not display it at all if it has errors  For best results, update your browsers to the newest available versions  Remember: HTML is designed to be viewed, XML is designed to be used 37

38 S TRUCTURE OF XML D OCUMENT  XML document has to be well-formed.  Conform to syntax requirements  Conform to a simple container structure  Common structure of XML document:  Prolog  Body  Epilog 38

39 P ROLOG  Includes:  XML Declaration Version is mandatory, encoding and standalone are optional  Document Type Declaration <!DOCTYPE It is not DTD=Document Type Definition A simple well-formed XML does not need it.  Schema declaration 39

40 B ODY & E PILOG  Body  Contains 1 or more elements  The “contents”  Epilog  Hardly used  Can be used to identify end of document 40

41 W ELL - FORMED XML D OCUMENT 41  Every element must have both a start tag and an end tag, e.g....  But empty elements can be abbreviated:.  XML tags are case sensitive  XML tags may not begin with the letters xml, in any combination of cases  Elements must be properly nested, e.g. not bold and italic  Every XML document must have one and only one root element  The values of attributes must be enclosed in single or double quotes, e.g.  Character data cannot contain < or &

42 XML Process  An XML document is created in an editor. The XML parser reads the document and converts it into a tree of elements.  The parser passes the tree to the browser that displays it.

43 Summary  XML is a meta-markup language that enables the creation of markup languages for particular documents and domains.  XML documents are created in an editor, read by a parser, and displayed by a browser.  Be careful. XML isn’t completely finished. It will change and expand, and you will encounter bugs in current XML software.


Download ppt "XML Programming Introduction to XML ITC570 1. L EARNING O BJECTIVES  Be able to:  Understand XML technologies and their roles.  Understand different."

Similar presentations


Ads by Google