1 / 37

Enterprise Integration

Enterprise Integration. eXtensible Markup Language (XML). Agenda. Introduction to XML Basic Rules of XML DTD Schema. What is XML?. XML stands for E X tensible M arkup L anguage XML is a markup language much like HTML XML was designed to describe data

elita
Download Presentation

Enterprise Integration

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. Enterprise Integration eXtensible Markup Language (XML)

  2. Agenda • Introduction to XML • Basic Rules of XML • DTD • Schema

  3. What is XML? • XML stands for EXtensible Markup Language • XML is a markup language much like HTML • XML was designed to describe data • XML tags are not predefined. You must define 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

  4. The main difference between XML and HTML • XML was designed to carry data. • XML is not a replacement for HTML. • 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.

  5. XML does not DO anything • XML is created to structure, store and to send information. • XML is a cross-platform, software and hardware independent tool for transmitting information.

  6. An example XML document <?xml version="1.0"> <note> <to>Tove</to> <from>Jani</from> <heading set=“1234”>Reminder</heading> <body>Don't forget me this weekend!</body> </note> content attribute element

  7. The Building blocks of XML documents • Elements • Tags • Attributes • Entities • Entities are variables used to define common text. Entity references are references to entities. • PCDATA • Text that will be parsed by a parser. • CDATA • Text that will NOT be parsed by a parser

  8. Basic Rules of XML

  9. Some rule of XML (1/2) • All XML elements must have a closing tag <to>Tove <to>Tove</to> • XML tags are case sensitive <Message>This is incorrect</message> <Message>This is correct</Message> • All XML elements must be properly nested <aaa><bbb>this is incorrect</aaa></bbb> <aaa><bbb>this is correct</bbb></aaa>

  10. Some rule of XML (2/2) • All XML documents must have a root element • Attribute values must always be quoted • <note date=12/11/2002> • <note date="12/11/2002"> • With XML, white space is preserved <root> <child> <subchild>.....</subchild> </child></root>

  11. XML Element Naming • XML elements must follow these 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

  12. XML Attribute • Quote Styles • <person sex="female"> • <person sex='female'> • <gangster name='George "Shotgun" Ziegler'> • <gangster name="George 'Shotgun' Ziegler">

  13. Document Type Definition(DTD)

  14. Document Type Definition • The purpose of a Document Type Definition is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. • A DTD can be declared inside in your XML document, or as an external reference.

  15. Internal DTD declaration • <!DOCTYPE root-element [element-declarations]> note.xml <?xml version="1.0"?><!DOCTYPE note [ <!ELEMENT note(to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]><note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body></note>

  16. External DTD declaration note.xml <?xml version="1.0"?><!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body></note> note.dtd <?xml version="1.0"?><!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>

  17. DTD-Elements (1/3) • Declaring an Element. • <!ELEMENT element-name category> • <!ELEMENT element-name (element-content)> • Empty elements • <!ELEMENT element-name EMPTY> • <!ELEMENT aaa EMPTY><aaa /> • Elements with only character data • <!ELEMENT element-name (#PCDATA)> • <!ELEMENT aaa (#PCDATA)> • Elements with any contents • <!ELEMENT element-name ANY> • <!ELEMENT note ANY>

  18. DTD-Elements (2/3) • Elements with children (sequences) • <!ELEMENT element-name (child-element-name)> • <!ELEMENT element-name (child-element-name,child-element-name,.....)> • <!ELEMENT note (to,from,heading,body)> • Declaring only one occurrence of the same element • <!ELEMENT element-name (child-name)> • <!ELEMENT note (message)> • Declaring minimum one occurrence of the same element • <!ELEMENT element-name (child-name+)> • <!ELEMENT note (message+)>

  19. DTD-Elements (3/3) • Declaring zero or more occurrences of the same element  • <!ELEMENT element-name (child-name*)> • <!ELEMENT note (message*)> • Declaring zero or one occurrences of the same element  • <!ELEMENT element-name (child-name?)> • <!ELEMENT note (message?)> • Declaring either/or content • <!ELEMENT note (to,from,header,(message|body))> • Declaring mixed content • <!ELEMENT note (#PCDATA|to|from|header|message)*>

  20. DTD-Attributes (1/2) • <!ATTLIST element-name attribute-name attribute-type default-value> • <!ATTLIST payment type CDATA "check"> • <payment type="check" /> • attribute-type

  21. DTD-Attributes (2/2) • default-value

  22. XML Schema(XSD)

  23. A Simple Example <?xml version="1.0"?><note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="note.xsd"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body></note> <?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element></xs:schema>

  24. Schema- Simple Types (Elements) • A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. • <xsd:element name="xxx" type="yyy"/> • <xsd:element name="lastname" type="xs:string"/> • Common XML Schema Data Types • Declare Default and Fixed Values for Simple Elements • <xs:element name="color" type="xs:string" default="red"/> • <xs:element name="color" type="xs:string" fixed="red"/>

  25. Schema- Simple Types (Attributes) • <xs:attribute name="xxx" type="yyy"/> • <xs:attribute name="lang" type="xs:string"/> • Declare Default and Fixed Values for Attributes • <xs:attribute name="lang" type="xs:string" default="EN"/> • <xs:attribute name="lang" type="xs:string" fixed="EN"/> • Creating Optional and Required Attributes • <xs:attribute name="lang" type="xs:string" use="optional"/> • <xs:attribute name="lang" type="xs:string" use="required"/> • Restrictions on Attributes

  26. Schema- Complex Types (Elements) • A complex element is an XML element that contains other elements and/or attributes. <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType></xs:element> <xs:element name="employee" type="personinfo"/><xs:complexType name="personinfo"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence></xs:complexType>

  27. XSL • XSL stands for eXtensible Stylesheet Language • XSL consists of three parts: XSLT- is a language for transforming XML documents XPath- is a language for defining parts of an XML document XSL-FO- is a language for formatting XML documents

  28. What is XPath? • XPath is a syntax for defining parts of an XML document • XPath uses paths to define XML elements • XPath defines a library of standard functions • XPath is a major element in XSLT • XPath is not written in XML • XPath is a W3C Standard

  29. XPath Syntax <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd country="USA"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <price>10.90</price> </cd> <cd country="UK"> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <price>9.90</price> </cd> <cd country="USA"> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <price>9.90</price> </cd> </catalog> /catalog/cd/price /catalog/cd/* /catalog/cd[1] /catalog/cd[last()] /catalog/cd[price] /catalog/cd[price=10.90] /catalog/cd[price=10.90]/price /catalog/cd/title | /catalog/cd/artist //@country //cd[@country='UK']

  30. XSLT- Transformation • XSLT is the most important part of the XSL Standards. It is the part of XSL that is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element. • XSLT can also add new elements into the output file, or remove elements. It can rearrange and sort elements, and test and make decisions about which elements to display, and a lot more.

  31. XSLT example <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th align="left">Title</th> <th align="left">Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template></xsl:stylesheet>

  32. XSLT example • <?xml version="1.0" encoding="ISO-8859-1"?> • <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> • <catalog> • <cd> • <title>Empire Burlesque</title> • <artist>Bob Dylan</artist> • <country>USA</country> • <company>Columbia</company> • <price>10.90</price> • <year>1985</year> • </cd> • . • . • . • </catalog>

  33. XSLT example

  34. XSLT element • The <xsl:template> element contains rules to apply when a specified node is matched. • The <xsl:value-of> element can be used to select the value of an XML element and add it to the output stream of the transformation • The XSL <xsl:for-each> element can be used to select every XML element of a specified node set • Note: The value of the required select attribute contains an XPath expression. It works like navigating a file system where a forward slash (/) selects subdirectories.

  35. XSLT element • <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> = (equal) != (not equal) &lt; less than &gt; greater than • <xsl:for-each select="catalog/cd"> <xsl:if test=“price &gt; 10”> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:if> </xsl:for-each> • <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each>

  36. Reference • http://www.zvon.org • http://www.w3schools.com • Validator: • http://www.topologi.com/ • Togologi Schematron Validator

  37. Homework • Choose one product and specify your product in DTD (xml schema). • Use XML to describe you product information content. • Present your product to different roles (customer or supplier) on web by using XSL. • Submit all files (xml, dtd, xml schema, and xsl) with a doc file to specify the context of the homework.

More Related