1 / 41

Orientatie XML2 Gert van der Steen Palstar bv University of Utrecht

Orientatie XML2 Gert van der Steen Palstar bv University of Utrecht. Memo als XML document. <?XML version=“1.0” encoding=“ISO-8859-1” ?> <memo status="draft” reference =“GvdS/19991108/3”> <idinfo> <to>Peter Baars</to> <to>Connie Gaiser</to> <from>Gert van der Steen</from>

dani
Download Presentation

Orientatie XML2 Gert van der Steen Palstar bv University of Utrecht

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Orientatie XML2 Gert van der Steen Palstar bv University of Utrecht

  2. Memo als XML document <?XML version=“1.0” encoding=“ISO-8859-1” ?> <memo status="draft” reference =“GvdS/19991108/3”> <idinfo> <to>Peter Baars</to> <to>Connie Gaiser</to> <from>Gert van der Steen</from> <date>November 8 1999</date> <subject>Personal holiday</subject> </idinfo> <body> <para>All personnel are entitled to one personal day per calendar year.</para> <para>If you have any questions, please forward them to my office.</para> </body> </memo> memo idinfo body para para

  3. Memo als Document Boom / Componenten status="draft” reference =“GvdS/19991108/3” memo idinfo body to to from date subject para para “Peter Baars” “Connie Gaiser” “Gert van der Steen” “November 8 1999” “Personal holiday” “All personnel are entitled to one personal day per calendar year.” “If you have any questions, please forward them to my office.”

  4. Diagram van DTD voor Memo status reference

  5. XML DTD voor Memo <!DOCTYPE memo [ <!ELEMENT memo (idinfo, body) > <!ATTLIST memo status (final | draft) "final” reference CDATA > <!ELEMENT idinfo (to+, from, date, subject?) > <!ELEMENT body (para+) > <!ELEMENT to (#PCDATA) > <!ELEMENT from (#PCDATA) > <!ELEMENT date (#PCDATA) > <!ELEMENT subject (#PCDATA) > <!ELEMENT para (#PCDATA) > ] >

  6. XML W3C Schema voor Memo 1/2 <xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified"> <xsd:complexType name="bodyType"> <xsd:sequence> <xsd:element ref="para" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:element name="date" type="xsd:string"/> <xsd:element name="from" type="xsd:string"/> <xsd:complexType name="idinfoType"> <xsd:sequence> <xsd:element ref="to" maxOccurs="unbounded"/> <xsd:element ref="from"/> <xsd:element ref="date"/> <xsd:element ref="subject" minOccurs="0"/> </xsd:sequence> </xsd:complexType>................................................................. Vervolg ..>

  7. XML W3C Schema voor Memo 2/2 <xsd:element name="memo"> <xsd:complexType> <xsd:sequence> <xsd:element name="idinfo" type="idinfoType"/> <xsd:element name="body" type="bodyType"/> </xsd:sequence> <xsd:attribute name="status" use="default" value="final"> <xsd:simpleType> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="final"/> <xsd:enumeration value="draft"/> </xsd:restriction> </xsd:simpleType> </xsd:attribute> <xsd:attribute name="reference" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> <xsd:element name="para" type="xsd:string"/> <xsd:element name="subject" type="xsd:string"/> <xsd:element name="to" type="xsd:string"/> </xsd:schema>

  8. Gestandaardiseerde operaties op XML Documenten

  9. DOM 1/2 • application programming interface (API) for HTML and XML documents. • defines the way a document is accessed and manipulated • designed to be used with any programming language • uses the OMG IDL (Object Management Group Interface Description Language) as defined in CORBA 2.2 • strongly supported by Microsoft's Office2000 suite and other vendors • programmers can • create documents • navigate their structure • retrieve, add, modify, or delete elements and content

  10. DOM 2/2 Example in Javascript: add as the leftmost child of the top element the element “L”: var newElem = ActiveDocument.createElement("L"); var topElem = ActiveDocument.documentElement; topElem.insertBefore(newElem, topElem.firstChild);

  11. XSL = XSL-FO and XSLT • XSL-FO: formatting objects language • W3C Proposed Recommendation, not a standard yet ! • Alternative to CSS for client rendering • Layout companion standard for XSLT • Supports high-end page layout (e.g. multicolumn, rotated text) • Beta-quality implementations (convert to PDF), e.g. • RenderX FO2PDF URL http://www.renderx.com/ • XSLT: transformation language for XSL • W3C Recommendation • Alternative for DOM, Balise/Omnimark ... • XML to HTML, FO, or other XML output languages.

  12. XSLT operation XML Stylesheet XSLT/XSL XSL Formatting Objects XSLT Engine Source Node Tree (Templates) Source XSL Formatting Objects XML Source Node Tree Result Node Tree Instruction Execution Result XML XML Non- XML

  13. XSLT Transformation in Server or in Browser Display Display XML XSLT Process XSLT Process Web Host Transformation script XSLT XML Browser Source document HTML Browser Transformation script XSLT

  14. XSL-FO: Multilingual document

  15. XSL-FO : With stylesheet for Japanese reader

  16. XSL-FO : With stylesheet for English reader

  17. XSL-FO features 1/2 • an XSL stylesheet defines the presentation of an XML document • a style sheet can control the look and feel of a single document or a whole website • incorporates XSLT: rule-based translation of XML documents into other type of documents, like HTML • incorporates the ECMAScript language (standardized JavaScript) for data manipulation, allowing the translation of XML objects into any desired output

  18. XSL-FO features 2/2 • Different and personalized style sheets can be applied to the same XML document for different purposes and different output media, such as display, print, handheld devices, etc. • completely internationalized -left-to-right, right-to-left, and top-to-bottom scripts can occur mixed in the same document • equipped with professional page layout facilities such as multiple column sets, rotated text areas, float zones, etc. • history: subset of DSSSL with alternative syntax, plus key concepts from CSS

  19. XSL Formatting Objects 1/4

  20. XSL Formatting Objects 2/4

  21. XSL Formatting Objects 3/4

  22. XSL Formatting Objects 4/4

  23. 4 Soap 1/2 • Maakt gebruik van XML • Ondersteunt volledige berichtuitwisseling als wel vraag- en antwoordprotocollen voor interactieve applicaties • Te gebruiken voor zowel synchrone als asynchrone systemen • Realistische oplossing voor behoeften van eenvoudige, gedistribueerde, multidisciplinaire, multiplatformsystemen • Koppeling met http, later ook met MSMQ, MQSeries, RPC-systemen, incl. TP-monitoren als Cics, MTS en Tuxedo • 3 delen • envelop: wat zit er in bericht, wat moet er mee gebeuren • schema’s voor de berichten • conventie voor representatie van RPC’s en hun antwoorden • t.b.v. interfaces met andere systemen

  24. 4 Soap 2/2 • Defined semantics of what happens when a computer receives a SOAP message • Soap servers will publish contracts about what they will and will not accept • A lot simpler then Corba or Dcom • But security worries • A Soap message travels to multiple computers, who all perform some processing

  25. XSLT stylesheet • XSLT “Stylesheet” eigenlijk: “Transformationsheet” • Zelf een XML document • Standaard XML heading • Standaard XSLT heading • Rules (“templates”) • Toegespitst op boomstructuur

  26. Template rule <xsl:template match=“paragraph”> <p> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match=“/”> <html><body> <xsl:apply-templates/> </body></html> </xsl:template>

  27. Xpath • Subtaal, o.a. gebruikt binnen XSLT • Xpath expressie: • Identificatie van document onderdelen • Boolean conditions • Numerieke berekeningen • String manipulatie

  28. Knopen in een XML boom • Root knoop • Element knoop • Tekst knoop • Attribuut knoop • Commentaar knoop • Processing instruction knoop • Namespace knoop

  29. Memo als Document Boom / Componenten Root knoop Attribuut knoop memo reference =“GvdS/19991108/3” status="draft” Element knoop idinfo body to to from date subject para para “Peter Baars” “Connie Gaiser” “Gert van der Steen” “November 8 1999” “Personal holiday” “All personnel are entitled to one personal day per calendar year.” “If you have any questions, please forward them to my office.” Tekst knoop

  30. Transformatie methoden 1/2 • Recursieve afhandeling (“recursive descent”) • Voor elk element een template rule • Elk element produceert gewenste output • Elk element bevat <xsl:apply-templates> call • Output gegevens hebben ongeveer dezelfde structuur en volgorde als de input • Ook wel push processing genoemd

  31. Example Push Processing (XML->XML) XML in: <employee> <name>J. Smith</name> <number>123</number> </employee> XML out: <PERSON><NUM>123</NUM> <NM>J. Smith</NM></PERSON> XSLT: <xsl:template match=“employee”> <PERSON> <NUM><xsl:apply-templates select=“number”/></NUM> <NM><xsl:apply-templates select=“name”/></NM> </PERSON> </xsl:template>

  32. XSLT voorbeelden 1 Bekijk in subdir ‘XSLT_voorbeelden’ m.b.v. XMLSpy (het openen van de *.spp projecten is voldoende): • Booklist.(spp, xml, xsl) Dit voorbeeld illustreert het genereren van een HTML tabel vanuit een XML-lijst. • Brief.(spp, xml, xsl) Dit voorbeeld illustreert het presenteren van een XML document in HTML.

  33. Transformatie methoden 2/2 • Gerichte afhandeling • Expliciete keuze van volgorde door adressering in de invoer-boom • Ook wel pull processing genoemd • Adressering middels Xpath expressies

  34. Voorbeelden XPath expressies 1/2 a. Alle elementen //* b. Alle “book” elementen //book c. Alle “author” elementen binnen een “book” element //book/author d. Alle “book” elementen die een “author” element bevatten //book[author] e. Alle “category” attributen bij “book” elementen //book/@category f. Alle “book” elementen die voorzien zijn van een “category” attribuut //book[@category] g. Alle “book” elementen met “fiction” als attribuutwaarde voor “category” //book[@category=”fiction”] h. Alle “category” attributen met “fiction” als waarde //book/@category[.=”fiction”]

  35. Voorbeelden XPath expressies 2/2 i. Het eerste “book” element //book[1] j. Het 1-na-laatste “book” element //book[last()-1] k. Ieder tweede “book” element //book[not(position() mod 2)] l. Het eerste en het laatste “book” element //book[position()=1 or position()=last()] m. De tekst van de boektitels //book/title/text() n. Alle boeken met een prijs onder de 10 (dollar) //book[price<10] o. Alle boeken waarvan de auteursnaam met een “W” begint //book[starts-with(author, “W”)] p. De (tekst van de) titels van boeken met een prijs onder de 10 (dollar) //book[price<10]/title/text()

  36. Xpath proberen • Voorbeelden in “XPathpraktikum.doc”: • Visualiseren van geselecteerde nodesets in Xpath.xml • Voorbeeld: “alle ‘author’ elementen binnen een ‘book’ element”: “//book/author” <books> <book category="reference"> <author>Rees, N.</author> <title>Sayings of the Century</title> <price>8.95</price> </book> <book category="fiction"> <author>Waugh, E.</author> <title>Sword of Honour</title> <price>12.99</price> </book>

  37. Xpath navigation • Child, descendant, descendant-or-self • parent, ancestor, ancestor-or-self • following, following-sibling • preceding, preceding-sibling • attribute • namespace • self

  38. Xpath variabelen • Globaal en lokaal • Statisch • <xsl:variable name=“waarde” select=“10”> • Aanroep binnen expressie: $waarde • Als parameter: • <xsl:param> • <xsl:with-param>

  39. XSLT voorbeelden 2 Bekijk in subdir ‘XSLT_voorbeelden’ m.b.v. XMLSpy (het openen van de *.spp projecten is voldoende): • (League.spp, Soccer.xml, League.xsl) Dit voorbeeld illustreert het gebruik van numerieke functies (count(), sum()) om verschillende berekeningen uit te voeren op de resultaten van een reeks voetbalwedstrijden. • (List-elements.spp, List-elements.xsl, List-elements.xsl) Dit voorbeeld laat alle elementen uit een XML-bestand zien, gespecificeerd met prefix, local name en namespace URI. Kan op ieder XML-document toegepast worden, dus ook op zichzelf. • (Resorts.spp, Resorts.xml, Resorts.xsl) Dit voorbeeld illustreert de creatie van links, incl. het genereren van unieke id’s.

  40. XSLT proberen 3 Bekijk in subdir ‘XSLT_voorbeelden’ m.b.v. XMLSpy (het openen van het *.spp project is voldoende): • (Contact.spp, Contact.xml, Contact_list.xsl) Dit voorbeeld illustreert het genereren van een interactief HTML document, inclusief Javascript, vanuit een XML document. • Het voorbeeld is genomen uit Deitel, ch. 27. Zie aldaar voor de uitleg. • Referentie: • Deitel, Deitel & Nieto, “e-Business & e-Commerce, How to Program”, Prentice-Hall, 2001, ISBN 0-13-028419-X

  41. Text Books • Michael Kay, “XSLT Programmer’s Reference”, Wrox, 2000, ISBN 1-861003-12-9 • Neil Bradley, “The XSL Companion”, Addison Wesley, 2000, ISBN 0-201-67487-4

More Related