Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet Technology 1 Presentation 10: XML technologies.

Similar presentations


Presentation on theme: "Internet Technology 1 Presentation 10: XML technologies."— Presentation transcript:

1 Internet Technology 1 Presentation 10: XML technologies

2 Ingeniørhøjskolen i Århus Slide 2 af 34 Outline W3C & heritage of XML XML Markup & Namespaces DTD’s XML Schemas DOM/SAX

3 Ingeniørhøjskolen i Århus Slide 3 af 34 W3C & the legacy of XML World Wide Consortium –Founded 1994 to lead the WWW into the future –For standardizations on the Internet –First Chairman: Sir Tim Berners-Lee –Run by Chairman, Director & Staff –Boards of members submits proposals and work to formulate –Ensures standardization of WWW technologies Like: XHTML, XML, XSL, CSS, SOAP, WAP etc. Members: Microsoft, IBM, SUN, Oracle –http://www.w3c.orghttp://www.w3c.org

4 Ingeniørhøjskolen i Århus Slide 4 af 34 SGML Standard Generalized Markup Language (ISO 8879:1986 SGML)ISO ISO-standard technology for defining generalized markup languages for documentsISOmarkup languages Original SGML, which was accepted in October 1986 Based on Generalized Markup Language (GML) GML was developed in the 1960s by Charles Goldfarb, Edward Mosher and Raymond LorieCharles GoldfarbEdward Mosher Raymond Lorie This is a front-of-screen photograph from a 3279 mainframe-attached screenmainframe LEXX Editor for the OED (1985/1986), sample entry (segment of) This is a front-of-screen photograph from a 3279 mainframe-attached screenmainframe LEXX Editor for the OED (1985/1986), sample entry (segment of)

5 Ingeniørhøjskolen i Århus Slide 5 af 34 XML markup eXtended Markup Language XML based on SGML (subset of) Like SGML for 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 –http://www.w3.org/TR/REC-xml Structure decided by DTD or Schema (more later) Wide spread support for XML (hype)

6 Ingeniørhøjskolen i Århus Slide 6 af 34 Examples of XML usage GUI for “thin” clients –XHTML –WML (we shall look closer at this shortly) Inter-process communication –SOAP –BizTalk –ebXML Databases –XML Databases –XQuery –XLink, XPointer Representation / exchange of data –XMI (UML diagrams exchange format) –MathXML –CML –Proprietary Example: EPJ XML –good thing when every danish county makes its own Easy to comprehend due to the nature of XML Open office

7 Ingeniørhøjskolen i Århus Slide 7 af 34 Presenting XML documents Examples fetched from DEITEL First we will look at a standalone XML document and its components (elements) –Note: XML document needs to be Well formed (must be syntactically correct) Please go to http://www.w3schools.com/default.asp to see more in-depth examples of XML usage http://www.w3schools.com/default.asp

8 Ingeniørhøjskolen i Århus Slide 8 af 38 Article.xml 1 2 3 4 5 6 7 8 Simple XML 9 10 September 19, 2001 11 12 13 Tem 14 Nieto 15 16 17 XML is pretty easy. 18 19 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. 22 23 24 Element article is the root element. Elements title, date, author, summary and content are child elements of article. Element author is a “container element” contains Childs, firstName and lastName

9 Ingeniørhøjskolen i Århus Slide 9 af 34 Browser displaying XML (unformatted) IE5.5 displaying article.xml.

10 Ingeniørhøjskolen i Århus Slide 10 af 34 Small “stop up” exercise 1 We will do some small common exercises. Use 5 min. to this exercise: Setup a XML document, containing data about your merits at IHA and other institutions –Incl. “group of subjects” to which you have participated and your possible trainee period –The courses might have a name, a code, a type, a course holder, type of assessment, and other topics you find of relevance. Start with 2-3 courses –Your course gradings how do they relate to the courses and what are they?

11 Ingeniørhøjskolen i Århus Slide 11 af 34 Use of XML Namespaces XML namespaces used to avoid naming conflicts When several different elements are involved isn't always a book Keyword ”xmlns” Remember xmlns is nothing more than organizing names in spaces.

12 Ingeniørhøjskolen i Århus Slide 12 af 38 Namespace.xml 1 2 3 4 5 6 8 9 10 A book list 11 12 13 14 A funny picture 15 16 17 18 Keyword xmlns creates two namespace prefixes, text and image. URIs (Uniform Resource Identifiers) ensure that a namespace is unique. Attribute

13 Ingeniørhøjskolen i Århus Slide 13 af 38 Defaultnamespace.xml 1 2 3 4 5 6 8 9 10 A book list 11 12 13 14 A funny picture 15 16 17 18 Default namespace. Element file uses the default namespace. Element file uses the namespace prefix image.

14 Ingeniørhøjskolen i Århus Slide 14 af 38 Stop up exercise 2 Use Namespace(s) in your XML document (from s.u. exc. 1)

15 Ingeniørhøjskolen i Århus Slide 15 af 38 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 behaviour If DTD is used – some parsers can decide if XML document is “valid” – which is more than just “well formed”

16 Ingeniørhøjskolen i Århus Slide 16 af 38 Letter.dtd 1 2 3 4 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 contacs 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. #CDATA Unparsed character #PCDATA Parsed character

17 Ingeniørhøjskolen i Århus Slide 17 af 38 Letter.dtd 1 2 3 4 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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). See letter.xml next page

18 Ingeniørhøjskolen i Århus Slide 18 af 38 Letter.xml 1 2 3 4 5 6 7 8 9 10 11 John Doe 12 123 Main St. 13 14 Anytown 15 Anystate 16 12345 17 555-1234 18 19 20 21 22 Joe Schmoe 23 Box 12345 24 15 Any Ave. 25 Othertown 26 Otherstate 27 67890 28 555-4321 29 30 31

19 Ingeniørhøjskolen i Århus Slide 19 af 38 Letter.xml Program Output 32 Dear Sir: 33 34 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 http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/welcome.asp

20 Ingeniørhøjskolen i Århus Slide 20 af 38 Program Output http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/welcome.asp Or from http://kurser.iha.dk/eit/net1/iw3_htp_3e_examples/ch20_XML/xml_validator.exe

21 Ingeniørhøjskolen i Århus Slide 21 af 38 Stop up exercise 3 Take 5 minutes: Setup a DTD, that confirms to your xml document educations.xml and extend the xml document with DTD information

22 Ingeniørhøjskolen i Århus Slide 22 af 38 XML Schema DTD works OK – but –Is in Ex. Backus-Naur Form – why not use XML to describe? –Cannot declare a type to 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

23 Ingeniørhøjskolen i Århus Slide 23 af 38 Book.xsd 1 2 3 4 5 6 9 10 11 12 13 15 16 17 18 19 20 21 Namespace prefix. Element element defines an element to be included in the XML document structure. Attributes name and type specify the element ’s name and data type, respectively. Element complexType defines an element type that has a child element named book. Attribute minOccurs specifies that books must contain a minimum of one book element. The resulting namespace.

24 Ingeniørhøjskolen i Århus Slide 24 af 38 Book.xsd 1 2 3 4 5 6 9 10 11 12 13 15 16 17 18 19 20 21 A BookType has an Element named Title of Type “xsd:string” – which is defined at “http://www.w3.org/2000/10/XMLSchema”

25 Ingeniørhøjskolen i Århus Slide 25 af 38

26 Ingeniørhøjskolen i Århus Slide 26 af 38 Stop up exercise 4 Take a 5 minutes discussion to your neighbor about how to replace the DTD with a Schema

27 Ingeniørhøjskolen i Århus Slide 27 af 38 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) Think at a XML documents as a kind of persistent data (“a database”)

28 Ingeniørhøjskolen i Århus Slide 28 af 38 What is DOM DOM: Document Object Model –http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML- 20030109/http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML- 20030109/ W3C definition: –Standard for accessing structured documents –Core DOM used with XML –HTML DOM used with HTML –Representation of an object as an object tree structure –Provides a uniform interface for programming and scripting languages –API’s available for JavaScript, Java, C++, C# etc.

29 Ingeniørhøjskolen i Århus Slide 29 af 38 DOM Tree Structure Tree structure of an XML document (left) … or HTML (right) document …table tbody … …… tr td tekst tekst ….

30 Ingeniørhøjskolen i Århus Slide 30 af 38 Example – using DOM on Article.xml We have looked at Article.xml We Will: –Look at the Article.xml document again –Look at the Tree Structure formed by loading it into a DOM –Use JavaScript to work on it

31 Ingeniørhøjskolen i Århus Slide 31 af 38 1 2 3 4 5 6 7 8 Simple XML 9 10 September 19, 2001 11 12 13 Tem 14 Nieto 15 16 17 XML is pretty easy. 18 19 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. 22 23 24 XML document – Article.XML

32 Ingeniørhøjskolen i Århus Slide 32 af 38 DOM Methods firstName lastName contents summary author date title article Tree structure for article.xml.

33 Ingeniørhøjskolen i Århus Slide 33 af 38 DOMExample.ht ml 1 2 4 5 6 7 8 9 10 A DOM Example 11 12 13 14 15 16 63 64 65 66 Retrieve the root node’s first child node (i.e., title ) using property firstChild. Property parentNode returns a node’s parent node.

35 Ingeniørhøjskolen i Århus Slide 35 af 38 Program Output

36 Ingeniørhøjskolen i Århus Slide 36 af 38 Tools XML-Spy: www.xml-spy.comwww.xml-spy.com Sun’s Stylus Studio: www.stylusstudio.comwww.stylusstudio.com Others: –API’s for programmatic access

37 Ingeniørhøjskolen i Århus Slide 37 af 38 Formatting XSL & CSS XML is only content – no formatting Possible to transform the data to XHTML (or other) using JavaScript og server-side The W3C ideal is using CSS or XSL – eXtensible Style Sheets CSS is most common today– but XSL has more features

38 Ingeniørhøjskolen i Århus Slide 38 af 38 The 3 Main Technologies of XSL XSLT, a language for transforming information XSL or XSL-FO, a language for formatting information XPath, a language for defining parts of an XML document and accessing them Each of these elements could fill an entire class. We will be dealing with them in a later course


Download ppt "Internet Technology 1 Presentation 10: XML technologies."

Similar presentations


Ads by Google