1 / 37

XML introduction

XML introduction. What is XML? Examples of XML use A XML document Structuring data with tags More about tags. What is XML?. eXtensible Markup Language Is a markup language for making other markup languages XML is a meta language Examples of markup languages : HTML

taniel
Download Presentation

XML introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML introduction • What is XML? • Examples of XML use • A XML document • Structuring data with tags • More about tags

  2. What is XML? • eXtensible Markup Language • Is a markup language for making other markup languagesXML is a meta language • Examples of markup languages : • HTML • XHTML (a xml version of html) • RTF • (S)GML • Except from XHTML, these are not xml • With XML, tags specific to the domain can be defined. Sounds complicated? You can make your own tags to describe data with in XML

  3. In Other Words… • XML is a meta language - a language to define other languages in • You define the language using XML as meta language • Your XML language describes the data structure of your domain

  4. XML tells nothing about layout XML describes structure and semantics, not formatting HTML mixes data and layout <BODY> <DT>Hot Cop <DD>by Jacques Morali, Henri Belolo, and Victor Willis <UL> <LI>Jacques Morali <LI>PolyGram Records <LI>6:20 <LI>1978 <LI>Village People </UL> </BODY>

  5. XML Documents can be parsed using a browser:

  6. But be careful …and created and edited using a text editor:

  7. …or using a better tool:

  8. Data descripes itself • What is descriped here:

  9. And what is this? ?

  10. Sometimes a commentary is helpful

  11. Data exchange between applications • XML is a non propritary format • Meaning it is not owned by somebody or belongs to certain application • It is easy for humans to read and write xml documents • It can be written in a simple editor • It can easily be send by the networkin a secure or unsecure format • Note: But xml is not smart, if you send big data amounts. Why? In contrast to doc (word, word perfect...), pdf, mdb, qt, drw, etc.

  12. XML standards Not an XML-language it selves • DTD (Document Type Definition) Definition of a XML-language. The old way. • XSCHEMADefinition of a XML-language. The new way. • XPATHTraversing / navigation in a xml-document. • XSL(T)Stylesheet. Used for converting from one format to another. For instance from xml to html. • XSL-FOFormatting stylesheets. Used for documents in a non markup langauge, e.g. pdf-document og svg-documents

  13. Examples of use of xml • Data exchange • Handling of multiple client types on www • SOAP – Simple Object Access ProtocolServices are descriped with xml. Data is transported in a xml-document. Example: WebServices • RSS feeds – See for instance Visual Studio • Configuration files e.g. web.config

  14. Use of XML

  15. Examples of xml-languages • ODFOpen Document Format • OOXMLOpen Office XML • CMLChemical Markup Language • OFXOpen Financial eXchange • SVGScalable Vector Graphics • OSDOpen Software Description • XHTMLHTML i xml udgave

  16. XML might be written NotePad XML can be viewed in a msie browser XML can also be viewed in Mozilla Demo: Hello World

  17. XML document XML with stylesheet Stylesheet (XSL) Format with a stylesheet

  18. Example: TV schedule By this example the following is discussed: • Good xml-style • Structure and syntax in xml-documents • Terminology and definitions • XML tree

  19. Find candidates for tags As in database modelling: • By finding objects / entities in the user domain • Find keywords in the problem description • Look at existing output.E.g. Look in TV section of the paper. • Map from an existing database. • ... • Keywords: • - Title - Description • - Station - Category • - Date - Production year • - Start time - Stars • - Duration

  20. Declaration Rod element Underelement Strukturering Et XML-dokuments opbygning: • Dokumentet er hierarkisk opbygget i en træstruktur • Giver nogle fordele, men også ulemper ift. relations databaser • Der er eet rod-element, som indeholder alt det andet • Declarations <?..?> er ikke en del af træet • Træet kan indeholde et vilkårligt antal knuder

  21. A little about xml-style • As in programming you should choose a strict way of writing: • How shall naming be? Use _ or capital first letter?Or only capitals? • When to use text between start and end tags? and when to use attributes? • Else: Use w3.org's way (only non capitals and _)

  22. The structure can be expanded

  23. Root Parent Child Siblings XML documents is alway a tree structure

  24. Nesting of elements • Terminology: • Child elements – elements that are contained in other elements • Parent elements – elements that contains other elements • Sibling elements – elements that have the same parent element

  25. XML Syntax • “Syntax” refers to the rules of the language • Syntax is necessary for making documents written in the language consistent • Programs that interpret documents assume that the rules of the syntax is satisfied, else it can't be guarantied that the document is interpreted correctly.

  26. Components in a XML Documents • XML Declaration • Elements • Attributes • Entities • Commentary <?declaration?> <element attribute="value"> &lt; is a character reference. It is also an entity <!-- Comment: &lt; is the less-than symbol --> </element>

  27. Components: XML Declaration • XML Declaration: • Tells that the document is a XML document and other optional information's • The XML declaration is always the first line in a XML document • Attributes that can be used in the XML Declaration: • version • encoding • standalone • <?xml version=“1.0” Encoding=“UTF-8” standalone=“yes”?><?xml-stylesheet type="text/xsl" href="HelloWorld_v1.xsl"?>

  28. Components: XML Elements • Elements: • Used for describing data. Contains of: • start tag • contents • end tag • Examples: <element>Content</element> • The “root” element in a document is the outer most element and contains all other elements in the documents. A document can only contain one root element • A element without content is called a “empty element”, but is still an element • Example: <empty_element attribute="value"/>In real world, html: <input> and <img> are empty elements

  29. Components: XML Attributes • Attributes helps to describe XML elements • Attributes are always a part of the start tag • Attributes is also known as “name-value par” • Instead of <SHOW> ... <START_TIME> 3:45 </START_TIME> ... </SHOW> you could write <SHOW start_time="3:45“> ... </SHOW> It’s your design decision if something is an element or an attribute of some element (as in other data modelling processes)

  30. Components: XML Entities • Two types of entities: • General – Can contain information stored in a XML document • Parameters – used in DTD for referring an element-group • Three types of general entities: • Character – used instead of special characters(e.g. < &lt;) • Starts with ‘&’ and ends with ‘;’ • Content – used for reuse of blocks of text (variables) • Unparsed – used for binary or non-textual data (e.g. pictures)

  31. Examples of entities • Character entity: • Character: > • Entity reference: &gt; or &#62; • Usage: <formula> x &gt; y </formula> • Content entity: • Declaration: <!ENTITY address “123 Main St”> • Usage: <ship_address> &address; <ship_address> • Unparsed entity: • Declaration: <!ENTITY image SYSTEM “sunset.gif” NDATA GIF> • Usage: <picture> &aimage; </picture>

  32. Defining entities • An entity is a name and an associated value • The value may be: • A special character code • A piece of text • A filename • Entity definitions in DTD (next session) or in the xml-document it selves: <!DOCTYPE DOCUMENT [<!ENTITY signature "Kys og Klap">]>

  33. Components: Comments • Comments are ignored by the xml interpreter • The content of the commentary is surrounded by <!–- and --> • Example: <!-- This is a comment -->

  34. Well-Formed XML Documents • A “well-formed” document satisfies the syntax rules of XML: • A XML document contains one root element • All elements must have a start and an end tag, except empty elements • Elements must be nested correctly • All attributes must have a value • Attributes can only be defined in start tags and must be unique • Element names are case-sensitive • Special characters must be written as entities • Names of elements must start with a letter or underscore and may only contain letters, numbers, hyphen, period and underscore

  35. Parser • A xml parser is a program, that as minimum can validate whether a xml document is well formed. • Most parsers are also able to validate a xml document according to some xml language defined by a DTD or Schema. • A quick way is a view the document in a browser: MSIE5.5 +, Netscape 6+ or Mozilla/Firefox. • The most common parsers is properly Xerces (java) and MSXML (ms). • And you can write your own.....

  36. Source Internet Explorer 6.0 Mozilla 1.7 Parsing with the browser • We have seen when it goes well. Here is a document with errors errors What is the error?

  37. Reading stuff i.e. • Books: • XML and Web Services, Ron Schemlzer et al., Sams • XML- How To Program, Deitel et al., Prentice Hall • An Introduction to XML and Web Technologies, Anders Møller and Michael Schwartzbach, Addison-Wesley • Links: • www.zvon.orgReferences and tutorials • www.w3.orgStandards • www.w3school.comTutorials • www.topxml.comDeveloper forum • www.ibiblio.org/xmlXML bible • http://www.brics.dk/ixwt/Web site accompanying the book by Møller&Schwartzbach

More Related