Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML 6 6.1 XML. Outline 1. XML 2. XSL / XSLT 3. DTD 4. DOM 5. XSD 6. XPath 7. XForms.

Similar presentations


Presentation on theme: "XML 6 6.1 XML. Outline 1. XML 2. XSL / XSLT 3. DTD 4. DOM 5. XSD 6. XPath 7. XForms."— Presentation transcript:

1 XML 6 6.1 XML

2 Outline 1. XML 2. XSL / XSLT 3. DTD 4. DOM 5. XSD 6. XPath 7. XForms

3 What is XML? XML stands for EXtensible Markup Language A meta-language for descriptive markup: you invent your own tags XML uses a Document Type Definition (DTD) or an XML Schema to describe the data  XML with a DTD or XML Schema is designed to be self-descriptive Built-in internationalization via Unicode Built-in error-handling Optimized for network operations Tons of support from the big IT companies

4 Some History SGML (Standard Generalized Markup Language)  ISO Standard, 1986, for data storage & exchange  Metalanguage for defining languages (through DTDs)  A famous SGML language: HTML  Separation of content and display  Used in U.S. gvt. & contractors, large manufacturing companies, technical info. Publishers,...  SGML reference is 600 pages long XML  W3C recommendation in 1998  Simple subset (80/20 rule) of SGML: “ASCII of the Web”, “Semantic Web”  XML specification is 26 pages long

5 Timeline 1986  SGML becomes a standard 1989  Tim Berners-Lee creates the WWW 1994  W3C established 1998  XML 1.0 W3C Recommendation Jan 2000  XHTML becomes W3C Recommendation  A Reformulation of HTML 4 in XML 1.0 Oct 2000  W3c XML 1.0 (Second Edition) Recommendation  http://www.w3.org/TR/REC-xml Oct 2002  XML 1.1 Candidate Recommendation  updates XML to use Unicode 3

6 XML and HTML XML is not a replacement for HTML XML was designed to carry data XML and HTML were designed with different goals  XML was designed to describe data and to focus on what data is  HTML was designed to display data and to focus on how data looks. HTML is about displaying information, while XML is about describing information

7 HTML and XML, I 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

8 HTML and XML, II HTML and XML look similar, because they are both SGML languages  Both HTML and XML use elements enclosed in tags  Both use tag attributes More precisely,  HTML is defined in SGML  XML is a (very small) subset of SGML

9 HTML and XML, III 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

10 XML does not DO anything XML was not designed to DO anything XML is created to structure, store and to send information The following example is a book info, stored as XML: The Autobiography of Benjamin Franklin Benjamin Franklin 8.99 …

11 XML is Free and Extensible XML tags are not predefined  You must "invent" your own tags  The tags used to mark up HTML documents and the structure of HTML documents are predefined  The author of HTML documents can only use tags that are defined in the HTML standard XML allows the author to define his own tags and his own document structure

12 XML Future XML is going to be everywhere XML is a cross-platform, software and hardware independent tool for transmitting information. Documents Configuration Database Application X Repository XML

13 Benefits of XML Open W3C standard Representation of data across heterogeneous environments  Cross platform  Allows for high degree of interoperability Strict rules  Syntax  Structure  Case sensitive

14 How can XML be Used? XML can Separate Data from HTML With XML, your data is stored outside your HTML XML is used to Exchange Data With XML, data can be exchanged between incompatible systems 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 make your Data more Useful XML can be used to Create new Languages

15 Components of an XML Document Elements  Each element has a beginning and ending tag ...  Elements can be empty ( ) Attributes  Describes an element; e.g. data type, data range, etc.  Can only appear on beginning tag Processing instructions  Encoding specification (Unicode by default)  Namespace declaration  Schema declaration

16 Components of an XML Document Processing Instructions Elements Elements with Attributes

17 XML declaration The XML declaration looks like this:  The XML declaration is not required by browsers, but is required by most XML processors (so include it!)  If present, the XML declaration must be first--not even whitespace should precede it  Note that the brackets are  version="1.0" is required (this is the only version so far)  encoding can be "UTF-8" (ASCII) or "UTF-16" (Unicode), or something else, or it can be omitted  standalone tells whether there is a separate DTD

18 Processing Instructions PIs (Processing Instructions) may occur anywhere in the XML document (but usually first) A PI is a command to the program processing the XML document to handle it in a certain way XML documents are typically processed by more than one program Programs that do not recognize a given PI should just ignore it General format of a PI: Example:

19 XML Elements An XML element is everything from the element's start tag to the element's end tag XML Elements are extensible and they have relationships XML Elements have simple naming rules  Names can contain letters, numbers, and other characters  Names must not start with a number or punctuation character  Names must not start with the letters xml (or XML or Xml..)  Names cannot contain spaces

20 XML Attributes XML elements can have attributes Data can be stored in child elements or in attributes Should you avoid using attributes?  Here are some of the problems using attributes:  attributes cannot contain multiple values (child elements can)  attributes are not easily expandable (for future changes)  attributes cannot describe structures (child elements can)  attributes are more difficult to manipulate by program code  attribute values are not easy to test against a Document Type Definition (DTD) - which is used to define the legal elements of an XML document

21 An XML Document The Autobiography of Benjamin Franklin Benjamin Franklin 8.99 The Confidence Man Herman Melville 11.99

22 Another XML Document 7/14/97 North Place, NX USA High Temp: 103 Low Temp: 70 Morning: Partly cloudy, Hazy Afternoon: Sunny & hot Evening: Clear and Cooler

23 XML Validation XML with correct syntax is Well Formed XML XML validated against a DTD is Valid XML

24 Rules For Well-Formed XML There must be one, and only one, root element All XML elements must have a closing tag Sub-elements must be properly nested  A tag must end within the tag in which it was started Attributes are optional  Defined by an optional schema Attribute values must be enclosed in “” or ‘’ Processing instructions are optional XML is case-sensitive  and are not the same type of element White space is preserved CR / LF is converted to LF Comment in XML is similar to that of HTML

25 XML DTD A DTD defines the legal elements of an XML document  defines the document structure with a list of legal elements XML Schema  XML Schema is an XML based alternative to DTD Errors in XML documents will stop the XML program XML Validators

26 Browsers Support for XML Netscape 6 supports XML Internet Explorer 5.0 supports the XML 1.0 standard Internet Explorer 5.0 has the following XML support:  Viewing of XML documents  Full support for W3C DTD standards  XML embedded in HTML as Data Islands  Binding XML data to HTML elements  Transforming and displaying XML with XSL  Displaying XML with CSS  Access to the XML DOM

27 Viewing XML Files Raw XML files can be viewed in IE 5.0 (and higher) and in Netscape 6  but to make it display like a web page, you have to add some display information XML documents do not carry information about how to display the data Different solutions to the display problem, using CSS, XSL, JavaScript, and XML Data Islands Will you be writing your future Homepages in XML?

28 Displaying XML with CSS With CSS (Cascading Style Sheets) you can add display information to an XML document Formatting XML with CSS is NOT the future of the Web Formatting with XSL will be the new standard

29 Example: the xml file Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tyler UK CBS Records 9.90 1988..

30 Example: the css file CATALOG { background-color: #ffffff; width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { color: #FF0000; font-size: 20pt; } ARTIST { color: #0000FF; font-size: 20pt; } COUNTRY,PRICE,YEAR,COMPANY { Display: block; color: #000000; margin-left: 20pt; }

31 Displaying XML with XSL With XSL you can add display information to your XML document XSL is the preferred style sheet language of XML  XSL (the eXtensible Stylesheet Language) is far more sophisticated than CS  One way to use XSL is to transform XML into HTML before it is displayed by the browser

32 Example: the xml file Belgian Waffles $5.95 two of our famous Belgian Waffles with plenty of real maple syrup 650 Strawberry Belgian Waffles $7.95 light Belgian waffles covered with strawberries and whipped cream 900 …

33 Example: the xsl file - ( calories per serving)

34 View the result in IE 6

35 XML Data Islands XML can be embedded within HTML pages in Data Islands Manipulated via client side script or data binding The unofficial tag is used to embed XML data within HTML Data Islands can be bound to HTML elements (like HTML tables)

36 The Microsoft XML Parser To read and update an XML document, you need an XML parser The Microsoft XML parser comes with Microsoft Internet Explorer 5.0 Once you have installed IE 5.0, the parser is available to scripts, both inside HTML documents.  The parser features a language-neutral programming model that supports:  JavaScript, VBScript, Perl, VB, Java, C++ and more  W3C XML 1.0 and XML DOM  DTD and validation You can create an XML document object with the following code:  var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")

37 Loading an XML file into the parser XML files can be loaded into the parser using script code. The following code loads an XML document (note.xml) into the XML parser:  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("note.xml") //....... processing the document goes here  The second line in the code above creates an instance of the Microsoft XML parser  The third line turns off asynchronized loading, to make sure that the parser will not continue execution before the document is fully loaded  The fourth line tells the parser to load the XML document called note.xml

38 Namespaces: Overview Part of XML’s extensibility Allow authors to differentiate between tags of the same name (using a prefix)  Frees author to focus on the data and decide how to best describe it  Allows multiple XML documents from multiple authors to be merged Identified by a URI (Uniform Resource Identifier)  When a URL is used, it does NOT have to represent a live server

39 Namespaces: Declaration xmlns: bk = “http://www.example.com/bookinfo/” xmlns: bk = “urn:mybookstuff.org:bookinfo” Namespace declaration examples: Namespace declarationPrefix URI (URL) xmlns: bk = “http://www.example.com/bookinfo/”

40 Namespaces: Examples All About XML Joe Developer 19.99 All About XML Joe Developer 19.99

41 Namespaces: Default Namespace An XML namespace declared without a prefix becomes the default namespace for all sub-elements All elements without a prefix will belong to the default namespace: All About XML Joe Developer

42 Namespaces: Scope Unqualified elements belong to the inner-most default namespace.  BOOK, TITLE, and AUTHOR belong to the default book namespace  PUBLISHER and NAME belong to the default publisher namespace All About XML Joe Developer Microsoft Press

43 Namespaces: Attributes Unqualified attributes do NOT belong to any namespace  Even if there is a default namespace This differs from elements, which belong to the default namespace

44 Entities Entities provide a mechanism for textual substitution, e.g. You can define your own entities Parsed entities can contain text and markup Unparsed entities can contain any data  JPEG photos, GIF files, movies, etc. EntitySubstitution << &&

45 CDATA By default, all text inside an XML document is parsed You can force text to be treated as unparsed character data by enclosing it in Any characters, even & and <, can occur inside a CDATA Whitespace inside a CDATA is (usually) preserved The only real restriction is that the character sequence ]]> cannot occur inside a CDATA CDATA is useful when your text has a lot of illegal characters (for example, if your XML document contains some HTML text)

46 Pure XML -- Instance Model XML 1.0 Standard:  no explicit data model  only syntax of well-formed and valid (wrt. a DTD) documents implicit data model:  nested containers ("boxes within boxes")  labeled ordered trees (=a semistructured data model)  relational, object-oriented, other data: easy to encode foo bar lab A B C "foo" "bar" C: "bar" A: A: B: "foo" C: "lab" C children are ordered

47 c2b2a2 c3b3a3 c1b1a1 CBA R  R   tuple   A  a1  /A   B  b1  /B   C  c1  /C   /tuple   tuple   A  a2  /A   B  b2  /B   C  c2  /C   /tuple  …  /R  R tuple ABC a1 b1 c1 tuple ABC a2 b2 c2 tuple ABC a3 b3 c3 Example: Relational Data to XML

48 Adding Structure and Semantics XML Document Type Definitions (DTDs):  define the structure of "allowed" documents (i.e., valid wrt. a DTD)   database schema  => improve query formulation, execution,... XML Schema  defines structure and data types  allows developers to build their own libraries of interchanged data types XML Namespaces  identify your vocabulary

49 XML Related Technologies I XHTML - Extensible HTML CSS - Cascading Style Sheets XSL - Extensible Style Sheet Language  XSL consists of three parts: XML Document Transformation (renamed XSLT, see below), a pattern matching syntax (renamed XPath, see below), and a formatting object interpretation. XSLT - XML Transformation  XSLT is far more powerful than CSS. It can be used to transform XML files into many different output formats. XPath - XML Pattern Matching  XPath is a language for addressing parts of an XML document. XPath was designed to be used by both XSLT and XPointer.

50 XML Related Technologies II XLink - XML Linking Language  The XML Linking Language (XLink), allows elements to be inserted into XML documents in order to create links between XML resources. XPointer - XML Pointer Language  The XML Pointer Language (XPointer), supports addressing into the internal structures of XML documents, such as elements, attributes, and content. DTD - Document Type Definition  A DTD can be used to define the legal building blocks of an XML document. Namespaces  XML namespaces defines a method for defining element and attribute names used in XML by associating them with URI references.

51 XML Related Technologies III DOM - Document Object Model  The DOM defines interfaces, properties and methods to manipulate XML documents. XSD - XML Schema  Schemas are powerful alternatives to DTDs. Schemas are written in XML, and support namespaces and data types. XQL - XML Query Language  The XML Query Language supports query facilities to extract data from XML documents. SAX - Simple API for XML  SAX is another interface to read and manipulate XML documents

52 References W3 Schools XML Tutorial  http://www.w3schools.com/xml/default.asp W3C XML page  http://www.w3.org/XML/ XML Tutorials  http://www.programmingtutorials.com/xml.aspx Online resource for markup language technologies  http://xml.coverpages.org/ Several Online Presentations

53 Reading List W3 Schools XML Tutorial  http://www.w3schools.com/xml/default.asp


Download ppt "XML 6 6.1 XML. Outline 1. XML 2. XSL / XSLT 3. DTD 4. DOM 5. XSD 6. XPath 7. XForms."

Similar presentations


Ads by Google