Presentation on theme: "Presentation 6: Introduction to XML and related technologies – for use with SOAP / WSDL = Web services."— Presentation transcript:
Presentation 6: Introduction to XML and related technologies – for use with SOAP / WSDL = Web services
2 Outline Why an XML presentation? W3C & legacy of XML – ultra short XML markup and Namespaces DTD’s XML Schemas DOM/SAX The SOAP connection
3 Why an XML presentation? Because SOAP, WSDL & UDDI is based on XML technologies Future “Home-brew” framework based on XML? Important to understand how the API’s work Parsing mechanisms DOM SAX Why its slow ;)
4 W3C & the legacy of XML World Wide Consortium Founded 1994 Standardizations on the Internet First Chairman: Tim Berners-Lee Boards of members submits proposals Ensures standardization of WWW technologies Like: XHTML, XML, XSL, CSS, SOAP, WAP etc. Members: Microsoft, IBM, SUN, Oracle and many others Legacy: Standard Generalized Markup Language (SGML) Same legacy as HTML
5 XML markup eXtended Markup Language XML based on SGML (subset of) Like SGML for data & structure not layout (as HTML) XML targets the Internet – but is also being used for application exchange formats (Open Office, XMI) – CSVs XML is an W3C Recommendation Structure decided by DTD or Schema (more later) Wide spread support for XML
6 Presenting XML documents First standalone XML document and its component Note: XML document are “Well-formed” Please visit for in-depth examples of XML usagehttp://www.w3schools.com/default.asp
Ingeniørhøjskolen i Århus Slide 7 af 32 Article.xml Simple XML 9 10 September 19, Tem 14 Nieto XML is pretty easy Once you have mastered XHTML, XML is easily 20 learned. You must remember that XML is not for 21 displaying information but for managing information Optional XML declaration. Element article is the root element. Elements title, date, author, summary and content are child elements of article.
8 Browser displaying XML (unformatted) IE5.5 displaying article.xml.
9 Use of XML Namespaces XML namespaces used to avoid naming conflicts When several different elements are involved isnt always a book Keyword ”xmlns”
Ingeniørhøjskolen i Århus Slide 10 af 32 Namespace.xml A book list A funny picture Keyword xmlns creates two namespace prefixes, text and image. URIs (Uniform Resource Identifiers) ensure that a namespace is unique.
Ingeniørhøjskolen i Århus Slide 11 af 32 Defaultnamespace.xml A book list A funny picture Default namespace. Element file uses the default namespace. Element file uses the namespace prefix image.
12 DTDs Document Type Definition Extended Backus-Naur Form Defines how an XML document is structured Required elements Nesting of elements Does not define types or behavior If DTD is used – some parsers can decide if XML document is “valid” – which is more than just “wellformed”
Ingeniørhøjskolen i Århus Slide 13 af 32 Letter.dtd 6 7 The ELEMENT element type declaration defines the rules for element letter. The plus sign ( + ) occurrence indicator specifies that the DTD allows one or more occurrences of an element. (2 contacts in our example) The contact element definition specifies that element contact contains child elements name, address1, address2, city, state, zip, phone and flag — in that order.
Ingeniørhøjskolen i Århus Slide 14 af 32 Letter.dtd 6 7 The ATTLIST element type declaration defines an attribute (i.e., type ) for the contact element. Keyword #IMPLIED specifies that if the parser finds a contact element without a type attribute, the parser can choose an arbitrary value for the attribute or ignore the attribute and the document will be valid. Flag #PCDATA specifies that the element can contain parsed character data (i.e., text). Assignment: 5 min. – make a Letter XML document that is: -Well-formed (how would an XML Validator check this?) -Valid (how would an XML Validator check this?)
Ingeniørhøjskolen i Århus Slide 15 af 32 Letter.xml John Doe Main St Anytown 15 Anystate Joe Schmoe 23 Box Any Ave. 25 Othertown 26 Otherstate
Ingeniørhøjskolen i Århus Slide 16 af 32 Letter.xml 32 Dear Sir: It is our privilege to inform you about our new 35 database managed with XML. This new system allows 36 you to reduce the load of your inventory list server by 37 having the client machine perform the work of sorting 38 and filtering the data. 39 Sincerely 40 Mr. Doe 41 42
17 XML Schema DTD works OK – but Is in Ex. Backus-Naur Form – why not use XML? Cannot declare the type of an element hundrede kr Could give problems Several other problems W3C XML Schema Use XML to describe the structure of XML documents … Possible to give type information to XML definitions Not supported by all parsers yet Will live besides DTDs for a while
Ingeniørhøjskolen i Århus Slide 18 af 32 Book.xsd Element element defines an element to be included in the XML document structure. A BookType has an Element named Title of Type “xsd:string” – which is defined at “http://www.w3.org/2000/10/XMLSchema”
Ingeniørhøjskolen i Århus Slide 19 af 32
20 How to use XML? Need a parser (or a parser API) to access XML (as with CSV) Two commonly used methods: DOM (Document Object Model) W3C Recommendation Makes a tree structure representation of an XML document in memory SAX (Simple API for XML) Supported by diff. vendors Parses document line by line and sends events to subscribers Needs to parse every time access to XML document is needed DOM is better for Slow to load XML document (need all) Quick access to random read or update of XML (like WWW browser - BOM) Requires a lot of memory (need to hold entire XML in mem) SAX is better for Applications subscribing to certain parts of XML (event subscription) Slow for random access to XML document (must parse every time)
22 DOM Tree Structure Tree structure of an XML document (left) … or HTML (right) document …table tbdoy … …… tr td tekst tekst ….
Ingeniørhøjskolen i Århus Slide 24 af Simple XML 9 10 September 19, Tem 14 Nieto XML is pretty easy XML is easily 20 learned. You must remember that XML is not for 21 displaying information but for managing information XML document – Article.XML
25 DOM Methods firstName lastName contents summary author date title article Tree structure for article.xml.
Ingeniørhøjskolen i Århus Slide 26 af 32 DOMExample.ht ml 1 2 A DOM Example
Ingeniørhøjskolen i Århus Slide 28 af 32 Program Output
29 The SOAP Connection SOAP, WSDL, UDDI uses: XML Namespaces and Schemas Original idea behind Web services Connection through the Internet Good sense to use XML – W3C child Everyone loves W3C practical solutions “that work”