37
Enterprise Integration eXtensible Markup Languag e (XML)

Enterprise Integration

  • Upload
    elita

  • View
    38

  • Download
    5

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Enterprise Integration

Enterprise Integration

eXtensible Markup Language(XML)

Page 2: Enterprise Integration

AgendaIntroduction to XMLBasic Rules of XMLDTDSchema

Page 3: Enterprise Integration

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

Page 4: Enterprise Integration

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.

Page 5: Enterprise Integration

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

Page 6: Enterprise Integration

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>

element

content

attribute

Page 7: Enterprise Integration

The Building blocks of XML documents

Elements Tags AttributesEntities

Entities are variables used to define common text. Entity references are references to entities.

PCDATAText that will be parsed by a parser.

CDATA Text that will NOT be parsed by a parser

Entity References

Character

&lt; <

&gt; >

&amp; &

&quot; “

&apos; ‘

Page 8: Enterprise Integration

Basic Rules of XML

Page 9: Enterprise Integration

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>

Page 10: Enterprise Integration

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>

Page 11: Enterprise Integration

XML Element NamingXML 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

Page 12: Enterprise Integration

XML AttributeQuote Styles

<person sex="female"><person sex='female'>

<gangster name='George "Shotgun" Ziegler'>

<gangster name="George 'Shotgun' Ziegler">

Page 13: Enterprise Integration

Document Type Definition(DTD)

Page 14: Enterprise Integration

Document Type DefinitionThe 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.

Page 15: Enterprise Integration

Internal DTD declaration<!DOCTYPE root-element [element-declarations]>

<?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>

note.xml

Page 16: Enterprise Integration

External DTD declaration

<?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>

<?xml version="1.0"?><!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>

note.xml

note.dtd

Page 17: Enterprise Integration

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>

Page 18: Enterprise Integration

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+)>

Page 19: Enterprise Integration

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)*>

Page 20: Enterprise Integration

DTD-Attributes (1/2)<!ATTLIST element-name attribute-name attribute-type default-value>

<!ATTLIST payment type CDATA "check"> <payment type="check" />

attribute-typeValue Explanation

CDATA The value is character data

(en1|en2|..) The value must be one from an enumerated list

ID The value is a unique id

IDREF The value is the id of another element

IDREFS The value is a list of other ids

NMTOKEN The value is a valid XML name:letters, digits and ".", "-", "_", ":"

NMTOKENS The value is a list of valid XML names

Page 21: Enterprise Integration

DTD-Attributes (2/2)default-value

Value Explanation

value The default value of the attribute<!ATTLIST square width CDATA "0"><square width="100" />

#REQUIRED The attribute value must be included in the element<!ATTLIST person number CDATA #REQUIRED><person number="5677" /> <person />

#IMPLIED The attribute does not have to be included<!ATTLIST contact fax CDATA #IMPLIED><contact fax="555-667788" /><contact/>

#FIXED value

The attribute value is fixed<!ATTLIST sender company CDATA #FIXED "Microsoft">

<sender company="Microsoft" /><sender company="W3Schools" />

Page 22: Enterprise Integration

XML Schema(XSD)

Page 23: Enterprise Integration

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>

Page 24: Enterprise Integration

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"/>

xsd:string xsd:integer xsd:datexsd:decimal xsd:boolean xsd:time

Page 25: Enterprise Integration

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

Page 26: Enterprise Integration

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>

Page 27: Enterprise Integration

XSLXSL stands for eXtensible Stylesheet LanguageXSL 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

Page 28: Enterprise Integration

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

Page 29: Enterprise Integration

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']

Page 30: Enterprise Integration

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.

Page 31: Enterprise Integration

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>

Page 32: Enterprise Integration

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>

Page 33: Enterprise Integration

XSLT example

Page 34: Enterprise Integration

XSLT elementThe <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 setNote: The value of the required select attribute contains an XPath expression. It works like navigating a file system where a forward slash (/) selects subdirectories.

Page 35: Enterprise Integration

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>

Page 36: Enterprise Integration

Referencehttp://www.zvon.org http://www.w3schools.comValidator:

http://www.topologi.com/Togologi Schematron Validator

Page 37: Enterprise Integration

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.