Presentation is loading. Please wait.

Presentation is loading. Please wait.

8/6/2015Comp Sci 3461 XML_1 Ch. 7 Fall 2010. 8/6/2015Comp Sci 3462 Bibliography  W3C Recommendations  XML online tutorials.

Similar presentations


Presentation on theme: "8/6/2015Comp Sci 3461 XML_1 Ch. 7 Fall 2010. 8/6/2015Comp Sci 3462 Bibliography  W3C Recommendations  XML online tutorials."— Presentation transcript:

1 8/6/2015Comp Sci 3461 XML_1 Ch. 7 Fall 2010

2 8/6/2015Comp Sci 3462 Bibliography  W3C Recommendations http://www.w3.org/TR/REC-xml/  XML online tutorials 1. http://www.w3schools.com/xml/default.asp http://www.w3schools.com/xml/default.asp 2. Java API for XML Processing (JAXP): https://jaxp.dev.java.net/ https://jaxp.dev.java.net/ 3. http://www.xml-training-guide.com/ http://www.xml-training-guide.com/  Examples from textbook  Examples from “ Internet & World Wide Web How to Program” Third Edition by Deitel, Deitel, and Goldberg Prentice Hall

3 8/6/2015Comp Sci 3463 Extensible Markup Language (XML) What is XML?  A meta-markup language A technology for creating markup languages A technology for creating markup languages Why should you learn XML? It allows you to invent your own tags It allows you to invent your own tags XML documents can be easily parsed XML documents can be easily parsed XML is portable XML is portable  The Web is becoming XML-based rather than HTML-based

4 8/6/2015Comp Sci 3464 XHTML vs XML  Based on tag pairs  Purpose: Markup language Markup language Displays the data Displays the data Focus: How it looks Focus: How it looks Does not care about the meaning of contents Does not care about the meaning of contents Predefined tags Predefined tags  Based on tag pairs  Purpose: Meta-markup language to define markup language ML defined by XML describes the data Focus: meaning (what) of data Method of data exchange Content must be well structured No predefined tags

5 8/6/2015Comp Sci 3465 How to display XML data?  XHTML: Use CSS (Cascading Style Sheet)  XSL (Extensible Style Language)

6 8/6/2015Comp Sci 3466 Historical Development SGML( Standard Generalized Markup Language) HTML XML XHTMLRSS MathML MusicXML... CMLXBRL

7 8/6/2015Comp Sci 3467 XML Syntax  Same as XHTML (an application of XML)  First line:  First line:  Tree of elements: one root element  Element: opening tag, content, closing tag  Opening tag format:  Opening tag format:  Closing tag format:  Closing tag format:  Opening tag may contain attributes  Attribute values must be quoted

8 8/6/2015Comp Sci 3468 XML Documents  Contain marked up data  Do not contain any formatting information  XML parser passes data on to an application (e.g. browser)  Stylesheet may be applied to render the document

9 8/6/2015Comp Sci 3469 XML Documents  Two major elements Prolog Prolog XML declaration statementsXML declaration statements Processing instructionsProcessing instructions CommentsComments For example:For example: Body Body

10 8/6/2015Comp Sci 34610 XML Document  XML is hierarchical E.g. E.g. BookBook Title Title Chapter Chapter ParagraphParagraph<Book> </Book>

11 8/6/2015Comp Sci 34611 XML Document  SystemMessage as an example <SystemMessage> System Down for Maintenance System Down for Maintenance Going down for maintenance soon! Going down for maintenance soon! Joe SystemGod Joe SystemGod systemgod@someserver.com systemgod@someserver.comsystemgod@someserver.com Oct. 19, 2010 Oct. 19, 2010 </SystemMessage>

12 8/6/2015Comp Sci 34612 Rules  XML is case-sensitive  All XML tags must be properly closed  XML tags must be properly nested  No overlapping tags are allowed

13 8/6/2015Comp Sci 34613 View 1article.xml with Browsers  Microsoft Internet Explorer  Netscape  Mozilla  Firefox  Opera  What did you discover?

14 8/6/2015Comp Sci 34614

15 8/6/2015Comp Sci 34615

16 8/6/2015Comp Sci 34616 A more complicated xml document  XML for a Business Letter  See 2letter.xml

17 8/6/2015Comp Sci 34617 Dear Sir: It is our privilege to inform you about our new database managed with XML. This new system allows you to reduce the load of your inventory list server by having the client machine perform the work of sorting and filtering the data. Sincerely Mr. Doe

18 8/6/2015Comp Sci 34618 DTD  DTD (Document-Type-Information) added  XML document does not need DTD XML parsers need DTD to ensure that XML documents have the proper structure XML parsers need DTD to ensure that XML documents have the proper structure Use a validator Use a validator www.w3.org/XML/Schema.html for suggestions www.w3.org/XML/Schema.html for suggestions www.w3.org/XML/Schema.html Microsoft downloadable XML validator http://support.microsoft.com/kb/307379 Microsoft downloadable XML validator http://support.microsoft.com/kb/307379 http://support.microsoft.com/kb/307379

19 8/6/2015Comp Sci 34619

20 8/6/2015Comp Sci 34620

21 8/6/2015Comp Sci 34621 The contact element John Doe 123 Main St. Anytown Anystate 12345 555-1234

22 8/6/2015Comp Sci 34622 Characters XML documents may contain  Carriage returns  Line feeds  Unicode characters Angle brackets delimit markup text Character data is the text between start and end tags

23 8/6/2015Comp Sci 34623 Reserved Characters  These characters may not be used in character data: & ' "  Entity references are used if reserved characters are needed in character data <blah> "Hello & goodbye." </blah>

24 8/6/2015Comp Sci 34624 Unicode Characters Entity references are used for Unicode characters not found on keyboard Example: Example:د denotes an Arabic character

25 8/6/2015Comp Sci 34625 DOCTYPE  XML documents may contain a tag <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Strict//EN" "http://www.w3.org/TR/chtml1/DTD/xhtml1-strict.dtd">  Specifies root element (html)  Information about location of the document type definition (dtd)

26 8/6/2015Comp Sci 34626 CDATA Sections  Sections of XML doc ignored by parser  May contain special characters  Example: JavaScript code <![CDATA[ XML parser >> all of this stuff. Note no space between first [ and CDATA; CDATA and second [ ]]>

27 8/6/2015Comp Sci 34627 Namespaces  Document authors may invent their own elements  Tag names may be reused  Naming collisions must be avoided How? How?

28 8/6/2015Comp Sci 34628 XML Namespace  XML Allows document authors to create custom elements Allows document authors to create custom elements Naming collisionsNaming collisions XML namespace XML namespace Collection of element and attribute names may conflictCollection of element and attribute names may conflict Math Math xhtml xhtml Uniform resource identifier (URI)Uniform resource identifier (URI) Uniquely identifies the namespace Uniquely identifies the namespace A string of text for differentiating names A string of text for differentiating names Math Math xhtml xhtml Any name except for reserved namespace xmlAny name except for reserved namespace xml DirectoryDirectory Root element and contains other elements Root element and contains other elements

29 8/6/2015Comp Sci 34629 Specify Namespace with URI Example: namespace.xml <directory xmlns:text = "urn:deitel:textInfo" xmlns:image = "urn:deitel:imageInfo"> A book list A funny picture

30 8/6/2015Comp Sci 34630 Or use URL  <text:directory xmlns:text = http://www.deitel.com/xml-text Xmlns:image = http://www.deitel.com/xmlns-image> http://www.deitel.com/xmlns-image

31 8/6/2015Comp Sci 34631 Default namespace Example: defaultnamespace.xml <directory xmlns = "urn:deitel:textInfo" xmlns:image = "urn:deitel:imageInfo"> A book list A funny picture

32 8/6/2015Comp Sci 34632 How to specify structure of document  Two methods for defining an XML document's structure DTD DTD Schema Schema  "Valid" XML doc: conforms to DTD or schema  Note: a doc may be well-formed but invalid

33 8/6/2015Comp Sci 34633 DTD  Document Type Definition  Uses Extended Backus-Naur Form (EBNF) grammar to define structure  DTDs exist for XHTML strict and transitional  Used by validation services

34 8/6/2015Comp Sci 34634 Document Type Definitions  Enables XML parser to verify whether XML document is valid  Allow independent user groups to check structure and exchange data in standardized format  Expresses set of rules for structure using EBNF grammar  ELEMENT type declaration Defines rules Defines rules  ATTLIST attribute-list declaration Defines an attribute Defines an attribute

35 8/6/2015Comp Sci 34635 DTD for 2letter.xml <!ELEMENT letter ( contact+, salutation, paragraph+, closing, signature )> <!ELEMENT contact ( name, address1, address2, city, state, zip, phone, flag )>

36 8/6/2015Comp Sci 34636 Indicators  +: one or more elements  *: optional element that can occur any number of times  ?: optional element that can occur at most once  No indicator: exactly once

37 8/6/2015Comp Sci 34637 ATTLIST – Attribute-List Declaration  Defines type If no type, arbitrary or ignore If no type, arbitrary or ignore Attribute must be present Attribute must be present Attribute if present must have the given fixed value Attribute if present must have the given fixed value

38 8/6/2015Comp Sci 34638 XHTML11.DTD

39 8/6/2015Comp Sci 34639 Why Schema? Development feels DTD inflexible Development feels DTD inflexible Cannot manipulate DTD as XML documents Cannot manipulate DTD as XML documents DTD defines structure, not contents DTD defines structure, not contents 5 5 5 is treated as PCDATA – Parsed Character Data5 is treated as PCDATA – Parsed Character Data Parser verifies that 5 is PCDATA but not numericParser verifies that 5 is PCDATA but not numeric Even string is acceptableEven string is acceptable XML Schema allows specification that quantity must be numericXML Schema allows specification that quantity must be numeric

40 8/6/2015Comp Sci 34640 Schema  New and improved method describing XML doc structure  Uses XML syntax  Schema is an XML document Schemas may be modified by software Schemas may be modified by software  Allows more detailed specification of element content  Tutorial: www.w3schools.com/schema/default.asp www.w3schools.com/schema/default.asp

41 8/6/2015Comp Sci 34641 W3C XML Schema Documents  Properties Specify XML document structure Specify XML document structure Do not use EBNF grammar Do not use EBNF grammar Use XML syntax Use XML syntax Can be manipulated like other XML documents Can be manipulated like other XML documents Require validating parsers Require validating parsers W3C XML schemas www.w3.org/XML/Schema W3C XML schemas www.w3.org/XML/Schemawww.w3.org/XML/Schema XML document is “Schema valid” meansXML document is “Schema valid” means XML document conforms to a schema document XML document conforms to a schema document Schemas uses.xsd extensionSchemas uses.xsd extension

42 8/6/2015Comp Sci 34642 W3C XML Schema Documents  Root element schema e.g. book.xsd Contains elements that define the XML document structure Contains elements that define the XML document structure targetNamespace targetNamespace Namespace of XML vocabulary the schema definesNamespace of XML vocabulary the schema defines Same as the xmlns defined in book.xmlSame as the xmlns defined in book.xml Xml document is connected via this targetNamespaceXml document is connected via this targetNamespace element tag element tag Defines element to be included in XML document structureDefines element to be included in XML document structure name and type attributesname and type attributes Specify element’s name and data type respectively Specify element’s name and data type respectively Built-in simple typesBuilt-in simple types String, date, int, double, time, etc String, date, int, double, time, etc

43 8/6/2015Comp Sci 34643 W3C XML Schema Documents  Two categories of data types Simple types Simple types Cannot contain attributes or child elementsCannot contain attributes or child elements Complex types Complex types May contain attributes and child elementsMay contain attributes and child elements complexTypecomplexType Define complex type Define complex type Simple contentSimple content Cannot have child elements Cannot have child elements Complex contentComplex content May have child elements May have child elements

44 8/6/2015Comp Sci 34644 Is the schema correctly specified?  To validate book.xsd, use XSV (XML Schema Validator) open source: www.w3.org/2001/03/webdata/xsv www.w3.org/2001/03/webdata/xsv  Or Free Trials http://www.stylusstudio.com/xml_parsers.html

45 8/6/2015Comp Sci 34645

46 8/6/2015Comp Sci 34646

47 8/6/2015Comp Sci 34647

48 8/6/2015Comp Sci 34648 Online XSD Schema Validator  Schema\book.xml is based on Schema specification  Schema\book.xsd, an XML Schema document, defines the structure for book.xml Schemas use.xsd extension Schemas use.xsd extension  Does book.xml conform to the schema book.xsd?  Cut and paste book.xml and book.xsd into www.xmlforasp.net/Schemavalidator.aspx and validate www.xmlforasp.net/Schemavalidator.aspx  Or SAX (exercise) http://msdn2.microsoft.com/en-us/library/ms756991.aspx

49 8/6/2015Comp Sci 34649 Book.xml XML How to Program C How to Program Java How to Program C++ How to Program Perl How to Program

50 8/6/2015Comp Sci 34650 Book.xsd <schema xmlns = "http://www.w3.org/2001/XMLSchema" xmlns:deitel = "http://www.deitel.com/booklist" targetNamespace = "http://www.deitel.com/booklist"> <element name = "book" type = "deitel:SingleBookType" minOccurs = "1" maxOccurs = "unbounded"/>

51 8/6/2015Comp Sci 34651

52 8/6/2015Comp Sci 34652

53 8/6/2015Comp Sci 34653


Download ppt "8/6/2015Comp Sci 3461 XML_1 Ch. 7 Fall 2010. 8/6/2015Comp Sci 3462 Bibliography  W3C Recommendations  XML online tutorials."

Similar presentations


Ads by Google