practical use of xml xml practical use of
play

Practical Use of XML XML Practical Use of Rostislav Titov - PowerPoint PPT Presentation

CERN European Organization for Nuclear Research IT Department e Business Section Practical Use of XML XML Practical Use of Rostislav Titov IT-AIS-EB (e-Business) Section CERN Geneva, Switzerland XML XML eXtensible Markup


  1. CERN – European Organization for Nuclear Research IT Department – e – Business Section Practical Use of XML XML Practical Use of Rostislav Titov IT-AIS-EB (e-Business) Section CERN – Geneva, Switzerland

  2. XML XML eXtensible Markup Language eXtensible Markup Language � SGML (ISO standard, 1986) Mainly for technical documentation � XML (W3C recommendation, 1998) Simplification and enhancement of SGML, wide area of use CERN e – Business

  3. Why Markup? Why Markup? <book lang=“Hungarian”> Markup allows to add Markup allows to add <chapter> information about data Introduction ???????? information about data ????? Text structure <section> </section> structure Markup ???????? <section> </section> </chapter> <chapter> More document markup ?????????????? ?????? ? ??????? ? Reserved attributes ????????????????? ???????? <section> </section> ? ????????? ?? ????????? Processing instructions <section> </section> </chapter> </book> CERN e – Business

  4. XML: Rules : Rules XML <?xml version="1.0" encoding="UTF-8"?> � Header <presentation> � One root element <author> <firstname>Rostislav</firstname> � Tag hierarchy <lastname>Titov</lastname> </author> � Attributes <chapter number="1" title="What is XML"> � Text elements XML (Extensible Markup Language) is … </chapter> � Empty elements <conclusion/> </presentation> Some rules � Element names are case-sensitive � Every opening tag should have a closing tag � Tags cannot intersect (<a><b></a></b>) � Attributes values – in quotes or apostrophes CERN e – Business

  5. XML: Data Transfer : Data Transfer XML � Platform and language independent � Easy to write, easy to process � Understandable for humans and computers � Open standard – Many libraries exist – Lots of literature available – Specialized XML-editors � Possibility to check the document structure CERN e – Business

  6. XML: Data Transfer (2) : Data Transfer (2) XML Example: EDH Transport Request XML External EDH Program � Automatic form generation from external programs � XML as data transfer format � Schema checkup as a warranty of data consistency CERN e – Business

  7. Web Services Web Services � Data transfer between programs on Internet � Open Standard � Platform and language independent (Java, .Net, …) Web XML service SOAP SOAP XML WSDL WSDL WSDL – Web Service Definition Language SOAP – Simple Object Access Protocol CERN e – Business

  8. XML: Data Storage : Data Storage XML � Data structure is kept together with the data � Object “addendum” to relational RDBMS � Structure checkup � Supported by many modern RDBMS – Microsoft SQL Server 2005, Oracle 9i +, – XML Data Type – XML indexes – XML Queries (XQuery etc.) – Data output in XML format CERN e – Business

  9. XML: Data Storage (2) : Data Storage (2) XML Example: EDH Search System Problem: Effective search using arbitrary number of criteria is problematic Our solution: � All documents are stored in XML � Context-specific XML search (Oracle InterMedia) Example: «Find documents created by Slava»: Select DOC_ID from DOC_XML where Contains(XML, “Slava within creator”) > 0; CERN e – Business

  10. XML: Data Transformations : Data Transformations XML � XML can be transformed into HTML, text, PDF, ... – No need for special program solutions – Commercial visual editors exist – Platform independent CERN e – Business

  11. XML- -based Standards based Standards XML � Possibility to formally define the structure � Platform and language independent � Understandable for humans and computers � Possibility to use XML technologies (XSLT transformations, XQuery queries)… – WSDL (Web Services Definition Language) – SOAP (Simple Object Access Protocol) – XHTML (HTML that complies to XML rules) – SVG (Scalable Vector Graphics) – ebXML (XML for e-Business) – … CERN e – Business

  12. Formal Structure Definition Formal Structure Definition � There are ways to define XML structure formally Obsolete! Obsolete! Not for new Not for new development development • DTD (Document Type Definition) • XML Schema CERN e – Business

  13. XML Schema: : Possibilities Possibilities XML Schema � Check element presence and their order � Sequences and choices � Number of repetitions for elements and groups � Attributes and their presence � Type of elements and attributes � Restrictions for elements and attributes � Default values � Unique constraints � ... CERN e – Business

  14. XML- -schema schema: : when it is needed when it is needed? ? XML � Formal structure definition for future reference � Programmers may rely on data consistence � Authors may check XML validness in advance CERN e – Business

  15. XML- -schema schema: : when NOT needed when NOT needed? ? XML � When we know in advance that XML is valid � When we do not care about document validness � When maximum processing speed is required � Small “throw away” projects CERN e – Business

  16. XPath: : XML Navigation XML Navigation XPath � Access to XML elements � Result of an XPATH-expression can be: � XML Node � String � Node Set � Number � Boolean � Empty Set C:\presentation\author\firstname /presentation/author/firstname CERN e – Business

  17. XPath Path: Examples : Examples X <cern> <dg><person>R. Aymar</person></dg> <department name=“PH”> � Find the DG’s name <dh><person>W-D. Schlatter</person></dh> </department> /cern/dg/person/text() <department name=“IT”> <dh><person>W. von Rueden</person></dh> <group name=“IT-AIS”> � Find all departments <gl><person>R. Martens</person></gl> </group> /cern/department/@name <group name=“IT-CO”> <gl><person>D. Myers</person></gl> </group> � Find all people <group name=“IT-IS”> <gl><person>A. Pace</person></gl> </group> //person </department> </cern> � Find the name of DH of IT /cern/department[@name=“IT”]/dh/person/text() � Find how many groups has a department where R. Martens works count(//gl/person[starts-with(., 'R. Martens')]/../../../group) CERN e – Business

  18. XPath: Examples : Examples ( (8 8) ) XPath Example: Event Handling System Handling System Events Subscriptions XML XPath XPath XML Check events against XPath XML Notifications «I want to see all documents for more than 600 CHF» / document [amount > 600] CERN e – Business

  19. XPath: Program Use : Program Use XPath XPath System.out.println(((XMLDocument)xml).selectSingleNode( "/config/report[@name='Slava']/title/text()").getNodeValue()); DOM Model Element root = xml.getDocumentElement(); Node child; for (child= root.getFirstChild(); child != null; child = child.getNextSibling()) if (child.getNodeName().equals ("report") && ( (Element)child ).getAttribute("name").equals ("Slava")) break; for (child = ((Element)child).getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeName().equals ("title") ) { for (Node child2 = child.getFirstChild(); child2 != null; child2 = child2.getNextSibling()) if ( child2 instanceof Text) System.out.println(( (Text)child2 ).getData().trim()); } CERN } e – Business

  20. XQuery y – –XML XML Query Language Query Language XQuer � XQuery is SQL for XML – Database independent – Easy to use � Supported by popular RDBMS (Microsoft SQL Server 2005, Oracle 9i and10g) � Based on XPath, supports document sets CERN e – Business

  21. XSLT: XML Transformations XSLT: XML Transformations � Transforms XML to HTML, text or other XML � XSLT 1.0 (Current), XSLT 2.0 (Draft) � XSLT is a “Human Interface” to XML � Supported by Web Browsers XSLT CERN e – Business

  22. XSLT: Simplified Structure XSLT: Simplified Structure � XSLT is an XML file � Active usage of XPath expressions <html> xsl:stylesheet Evaluate XPath and print value <body> xsl:value-of … xsl:template xsl:value-of … … xsl:apply-templates xsl:template … Apply templates </body> Apply a template to other elements to the given element <html> CERN e – Business

  23. XSLT: Possibilities XSLT: Possibilities Conditions (<xsl:if>) � Loops (<xsl:for-each>) � � Variables (<xsl:variable>) Sorting (<xsl:sort>) � Numbering [1., 1.1., 1.1.?, 2.,] (<xsl:number>) � Number formatting (format-number()) � Multiple step processing (mode) � � String manipulations (via XPath) XSLT 2.0 (Draft) XPath 2.0 � Custom functions � Regular expressions � � Date and time formatting Groupings � CERN e – Business

Recommend


More recommend