XML: OverviewMIS 181.9: Service Oriented
Architecture2nd Semester, 2011-2012
Markup Language
►Use of tags►HTML
►Use of pre-defined tags for formatting►XHTML
►Modified HTML►XML
►No pre-defined tags
Separation of Data and Presentation
►XML contains data►Content► Structure
►No display instructions
Sample
<book><title>Charlie and the Chocolate Factory</title><author>
<lastname>Dahl</lastname><firstname>Roald<firstname>
</author><publisher>Penguin Books</publisher><price>$12.95</price><contentType>Fiction</contentType><format>Paperback</format><isbn>0394910117</isbn>
</book>
Advantages
►Extensible►Open►Nonproprietary
Limitations
►Not a database►Not a programming language
XML File► Text file with the following contents:
► PROLOG► XML Declaration
► <?xml version="1.0" encoding="ISO-8859-1"?> ► Processing instructions► Comments► Document type declaration
► Root element► Tags: Opening, closing► Element instances
► Data► Attributes
Document Model
►Special document►Describes the structure, rules►Used to validate a XML file
►Document Type Definition (DTD)►XML Schema Definition (XSD)
<?xml version=”1.0” encoding=”UTF-8”?><!ELEMENT books (book, totalCost, customer)><!ELEMENT book (bookInfo, salesInfo)><!ATTLIST book contentType (Fiction | Nonfiction) #REQUIRED format (Hardback | Paperback) #REQUIRED><!ELEMENT bookInfo (title, author, publisher, isbn)><!ELEMENT title (#PCDATA)><!ELEMENT author (#PCDATA)><!ELEMENT publisher (#PCDATA)><!ELEMENT isbn (#PCDATA)><!ELEMENT salesInfo (price, itemNumber, date, source, shipping, cost)><!ELEMENT price (#PCDATA)><!ATTLIST price priceType (Retail | Wholesale) #REQUIRED><!ELEMENT itemNumber (#PCDATA)><!ELEMENT date (#PCDATA)><!ELEMENT source EMPTY><!ATTLIST source sourceType (Retail | Wholesale) #REQUIRED><!ELEMENT shipping (#PCDATA)><!ELEMENT cost (#PCDATA)><!ELEMENT totalCost (#PCDATA)><!ELEMENT customer (custNumber, lastName, firstName, address, city, state, zip, phone, email)><!ATTLIST customer custType (newRetail | prevRetail | newWholesale |prevWholesale) #REQUIRED><!ELEMENT custNumber (#PCDATA)><!ELEMENT lastName (#PCDATA)><!ELEMENT firstName (#PCDATA)><!ELEMENT address (#PCDATA)><!ELEMENT city (#PCDATA)><!ELEMENT state (#PCDATA)><!ELEMENT zip (#PCDATA)><!ELEMENT phone (#PCDATA)><!ELEMENT email (#PCDATA)>
DTDs► Defines the ELEMENTs, ATTributes for each element
in a XML document► Can be found within a XML document OR as a
separate file► XML file should include the following in the prolog
► Internal:<!DOCTYPE books [<!ELEMENT books (book+, totalCost, customer)><!ELEMENT book (bookInfo, salesInfo)>...]>► Separate:<!DOCTYPE books SYSTEM “bookstore.dtd”>
XSD: Another Document Model
►DTDs: better if your XML file contains mainly text data
►What if the XML file has different types of data?
►XML files with large amounts of data and varying data types could be better validated with XML Schemas
<xsd:element name=”bookInfo”><xsd:complexType><xsd:sequence><xsd:element ref=”title” type=”xsd:string”/><xsd:element ref=”author”/><xsd:element ref=”publisher”/><xsd:element ref=”publishdate”/ ”type=xsd:date”><xsd:element ref=”isbn”/></xsd:sequence></xsd:complexType></xsd:element><xsd:element name=”title” type=”xsd:string”/><xsd:element name=”customer”><xsd:complexType><xsd:sequence><xsd:element name=”firstName” type=”xsd:string”/><xsd:element name=”lastName” type=”xsd:string”/></xsd:sequence><xsd:attribute name=”custNumber” type=”xsd:positiveInteger”/></xsd:complexType></xsd:element>
XSD example
XML at Work
1. XBRL (http://xbrl.org) – Financial Statements
2. NewsML (http://www.iptc.org) - News
3. MusicXML (http://www.musicxml.org/xml.html) – Musical scores
4. SHML (Structured Health ML) (http://mlp-xml.sourceforge.net/words/Med_kB_lex.html) – medical diagnoses and treatments
Provides standards for exchanging and processing data
Well-formed XML files
►Only one document element► Every open tag must be closed► If element is empty, it has to be closed► Elements must be properly nested► Tag and attribute names are case sensitive► Attribute values must be enclosed on
single/double quotes
XML and Web Services
► Web Services: application components that allow interoperability
► Web Services platform elements► SOAP (Simple Object Access Protocol)
►XML-based protocol used to exchange information via HTTP►Communication protocol
► UDDI (Universal Description, Discovery and Integration)►Directory for storing web services; communicates via SOAP
► WSDL (Web Services Description Language)►XML-based language for describing web services
Top Related