XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.

  • Published on
    05-Jan-2016

  • View
    216

  • Download
    2

Embed Size (px)

Transcript

  • XML Introduction

  • What is XML?XML stands for eXtensible Markup LanguageXML is a markup language much like HTML that is used to describe dataXML tags are not predefined - you must define your own tagsXML uses a Document Type Definition (DTD) or an XML Schema to describe the dataXML with a DTD or XML Schema is designed to be self-descriptive

  • XML vs HTMLXML was designed to carry dataHTML and XML were designed with different goalsHTML is about displaying information, while XML is about describing information

  • XML example Tom Jane Reminder Meeting

    The XML example was created to structure and store information. It does not DO anything because someone must write programs to send, receive or display it.

  • XML example (cont.)New tags and the corresponding document structure are invented in our example

  • How XML complements HTMLXML separates Data from HTMLData can be exchanged between incompatible systemsWith XML, plain text files can be used to share dataXML can also be used to create new languages, such as the Wireless Markup Language (WML)

  • XML Elements Tom Jane Reminder Meeting

    The first line in the document the XML declaration defines the XML version and character encoding used in the document

  • XML Elements (cont.)In the example, the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin-1/West European) character setThe next line describes the root element of the document The next 4 lines describe 4 child elements of the root: , , and And finally the last line ends the root element

  • XML Elements (cont.)All XML elements must have a closing tagIn HTML, some elements do not have to have a closing tag, for example: This is a paragraphXML tags are case sensitive, whereas HTML tags are case insensitiveAll XML elements must be properly nested and improper nesting of tags makes no sense to XML.This is bold and italic - IncorrectThis is bold and italic - Correct

  • XML Elements (cont.)All XML documents must have a root elementAll other elements are within this root elementAll elements can have sub elements (child elements) that are properly nested within their parent element:

    .

  • XML Elements (cont.)XML elements can have attributes in name/value pairsThe attribute value must always be quoted

    Tom

    The syntax for writing comments in XML is similar to that of HTML:

  • XML Elements (cont.)XML elements have relationshipsFor example, a hierarchy such as:My First XMLIntroduction to XMLWhat is HTMLWhat is XMLXML SyntaxElements must have a closing tagElements must be properly nested

  • XML Elements (cont.)Can be organized into:

    My First XMLIntroduction to XMLWhat is HTMLWhat is XML

    XML SyntaxElements must have a closing tagElements must be properly nested

  • Element NamingXML elements must follow these naming rules:Names can contain letters, numbers, and other charactersNames must not start with a number or punctuation characterNames must not start with the letters xml (or XML or Xml ..)Names cannot contain spaces

  • Element Naming (cont.)Non-English letters like are perfectly legal in XML element names, but watch out for problems if the software vendor doesn't support themThe ":" should not be used in element names because it is reserved for namespaces (discussed later)

  • "Well Formed" XML documentsXML with correct syntax is Well Formed XMLXML validated against a Document Type Definition (DTD) is Valid XMLA DTD defines the legal elements of an XML documentA Schema is an alternative to a DTD but we are not going to cover it because Greenstone does not use XML Schema

  • Introduction to DTDThe purpose of a Document Type Definition is to define the legal building blocks of an XML documentA DTD defines the document structure with a list of legal elementsA DTD can be declared inline in your XML document or as an external referenceIf a DTD is included in your XML document, it should be wrapped in a DOCTYPE definition: - Inline
  • Introduction to DTD (cont.)An Inline DTD example:1: 2: 5: 6: 7: 8: ]>9: 10: Tom 11: Jane 12: Reminder13: Don't forget me this weekend! 14:

  • Introduction to DTD (cont.)!DOCTYPE note (in line 2) defines that this is a document of type note!ELEMENT note (in line 3) defines the note element as having four elements: "to,from,heading,body"!ELEMENT to (in line 4) is defined to be of type "#PCDATA".!ELEMENT from (in line 5) is defined to be of type "#PCDATA"and so on.....

  • Introduction to DTD (cont.)External Reference example:

    Tom Jane ReminderDon't forget me this weekend!

  • Introduction to DTD (cont.)Note.dtd

  • Introduction to DTD (cont.)PCDATA PCDATA is text that will be parsed by a parser Tags inside the text will be treated as markup and entities will be expandedCDATACDATA is text that will NOT be parsed by a parser Tags inside the text will NOT be treated as markup and entities will not be expanded

  • Declaring a DTD ElementIn the DTD, XML elements are declared with an element declaration: or

    There are various types of elements that we can declare in a DTD

  • Types of DTD elementsEmpty Elements

    Elements with only character data

    Elements with any contents

    Elements with children (sequences)

    Note that when children are declared in a sequence separated by commas, the children must appear in the same sequence in the document.

  • Types of DTD elements (cont.)Declaring only one occurrence of the same element

    Declaring minimum one occurrence of the same element

    Declaring zero or more occurrences of the same element

    Declaring zero or one occurrences of the same element

  • Types of DTD elements (cont.)Declaring either/or content

    Declaring mixed content

    DTD attributes are declared with an ATTLIST declaration - not covered because Greenstone does not use them

  • DTD ValidationInternet Explorer 5.0 and above can validate your XML against a DTDAn ill-formed or illegal XML document will generate an error

  • Why use a DTD?Each XML file can carry a description of its own format with it With a DTD, independent groups of people can agree to use a common DTD for interchanging data A standard DTD can be used to verify that the data one receives from the outside world is valid We can also use a DTD to verify our own data

  • ReferencesDTD Tutorial http://www.w3schools.com/dtd/default.aspXML Tutorialhttp://www.xmlfiles.com/xml/http://www.w3schools.com/xml/default.aspHTML Tutorialhttp://www.w3schools.com/html/default.asp

Recommended

View more >