Presentation is loading. Please wait.

Presentation is loading. Please wait.

Præsentation 3: Opsummering af Client-Side Teknologier del 2 Internetteknologi 2 (ITNET2)

Similar presentations


Presentation on theme: "Præsentation 3: Opsummering af Client-Side Teknologier del 2 Internetteknologi 2 (ITNET2)"— Presentation transcript:

1 Præsentation 3: Opsummering af Client-Side Teknologier del 2 Internetteknologi 2 (ITNET2)

2 Ingeniørhøjskolen i Århus Slide 2 af 61 Indhold i denne præsentation En hvirvelvind introduktion til: –XML –DTD –XML Schema –XSL –XSL-FO –XSLT –XPath –XML-programmering

3 Grundlæggende XML

4 Ingeniørhøjskolen i Århus Slide 4 af 61 XML markup eXtended Markup Language XML based on SGML (subset of) Like SGML for structure not layout (as HTML) XML targets the Internet – but is also being used for application exchange formats (Open Office, XMI) – CSVs XML is an W3C Recommendation –http://www.w3.org/TR/REC-xml Structure decided by DTD or Schema (more later) Wide spread support for XML (hype)

5 Ingeniørhøjskolen i Århus Slide 5 af 61 Examples of XML usage GUI for “thin” clients –XHTML –WML (we shall look closer at this shortly) Inter-process communication –SOAP –BizTalk –ebXML Databases –XML Databases –XQuery –XLink, XPointer Representation / exchange of data –XMI (UML diagrams exchange format) –MathXML –CML –Proprietary Example: EPJ XML –good thing when every danish county makes its own Easy to comprehend due to the nature of XML Open office

6 Ingeniørhøjskolen i Århus Slide 6 af 61 Article.xml 1 2 3 4 5 6 7 8 Simple XML 9 10 September 19, 2001 11 12 13 Tem 14 Nieto 15 16 17 XML is pretty easy. 18 19 Once you have mastered XHTML, XML is easily 20 learned. You must remember that XML is not for 21 displaying information but for managing information. 22 23 24 Element article is the root element. Elements title, date, author, summary and content are child elements of article.

7 Ingeniørhøjskolen i Århus Slide 7 af 61 Namespace.xml 1 3 4 5 6 <text:directory xmlns:text = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo"> 8 9 10 A book list 11 12 13 14 A funny picture 15 16 17 18 Keyword xmlns creates two namespace prefixes, text and image. URIs ensure that a namespace is unique. Use of XML Namespaces XML namespaces used to avoid naming conflicts When several different elements are involved isnt always a book Keyword ”xmlns”

8 XML skemadefinitioner: Document Type Definition (DTD) og XML Schema

9 Ingeniørhøjskolen i Århus Slide 9 af 61 DTDs Document Type Definition Extended Backus-Naur Form Defines how an XML document is structured –Required elements –Nesting of elements –Does not define types or behaviour If DTD is used – some parsers can decide if XML document is “valid” – which is more than just “wellformed”

10 Ingeniørhøjskolen i Århus Slide 10 af 61 Letter.dtd 1 2 3 4 <!ELEMENT letter ( contact+, salutation, paragraph+, 5 closing, signature )> 6 7 <!ELEMENT contact ( name, address1, address2, city, state, 8 zip, phone, flag )> 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 The ELEMENT element type declaration defines the rules for element letter. The plus sign ( + ) occurrence indicator specifies that the DTD allows one or more occurrences of an element. (2 contacs in our example) The contact element definition specifies that element contact contains child elements name, address1, address2, city, state, zip, phone and flag — in that order.

11 Ingeniørhøjskolen i Århus Slide 11 af 61 Letter.xml 1 6 8 10 11 John Doe 12 123 Main St. 13 14 Anytown 15 Anystate 16 12345 17 555-1234 18 19 20 21 22 Joe Schmoe 23 Box 12345 24 15 Any Ave. 25 Othertown 26 Otherstate 27 67890 28 555-4321 29 30 32 Dear Sir: 33 34 It is our privilege to inform you about our new 35 database managed with XML. This new system allows 36 you to reduce the load of your inventory list server by 37 having the client machine perform the work of sorting 38 and filtering the data. 39 Sincerely 40 Mr. Doe 41 42

12 Ingeniørhøjskolen i Århus Slide 12 af 61 XML Schema DTD works OK – but –Is in Ex. Backus-Naur Form – why not use XML to describe? –Cannot declare a type to of an element – hundrede kr Could give problems –Several other problems W3C XML Schema –Use XML to describe the structure of XML documents … –Possible to give type information to XML definitions Not supported by all parsers yet Will live besides DTDs for a while

13 Ingeniørhøjskolen i Århus Slide 13 af 61 Book.xsd 1 2 3 4 5 6 <xsd:schema xmlns:xsd = "http://www.w3.org/2000/10/XMLSchema" 7 xmlns:deitel = "http://www.deitel.com/booklist" 8 targetNamespace = "http://www.deitel.com/booklist"> 9 10 11 12 13 <xsd:element name = "book" type = "deitel:BookType" 14 minOccurs = "1" maxOccurs = "unbounded"/> 15 16 17 18 19 20 21 Namespace prefix. Element element defines an element to be included in the XML document structure. Attributes name and type specify the element ’s name and data type, respectively. Element complexType defines an element type that has a child element named book. Attribute minOccurs specifies that books must contain a minimum of one book element. The resulting namespace.

14 Ingeniørhøjskolen i Århus Slide 14 af 61 Local definitions vs public in XML Schema Instead of using the ”type” system Use local definitions Another public variant is using ”ref” How may this be done using the ”type” approach instead?

15 Accessing XML

16 Ingeniørhøjskolen i Århus Slide 16 af 61 How to use XML? Need a parser (or a parser API) to access XML (as with CSV) Two commonly used methods: –DOM (Document Object Model) W3C Recommendation Makes a tree structure representation of an XML document in memory –SAX (Simple API for XML) Supported by diff. vendors Parses document line by line and sends events to subscribers Needs to parse every time access to XML document is needed DOM is better for –Slow to load XML document (need all) –Quick access to random read or update of XML (like WWW browser - BOM) –Requires a lot of memory (need to hold entire XML in mem) SAX is better for –Applications subscribing to certain parts of XML (event subscription) –Slow for random access to XML document (must parse every time)

17 XSL: XSLT, XSL_FO, XPath

18 Ingeniørhøjskolen i Århus Slide 18 af 61 Formatting XSL & CSS XML is only content – no formatting Possible to transform the data to XHTML (or other) using JavaScript and server-side The W3C ideal is using CSS or XSL – eXtensible Style Sheets CSS is most common today– but XSL has more features

19 Ingeniørhøjskolen i Århus Slide 19 af 61 XSL vs CSS W3C made both XSL and CSS: –The Extensible StyleSheet Language –XML based language for the formatting of document –… which by some is regarded as more advantageous compared with the more cryptic CSS –XSL consists of XSL-FO (Formatting Objects), the XSL Transformations language (XSLT) and XPath for defining and accessing part of the XML document –Exactly the same job may however be solved by using server-side programming –… but of course XSLT may be used client-side to relief the server (it can also be applied server-side)

20 Ingeniørhøjskolen i Århus Slide 20 af 61 The 3 Main Technologies of XSL XSLT, a language for transforming information XSL or XSL-FO, a language for formatting information XPath, a language for defining parts of an XML document and accessing them Each of these elements could fill an entire class. You will only need to be acquainted with the overall functionality of these

21 Ingeniørhøjskolen i Århus Slide 21 af 61 XPath Flexible notation for navigating around trees Resembles notation used in Unix filesystems A basic technology that is widely used –uniqueness and scope in XML Schema –pattern matching an selection in XSLT –relations in XLink and XPointer –computations on values in XSLT and XQuery XPath is not written in XML XPath is a W3C Standard

22 Ingeniørhøjskolen i Århus Slide 22 af 61 Location Paths in XPath location path evaluates to a sequence of nodes sequence is sorted in document order sequence will never contain duplicates The location path is a sequence of different steps A location step consists of –an axis (a direction of selection– successors, descendants) –a nodetest (indtifies a node within the axis) –Some predicates (a statement/expression yielding a boolean) axis :: nodetest [predicate] child::price[price=9.90] (example)

23 Ingeniørhøjskolen i Århus Slide 23 af 61 Evaluating Location Paths Location Paths may consist of several steps A step maps a context node into a sequence This also maps sequences to sequences –each node is used as context node –and is replaced with the result of applying the step The path then applies each step in turn, using the former step as the sequence to work on It may be absolute or relative (/cd/price or cd/price)

24 Ingeniørhøjskolen i Århus Slide 24 af 61 Example – finding all C nodes

25 Ingeniørhøjskolen i Århus Slide 25 af 61 What are we looking for here?

26 Ingeniørhøjskolen i Århus Slide 26 af 61 XPath Node Tests text() - child::text() all text nodes of current node comment() - child::comment() processing-instruction() node() - child::node() all children of current node * - attribute::* all attributes of current node More node tests exists

27 Ingeniørhøjskolen i Århus Slide 27 af 61 XPath Predicates General XPath expressions Evaluated with the current node as context Result is coerced (translated) into a boolean –a number yields true if it equals the context position –a string yields true if it is not empty –a sequence yields true if it is not empty –Example: child::price[price=9.90] - selects all price elements that are children of the current node with a price element that equals 9.90 –Example: child::cd[position()<6] Selects the first five cd children of the current node

28 Ingeniørhøjskolen i Århus Slide 28 af 61 XPath Abrivated Syntax Tedious work entering XPath syntax Enter: the abrivated syntax Table from http://www.w3schools.com

29 Ingeniørhøjskolen i Århus Slide 29 af 61 XPath Examples

30 Ingeniørhøjskolen i Århus Slide 30 af 61 XSLT XSL Transformations Language for transforming a format neutral XML document into another XML document – e.g. XHTML or WML for presentation May also add new elements or remove elements XSLT relies heavily on XPath for pattern matching –Specifying patterns for template rules –Selecting nodes for processing –Computing boolean conditions –Generating text contents for the output document

31 Ingeniørhøjskolen i Århus Slide 31 af 61 XSLT Template rules An XSLT stylesheet contains template rules The processor finds the most specific rule for the document root It then executes the template body Find the template rules that match the contex node Select the most specific one Evaluate the body (a sequence constructor)

32 Ingeniørhøjskolen i Århus Slide 32 af 61 Applying Templates element applies a template rule to the current element or to the current element's child nodes

33 Ingeniørhøjskolen i Århus Slide 33 af 61 XSL/XSLT example Transforming a XML document using XSLT invovles 2 tree structures –Source tree (original XML document) –Result tree (the transformed document) –AND of course the XSL document! (so totally 3) In this example –We take an XML document which could have been generated from a RDBMS database –We want to transform this XML document into an XHTML document for browsers –And maybe we COULD transform it into a PDF, and a WML document (for mobile phones) or whatever we might need in the future

34 Ingeniørhøjskolen i Århus Slide 34 af 61 XML dokument “Source tree” Games.xml 1 2 3 4 5 6 7 8 9 10 Cricket 11 12 13 More popular among commonwealth nations. 14 15 16 17 18 Baseball 19 20 21 More popular in America. 22 23 24 25 26 Soccer (Football) 27 28 29 Most popular sport in the world. 30 31 32 33 A processing instruction that references the XSL stylesheet games.xsl.. Wait – isn’t there something wrong here – why do we have XSL embedded in the XML documet? We will look at this later Value type specifies that games.xsl is a text/xsl file.

35 Ingeniørhøjskolen i Århus Slide 35 af 61 XSL dokument Elements.xsl 1 2 3 4 5 6 7 <xsl:stylesheet version = "1.0" 8 xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> 9 10 <xsl:output method = "html" omit-xml-declaration = "no" 11 doctype-system = 12 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 13 doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"/> 14 15 16 17 18 19 20 Sports 21 22 23 24 25 26 27 28 29 30 ID 31 Sport 32 Information 33 34 35 The stylesheet start tag—which begins the XSL stylesheet. Element xsl:output writes an XHTML document type declaration to the result tree. The match attribute to select the document root of the source document (i.e., game.xml ).

36 Ingeniørhøjskolen i Århus Slide 36 af 61 Elements.xsl 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 Element xsl:for-each iterates through the source XML document and search for game elements. These three select values are all XPath expressions. Other types of XPath uses include / for navigating to child nodes, and using * wildcards for selecting unknown elements. Other types of usage includes indexing e.g. [1] and selecting attributes using @ Element value-of retrieves attribute id ’s value and place it in a td element in the result tree.

37 Ingeniørhøjskolen i Århus Slide 37 af 61 XHTML dokument “result” tree Result of XSLT tranformation

38 Ingeniørhøjskolen i Århus Slide 38 af 61 More examples? Will only sedate you with boredom and a sad feeling of helplessness Please go try it out yourself instead –Plenty of examples at: –http://www.w3schools.com/xsl/default.asphttp://www.w3schools.com/xsl/default.asp

39 Ingeniørhøjskolen i Århus Slide 39 af 61 Not nice with embedded XSL? You may use JavaScript to separate gracefully // Load XML var xml = new ActiveXObject("Microsoft.XMLDOM") xml.async = false xml.load("cdcatalog.xml") // Load XSL var xsl = new ActiveXObject("Microsoft.XMLDOM") xsl.async = false xsl.load("cdcatalog.xsl") // Transform document.write(xml.transformNode(xsl)) Detect type of browser and load proper XSL doc

40 Ingeniørhøjskolen i Århus Slide 40 af 61 … and server-side as well You may also use server-side programming for this <% 'Load XML set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("cdcatalog.xml")) 'Load XSL set xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath("cdcatalog.xsl")) 'Transform file Response.Write(xml.transformNode(xsl)) %> … and of course – you dont really need XSL then – as the same job may be done in Java, C#, VB etc

41 Ingeniørhøjskolen i Århus Slide 41 af 61 Browser Troubles in Paradise “XSLT in Internet Explorer 5 (and 5.5) is NOT compatible with the official W3C XSL Recommendation.” “Internet Explorer 6 fully supports the official W3C XSLT Recommendation. “ “ Netscape 6 isn't fully supporting the official W3C XSLT Recommendation.” “ Netscape 7 supports the official W3C XSLT Recommendation.” –http://www.w3schools.com/xsl/xsl_browsers.asphttp://www.w3schools.com/xsl/xsl_browsers.asp

42 Ingeniørhøjskolen i Århus Slide 42 af 61 XSL-FO XSL-FO is a language for formatting XML data XSL-FO stands for Extensible Stylesheet Language Formatting Objects XSL-FO is a W3C Recommendation XSL-FO is now formally named XSL XSL-FO is not used extensively with WWW technologies yet, as CSS and XSLT may be used together. This may change however!

43 Ingeniørhøjskolen i Århus Slide 43 af 61 XSL-FO Formatting instructions: Block Margin, Border, Padding, Background Block Styling Attributes: –font-family –font-weight –font-style –font-size –font-variant –text-align –text-align-last –text-indent –start-indent –end-indent –wrap-option (defines word wrap) –break-before (defines page breaks) –break-after (defines page breaks) –reference-orientation (defines text rotation in 90" increments) Which in general will handle the same stuff as CSS

44 Ingeniørhøjskolen i Århus Slide 44 af 61 Other XSL-FO elements Areas, Output, Flow, Pages, List, Tables All of which we will not cover here!

45 Ingeniørhøjskolen i Århus Slide 45 af 61 XSL-FO Example Below is a XSL-FO document And the output would be

46 Ingeniørhøjskolen i Århus Slide 46 af 61 XML, XML-FO & XSLT Example Below is a XML document We apply some XSLT including XML-FO And we get a result

47 XML Programming

48 Ingeniørhøjskolen i Århus Slide 48 af 61 Programmatic XML access? Many API’s & framework for XML handling For Java: –JDOM: http://www.jdom.org/http://www.jdom.org/ –JAXP: http://java.sun.com/xml/jaxp/http://java.sun.com/xml/jaxp/ –SAX: http://www.saxproject.org/http://www.saxproject.org/

49 XML Tools

50 Ingeniørhøjskolen i Århus Slide 50 af 61 Tools XML-Spy: www.xml-spy.comwww.xml-spy.com Sun’s Stylus Studio: www.stylusstudio.comwww.stylusstudio.com Others: –API’s for programmatic access


Download ppt "Præsentation 3: Opsummering af Client-Side Teknologier del 2 Internetteknologi 2 (ITNET2)"

Similar presentations


Ads by Google