Till KTH:s startsida Till KTH:s startsida

Logga in till din kurswebb

Du är inte inloggad på KTH så innehållet är inte anpassat efter dina val.

Ändra tidsperiod eller vy
Vecka 45 2013 Visa i Mitt schema
Tis 5 nov 10:00-12:00 Lecture: course info, XML and DTD
HT 2013 xmlpub13
Föreläsning Lärare: Björn Hedin

The lecture starts 10.15

Introduction to the course and general course information during the first hour. The second hour is devoted to introducing XML in general, and how to write DTDs, which is required to complete the first lab assignment.

Prepare by reading this summary of the lecture

XML is a recommendation for how different types of data can be structured in tree structures, which are easy to understand and clear to both humans and computers. Examples of areas where XML is used is xhtml for coding web pages, SMIL (the language to encode MMS), DocBook (a highly structured document description languages) and JDF (a language to transmit information between different computer systems as part of a printing process). One can roughly divide the uses of document formats like HTML and SMIL, and data format JDF.

There are a number of major benefits of using an XML-based format over other types of formats, such as:

  • Data saved in XML-based formats are easily portable between different environments, and are easy to convert if new data formats emerge in the future.
  • "X" in XML stands for "extensible", which in this context means that it is easy to extend existing markup languages ​​to fit into any specific needs.
  • There are many high quality tools that handle XML, eg editors and parsers. Several of the best are free.
  • XML is very familiar to most programmers, reducing startup time.
  • XML documents are easy to read, both by humans and machines.
  • Many powerful "language" has been developed that utilize and require XML, eg XSLT, CSS, XQuery mm.
  • Plain text is used, so the format is platform independent.

Data is described by means of a hierarchy of "elements". At the top is a "top element" such as the element "html" in the XHTML document. An element may contain zero, one or more other elements. Element is encoded in the form <element-name> element content </ element-name>.

So called "attributes" can be associated to elements. For example, the attribute "href" is associated with the element 'a' in the following way in html:

<a href="http://www.kth.se> Link to KTH </ a>

A set of elements, attributes, and the way it is permitted to combine these is called an "XML vocabulary." Such a set of rules and restrictions ("constraints") can be defined by a DTD. If an instance document (ie an XML document containing data) is associated with a DTD, it is possible to "validate" the document against the DTD, which means that you can see if/that the instance document follows the rules that are set in the DTD. It thus provides an opportunity for a program to check that the document contains no errors.

Besides the ability to validate the instance document, a DTD is an easy way to concisely define how the creator of the vocabulary meant it to be used. The risk of misunderstandings are reduced. Unfortunately, it is sometimes not possible to define every constraint the vocabulary should have using a DTD. Some limitations have to be written as comments, and these restrictions can naturally not be validated by a validator. XML Schemas, which are processed at the next opportunity, is a powerful way to express the "constraints" vocabulary creator wants expressed, and fills the same role as a DTD.

A DTD describes a "content model" for elements, ie which elements of the hierarchy can be, or should be, "children" to another element. To express that an element "book" can contain exactly one element "title", one of several "authors" zero to one "initial" and zero to several "chapters" can be done by the line

<!ELEMENT book (title, author +, introduction?, chapter*)>

To further express that a writer has several names, zero to several middle name, and exactly one surname can be done by the line

<!ELEMENT author (first-name+, middle-name*, name)>

Expressing that the element "book" may have an attribute named "isbn" can be expressed by

<!ATTLIST book isbn CDATA #IMPLIED>

Links

For a pre-recorded slidecast (slides + audio) of the second part, see http://www.slideshare.net/bjornh/xml-och-dtd 

Literature: XML in a nutshell 

(3) = Essential for the course
(2) = Important for the course
(1) = Relevant to the course

  • (2) Chapter 1, "Introducing XML" provides an overview and helps the reader understand the advantages of XML. 
  • (3) Chapter 2, "XML fundamentals" provides an introduction to how to structure your own data and create your own markup language in XML. It also provides explanations of key concepts such as attributes, processing instructions, well-formed and more.
  • (3) Chapter 3, "Document Type Definitions" explains the concept of validation and review how to define a markup language using a DTD. To complete lab 1, you need to be able to understand this chapter well.
  • (1) Chapter 21, "XML Reference". Reference Chapter. NOTE! The examples on pages 369 and 370 is good to concretize the basic concepts and can be recommended to everyone.
Tis 5 nov 13:00-15:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 6 nov 08:00-10:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 6 nov 15:00-17:00 Lecture: XSLT
HT 2013 xmlpub13
Föreläsning Lärare: Björn Hedin
Plats: D41

Prepare for the lecture by reading this

XSLT is a technology for transforming XML documents belonging to a vocabulary to new XML documents that can belong to the same or an entirely different vocabulary.
A program called an XSLT processor takes as input an XML document (input tree) and an XSLT document. The basic principle is that the XSLT processor starts to go through the input tree from the top down. The node that is being processed is called the context node. Processor looking for patterns ("patterns") of the input tree and see if there is a rule in the XSLT document matches the pattern for context node. If so, the rule can add content to the result tree, and give instructions on which nodes next to be context nodes.

The patterns and rules about what will happen when the processor finds a certain pattern, described by the element "template" that is defined in the XSLT namespace belongs. The element template has an attribute "match" containing an xpath expression with which to describe the different parts of an XML tree. The content of the template element is then added to the result tree. Content can also include instructions about which nodes will then be contextual nodes. One common case is to allow all or some child nodes become context-nodes by xslt element apply-templates:

<xsl:apply-templates select="ett-xpath-uttryck"/>

Here is a complete example of a template

<xsl:template match="/party/toastmaster/firstname">
  <h1> Name: <xsl:apply-templates select="*"/> </ h1>
</ xsl: template>

The example matches all elements "first name" which is a child element to the "toast master" which in turn is a child element to the "party". If the XSLT processor, in the revision of the input tree, encounters such an element, the first add "<h1> Förnmamn:" the result tree, then go through all the child nodes of the element and see if any rules are applicable to these , to finally close it began h1 element with "</ h1>".

----

Here are the  slides from last year's lecture about XSLT . They might be updated.

Fre 8 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Fre 8 nov 17:00-18:00 Deadline lab 1: DTD och XML (OBS! endast en deadline, ingen undervisning)
HT 2013 xmlpub13
Laboration
Anmärkning: kl 17.30 Lab 1:XML och DTD
Vecka 46 2013 Visa i Mitt schema
Tis 12 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Tis 12 nov 13:00-15:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 13 nov 10:00-12:00 Föreläsning RSS/RDF/PHP/Databaser
HT 2013 xmlpub13
Föreläsning Lärare: Björn Hedin
Plats: D42

En relativt kort föreläsning (förmodligen räcker 1 timme) om php och RSS/RDF samt databaser, dvs det ni behöver för att börja med och slutföra lab3. De täcks av slidecastsen på http://www.slideshare.net/bjornh/php-och-mysql respektive http://www.slideshare.net/bjornh/rdf-och-rss 

Fre 15 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Plats: 5O3Mus (Musiksalen), 5O4Kon (Lindstedtsvägen 5 pl.5)
Fre 15 nov 17:00-18:00 Deadline lab 2: XSLT (OBS! endast en deadline, ingen undervisning)
HT 2013 xmlpub13
Laboration
Anmärkning: kl 17.30 Lab 2: XSLT
Vecka 47 2013 Visa i Mitt schema
Tis 19 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Tis 19 nov 13:00-15:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 20 nov 17:00-18:00 Deadline projektidé: (OBS! endast en deadline, ingen undervisning)
HT 2013 xmlpub13
Projekt
Anmärkning: kl 17.30 Projektidé
Tors 21 nov 13:00-15:00 OBS! Laboration!!!
HT 2013 xmlpub13
Datorlaboration Lärare: Björn Hedin

Pga krock med Armada på tisdagen så ändrar vi detta tillfälle från att vara föreläsning i E51 till att vara laboration i Violett och Turkos.

Fre 22 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Plats: 5O4Kon (Lindstedtsvägen 5 pl.5), 5O5Mat (Lindstedtsvägen 5 pl.5)
Fre 22 nov 17:00-18:00 Deadline lab 3: RDF och RSS med PHP och databaser (OBS! endast en deadline, ingen undervisning)
HT 2013 xmlpub13
Laboration
Anmärkning: kl 17.30 Lab 3: RDF och RSS med PHP och databaser
Vecka 48 2013 Visa i Mitt schema
Tis 26 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 27 nov 08:00-10:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 27 nov 17:00-18:00 Deadline projekt-DTD och databasstruktur (OBS! endast en deadline, ingen undervisning)
HT 2013 xmlpub13
Laboration
Anmärkning: 17.30 DTD och databasstuktur
Fre 29 nov 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Fre 29 nov 17:00-18:00 Deadline lab 4: XPath (OBS! endast en deadline, ingen undervisning)
HT 2013 xmlpub13
Laboration
Anmärkning: kl 17.30 Lab 4: XPath
Vecka 49 2013 Visa i Mitt schema
Tis 3 dec 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Ons 4 dec 08:00-10:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Tors 5 dec 13:00-15:00 Föreläsning
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Plats: 5O3Mus (Musiksalen), 5O4Kon (Lindstedtsvägen 5 pl.5)
Fre 6 dec 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Vecka 50 2013 Visa i Mitt schema
Tis 10 dec 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Fre 13 dec 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Fre 13 dec 13:00-15:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Vecka 51 2013 Visa i Mitt schema
Tis 17 dec 10:00-12:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin
Tis 17 dec 13:00-15:00 Laboration
HT 2013 xmlpub13
Laboration Lärare: Björn Hedin