ICT 5 Web Development - Chapter 08: XML & XHTML

pdf
Số trang ICT 5 Web Development - Chapter 08: XML & XHTML 16 Cỡ tệp ICT 5 Web Development - Chapter 08: XML & XHTML 389 KB Lượt tải ICT 5 Web Development - Chapter 08: XML & XHTML 0 Lượt đọc ICT 5 Web Development - Chapter 08: XML & XHTML 30
Đánh giá ICT 5 Web Development - Chapter 08: XML & XHTML
5 ( 22 lượt)
Nhấn vào bên dưới để tải tài liệu
Đang xem trước 10 trên tổng 16 trang, để tải xuống xem đầy đủ hãy nhấn vào bên trên
Chủ đề liên quan

Nội dung

Vietnam and Japan Joint ICT HRD Program ICT 5 Web Development Chapter 08. XML & XHTML Content 1. XML and XHTML Overview 2. XML Components 3. DTD & XML Schema 4. XML Validation 5. XML Applications Nguyen Thi Thu Trang trangntt--fit@mail.hut.edu.vn trangntt 2 1.1. XML (eXtensible Markup Language) ‹ ‹ A new standard by W3C, derived from SGML EXtensible Markup Language (XML) is a metametalanguage that describes the content of the document (self (self--describing data) Java = Portable Programs; XML = Portable Data ‹ XML does not specify the tag set or grammar of the language – Tag Set – markup tags that have meaning to a language processor – Grammar – defines correct usage of a language’s tag 1.1. XML (2) ‹ Applications of XML – Media for data interchange ‹A better alternative to proprietary data formats – B2B transactions on the Web ‹ Electronic business orders (ebXML) Exchange (IFX) ‹ Messaging exchange (SOAP) ?> ‹ Financial Iced Tea An iced tea that we serve everyday 4 1 1.2. XML vs. SGML ‹ 1.3. XML vs. HTML SGML (Standard Generalized Markup Language) ‹ – ISO ISO--standard metameta-language – Powerfull but very complex, suffers from lack of industry support – The basis for XML, first published in 1988 ‹ ‹ XML (eXtensible (eXtensible Markup Language) ‹ – Simpler yet offers most of the power of SGML because it is also a metameta-language – More likely to have broad industry support, because many companies and universitites involved in development Both based on SGML – XML is a subset of SGML – HTML is a markup language written in SGML XML fundamentally separates content (data and language) from presentation; HTML specifies the presentation HTML explicitly defines a set of legal tags as well as the grammar (intended meaning) – …
‹ XML allows any tags or grammar to be used (hence, eXtensible) – 5 6 1.3. XML vs. HTML (2) ‹ HTML – Not extensible – cannot customize ‹ Cannot accommodate special needs (e.g. mathematics, chemical formulas) ‹ Proprietary, vendorvendor-specific tags to extends capabilities – Only codes for display, not document structure, semantics or content ‹ XML – Can define own markup language Æ Flexible – Tagging/content separate from display – Reflects structure and semantics of documents Æ better searching and nevigation 7 1.4. XHTML • History of HTML • HTML 1.0 10 ▫ Created by Tim BernersBerners-Lee and submitted to IETF • HTML 2.0 ▫ RFC1866 in Nov. 1995 • HTML 3.2 ▫ ▫ Jan. 1997 moved from IETF to W3C • HTML 4.0 ▫ Dec. 1997 • HTML 4.01 ▫ Dec. 1999 2 HTML4.01 ` XHTML1.0 HTML4.01 has three variations ` Reformulation of HTML4.01 in XML ` Three variations of XHTML1.0 ` more strict syntax than HTML ` Strict "http://www.w3.org/TR/xhtml1/DTD/xhtml1 ` Transitional ` Frameset ` Transitional "http://www.w3.org/TR/xhtml1/DTD/xhtml1 ` Frameset "http://www.w3.org/TR/xhtml1/DTD/xhtml1 1.5. XHTML Features HTML, XHTML and XML ‹ • • HTML is an SGML application XHTML is an XML application HTML SGML XHTML XML Characters for a tag must be lower case – C – I <TITLE>, <Title> ‹ Close tags must be needed – C <p>Para.</p> – I <p>Para<p>Next para ‹ A empty An t element l t needs d “ />” on the th end d – C <img src=“” alt=“” /> – I <img src=“” alt=“” > 3 1.5. XHTML Features (2) ‹ An 1.5. XHTML Features (3) attribute element needs its value ‹ XML Declaration is needed – <? ? xmll version=“1.0” i “ 0” encoding=“utfencoding=“utf di “ f-8” ?> ? – C <select multiple=“multiple” name=“test”> – I <select multiple name=“test”> ‹ xmlns attribute and xml:lang attribute ‹ Attribute values must be quoted by tthe e single s g e quotation quotat o or o the t e double doub e quotation. – <html xmlns="http://www.w3.org/1999/xhtml p g " xml:lang="en"> – C <h1 id=“title”>Title</h1> – I <h1 id=title>Title</h1> Content 2. XML Components 1. XML and XHTML Overview 2. XML Components 3. DTD & XML Schema 4. XML Validation 5. XML Applications ‹ Prolog – Defines the xml version, entity definitions, and DOCTYPE ‹ Components of the document – Tags and attributes – CDATA (character data) – Entities – Processing instructions – Comments 15 16 4 2.1. XML Prolog ‹ 2.1.1. XML Declaration XML Files always start with a prolog ‹ ‹ Includes: I l d XML version and document encoding <?xml version="1 version="1.0" 0" encoding="ISO encoding="ISO-8859 8859-1" standalone="no"?> – Declaration – Entities and DTD definitions – The version of XML is required – The encoding identifies character set (default UTF--8) UTF – The value standalone identifies if an external document is referenced for DTD or entity definition 17 2.1.2. DOCTYPE Declaration Specifies the location of the DTD defining the syntax and structure of elements in the document ‹ Common forms: ‹ – <!DOCTYPE root [[DTD]> DTD]> – <!DOCTYPE root SYSTEM URL> – <!DOCTYPE root PUBLIC FPI FPI--identifier URL> ‹ The root identifies the starting element (root element) of the document 2.1.2. DOCTYPE Declaration (2) ‹ The DTD can be external to the XML document, referenced by a SYSTEM or PUBLIC URL – SYSTEM URL refers to a private DTD ‹ Located on the local file system or HTTP server – PUBLIC URL refers to a DTD intended for public use <?xml version=“1.0” encoding=“utfencoding=“utf-8”?> <!DOCTYPE authors SYSTEM “http://example.org/authors.dtd”> <authors> Root element … URI Reference of DTD SYSTEM or PUBLIC 20 5 Simple XML Example DTD (Document Type Definition) ‹ A schema language for SGML and XML <?xml version="1.0"?> <!DOCTYPE authors SYSTEM “http://example.org/authors.dtd”> <authors> <name> <firstname>Larry</firstname> <lastname>Brown</lastname> </name> <name> <firstname>Marty</firstname> <lastname>Hall</lastname> </name> ... </authors> – Definitions of elements, elements attributes, attributes entities – Content model: Tree structure by nested elements ‹ In authors.dtd on http://example.org: <!DOCTYPE authors [ <!ELEMENT <!ELEMENT <!ELEMENT <!ELEMENT authors(name)*> name(firstname, lastname)> firstname(#PCDATA)> lastname(#PCDATA)> ]> 22 Standalone XML document <?xml version="1.0" standalone="yes"?> <DOCTYPE authors [ <!ELEMENT authors (name)*> <!ELEMENT name (firstname, lastname)> <!ELEMENT firstname (#PCDATA)> <!ELEMENT lastname (#PCDATA)> ]> <authors> <name> <firstname>James</firstname> <lastname>Gosling</lastname> </name> ... </authors> Specifying a PUBLIC DTD <!DOCTYPE root PUBLIC FPI FPI-identifier URL> ‹ The Formal Public Identifier (FPI) has four parts: – 1. Connection of DTD to a formal standard ‹ ‹ ‹ - if defining yourself + nonstandards body has approved the DTD ISO if approved by formal standards committee – 2. Group responsible for the DTD – 3. Description and type of document – 4. 4 Language L used d in i the th DTD ‹ E.g. <!DOCTYPE Book PUBLIC " "-//W3C//DTD XHMTL 1.0 Transitional//EN" "http://www.w3.org/TR?xhtml1/DTD/xhtml1"http://www.w3.org/TR?xhtml1/DTD/xhtml1 -transitional.dtd"> <!DOCYTPE CWP PUBLIC ""-//Prentice Hall//DTD Core Series 1.0//EN“ "http://www.prenticehall.com/DTD/Core.dtd"> 23 24 6 2.2.1. XML Comments 2.2. Component of the document ‹ Comments ‹ XML Comments – The same as HTML comments ‹ Processing instructions ‹ Root element ‹ Tags and attributes ‹ Entities – <! <!--- This is an XML and HTML comment ---> > 25 26 2.2.2. Processing Instructions ‹ ‹ 2.2.3. XML Root Element Application-specific instruction to the XML processor Application<?processor<?processor -instruction?> ‹ Example <?xml version="1.0" ?> <?xml<?xml -stylesheet type="text/xml" href="orders.xsl" ?> <orders> <order> <count>37</count> <price>49.99</price> <book> <isbn>0130897930</isbn> / <title>Core Web Programming Second Edition Marty Hall Larry Brown ‹ 27 Required for XMLXML-aware applications to recognize beginning and end of document Example Core Web Programming BlockBlock-level Elements in HTML 4.0 TextText-level Elements in HTML 4.0 ... 28 7 2.2.4. XML Tags & Attributes ‹ Tag names: – – – – – ‹ 2.2.4. XML Tags & Attributes (2) (2) ‹ Case sensitive Start with a letter or underscore After first character, numbers, - and . are allowed Cannot contain whitespaces Avoid use of colon expect for indicating Element Attributes – Attributes provide metadata for the element – Every attribute must be enclosed in "" with no commas in between – Same naming conventions as elements namespaces < i it /> We put the . in .com. What did you do? For a well well--formed XML documents – Every tag must have an end tag – All tags are completely nested (tag order cannot be mixed) 29 2.2.5. Document Entities ‹ Content Entities refer to a data item, typically text – General entity references start with & and end with ; parsed avoid conflicts – The entity reference is replaced by it’s true value when – The characters < > & ' " require entity references to ‹ with the XML application (parser) < > & " ' Entities are user definable ]> Core Web Programming, ©RIGHT; 30 31 1. XML and XHTML Overview 2. XML Components 3. DTD & XML Schema 4. XML Validation 5. XML Applications 32 8 Well--formed versus Valid Well 3.1. Document Type Definition (DTD) ‹ An XML document can be well well-f formed d if it follows f ll b basic i syntax t rules l ‹ An XML document is valid if its structure matches a Document Type Definition (DTD) or an XML Schema ‹ Defines Structure of the Document – Allowable tags and their attributes – Attribute values constraints – Nesting of tags – Number of occurrences for tags – Entity definitions 33 34 DTD Examples 3.2. XML Schema 35 ‹ W3C recommendation released May 2001 – – – – – http://www.w3.org/TR/xmlschemahttp://www w3 org/TR/xmlschema-0/ http://www.w3.org/TR/xmlschema – http://www.w3.org/TR/xmlschemahttp://www.w3.org/TR/xmlschema-1/ – http://www.w3.org/TR/xmlschemahttp://www.w3.org/TR/xmlschema-2/ Depends on following specifications ‹ ‹ Benefits: – – – – ‹ XML--Infoset, XML Infoset, XMLXML-Namespaces, XPath Standard and useruser-defined data types Express data types as patterns Higher degree of type checking Better control of occurrences Clearly the future … but limited support 36 9 XML Schema Example XML Schema Example (2) g ... 37 38 Content 4. XML Validation 1. XML and XHTML Overview 2. XML Components 3. DTD & XML Schema 4. XML Validation 5. XML Applications ‹ DTD Validaton – Process of checking a document against a DTD ‹ Correct syntax ‹ Correct structure – If the document is invalid, a user agent may nott b be able bl to t handle h dl it correctly tl ‹ parse error 39 10
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.