1 / 52

TUTORIAL 1

TUTORIAL 1. CREATING AN XML DOCUMENT. Tutorial 1 project. Complete Case Problem 1: Jackson Electronics Include your name in the upper left hand corner Post the completed project on your web site Send an e-mail before Tuesday 11:59 pm To: jim@larson-tech.om

amato
Télécharger la présentation

TUTORIAL 1

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. TUTORIAL 1 CREATING AN XML DOCUMENT New Perspectives on XML, 2nd Edition Tutorial 1

  2. Tutorial 1 project • Complete Case Problem 1: Jackson Electronics • Include your name in the upper left hand corner • Post the completed project on your web site • Send an e-mail before Tuesday 11:59 pm To: jim@larson-tech.om Subject: Case Problem 1 by <your name> Body: url to your completed project New Perspectives on XML, 2nd Edition Tutorial 1

  3. Course project 1: Using an existing XML vocabulary Goal: To use an existing XML vocabulary for implementing a computing project in which you are interested • Reviewhttp://en.wikipedia.org/wiki/Xml_languages • Select an XML vocabulary that matches your interests • Familiarize yourself with XML vocabulary by reading its Wikipedia entry. • Determine if there is an XML vocabulary processor/interpreter available for free (or possibly a 30-day free trial). You may need to do several Google searches to identify and locate these processors • Prepare a classroom presentation that demonstrates the following • create the document using the XML vocabulary. You may use an editing tool that generates the XML vocabulary code • Display the XML code • Render the document using the XML vocabulary processor/interpreter New Perspectives on XML, 2nd Edition Tutorial 1

  4. Course project 1: Using an existing XML vocabulary Example Projects • Use MathXML to create a tutorial for deriving the quadratic equation • Use MusicXML to create a document for an original music composition that can be renderer as an audio file and displayed as a musical score • Use Scalable Vector Graphics (SVG) to display two-dimensional geometric figures for use in a tutorial for calculating areas of rectangles, triangles, and parallelograms • Use RDF to create Entity-Relationship description of a database that you designed for your database management class • Use SCXML to create a state transition diagram for a software project that you have worked on • Use DTTA to create documentation for a computer program you have written New Perspectives on XML, 2nd Edition Tutorial 1

  5. Course project 2: Define and use an new XML vocabulary Goal: To gain proficiency in using XML design and development tools • Define a new XML vocabulary by creating a CSS or SCHEMA • Create an XML document using that vocabulary • Validate the XML document using its DTD or SCHEMA • Using either CSS or XSLT, render the document on a laptop display • Using either CSS or XSLT, render the document on a small hand-held display • Using either CSS or XSLT, render the document as a PDF file. New Perspectives on XML, 2nd Edition Tutorial 1

  6. Course project 2: Define and use an new XML vocabularyExample Projects • Enter and display recipes (at least three yummy dishes) • Enter and display ancestry information including stories and antidotes • Enter and display three guided tours with pictures of points of interest in Portland • Music genre including description and examples from YouTube New Perspectives on XML, 2nd Edition Tutorial 1

  7. Project Approval process Write a proposal that includes: • Student Name(s) • Project Name • Goal of the project • Intended user of the project software • Software tools and languages to be used to implement the project • Estimated time in person-hours to (a) learn how to use the software tools and languages (b) design the project, (c) implement and test the project • Learning goals: what do you hope to learn by completing this project Send an e-mail before Tuesday 11:59 pm: To: jim@larson-tech.om Subject: Course project <n> proposal by <your name> New Perspectives on XML, 2nd Edition Tutorial 1

  8. Introductions • Who is your instructor? • Who you are? • As an undergraduate, what was your major and minor? • What do you know about XML? • Why are you taking this class? New Perspectives on XML, 2nd Edition Tutorial 1

  9. INTRODUCING XML • XML stands for Extensible Markup Language. A markup language specifies the structure and content of a document. • Because it is extensible, XML can be used to create a wide variety of document types. New Perspectives on XML, 2nd Edition Tutorial 1

  10. Extensibility • Some extensions may require changes to the browser or perhaps a different browser • Existing browsers can render the document containing the extension • New data types that can be represented using existing presentation styles • New monetary unit, changing employee number from 7 to 9 digits • Requires a new browser to interpret and render a document • VoiceXML • X3D • Use caution when using extensions • May not be supported on the standard browsers • Limit portability across browsers New Perspectives on XML, 2nd Edition Tutorial 1

  11. INTRODUCING XML • XML is a subset of the Standard Generalized Markup Language (SGML) which was introduced in the 1980s. • What is your experience with SGML? • SGML is very complex and can be costly. • These reasons led to the creation of Hypertext Markup Language (HTML), a more easily used markup language. • What is your experience with HTML? New Perspectives on XML, 2nd Edition Tutorial 1

  12. THE LIMITS OF HTML • HTML was designed for formatting text on a Web page. • It was not designed for dealing with the content of a Web page. • HTML is not extensible. • Browser developers have added features to HTML • Non standard features decrease portability of HTML • Confusing mix of HTML features New Perspectives on XML, 2nd Edition Tutorial 1

  13. THE LIMITS OF HTML • HTML cannot be applied consistently. • Different browsers require different standards • The final document be rendered differently on one browser compared with another. • HTML 5.0 is the latest standard specification being created by the World Wide Web Consortium • Still evolving • Browsers differ in how much of HTML 5.0 they support. New Perspectives on XML, 2nd Edition Tutorial 1

  14. THE 10 PRIMARY XML DESIGN GOALS • XML must be easily usable over the Internet • XML must support a wide variety of applications • Databases, word processing, spreadsheets, financial transactions, e-mail, etc • XML must be compatible with SGML • It must be easy to write programs that process XML documents • Many tools for developing and process XML documents • The number of optional features in XML must be kept to a minimum, ideally zero New Perspectives on XML, 2nd Edition Tutorial 1

  15. THE 10 PRIMARY XML DESIGN GOALS — CONTINUED • XML documents should be clear and easily understood by nonprogrammers • Tree-like structure • Meaningful elements names • The XML design should be prepared quickly • The design of XML must be exact and concise • XML documents must be easy to create • Terseness in XML markup is of minimum importance New Perspectives on XML, 2nd Edition Tutorial 1

  16. XML VOCABULARIES(a.k.a. XML application)http://en.wikipedia.org/wiki/Xml_languages New Perspectives on XML, 2nd Edition Tutorial 1

  17. WELL-FORMED AND VALID XML DOCUMENTS • An XML document is well-formed if it contains no syntax errors and fulfills all of the specifications for XML code as defined by the W3C. • An XML document is valid if it is well-formed and also satisfies the rules laid out in the DTD or schema attached to the document. • DTD = Document Type Definition • Both DTD and schema • Rules for how to structure data inn a document • Specified by developers or standards body New Perspectives on XML, 2nd Edition Tutorial 1

  18. Creating an XML Document • Document • Description of data • Application (may require a special browser to process) • Created using a text editor • Do not use Microsoft Word because of embeded invisible control characters • May be created using any of several XML editing tools New Perspectives on XML, 2nd Edition Tutorial 1

  19. THE STRUCTURE OF AN XML DOCUMENT • XML documents consist of three parts • The prolog • The document body • The epilog • The prolog is optional and provides information about the document itself New Perspectives on XML, 2nd Edition Tutorial 1

  20. THE STRUCTURE OF AN XML DOCUMENT • The document body contains the document’s content in a hierarchical tree structure. • The epilog is also optional and contains any final comments or processing instructions. New Perspectives on XML, 2nd Edition Tutorial 1

  21. THE STRUCTURE OF AN XML DOCUMENT: CREATING THE PROLOG • The prolog consists of four parts in the following order: • XML declaration • Miscellaneous statements or comments • Processing instructions • Document type declaration • May be embedded in the XML document • May reference an external document New Perspectives on XML, 2nd Edition Tutorial 1

  22. THE STRUCTURE OF AN XML DOCUMENT: THE XML DECLARATION • First line of code in an XML document. • Tells the processor what follows is written using XML. • Provide any information about how the parser should interpret the code. • The complete syntax is: <?xml version=“version number” encoding=“encoding type” standalone=“yes | no” ?> • A sample declaration might look like this: <?xml version=“1.0” encoding=“UTF-8” standalone=“yes” ?> • Other encodings: http://www.iana.org/assignments/character-sets Do not use curley quotes! New Perspectives on XML, 2nd Edition Tutorial 1

  23. THE STRUCTURE OF AN XML DOCUMENT: INSERTING COMMENTS • Comments or miscellaneous statements • Go after the declaration. • Comments may appear anywhere after the declaration. • The syntax for comments is: <!- - comment text- -> • This is the same syntax for HTML comments New Perspectives on XML, 2nd Edition Tutorial 1

  24. ELEMENTS • Elements are the basic building blocks of XML files. • Elements contain an opening tag and a closing tag • Content is stored between tags • A closed element, has the following syntax: <element_name>Content</element_name> • Example: <Artist>Miles Davis</Artist> New Perspectives on XML, 2nd Edition Tutorial 1

  25. ELEMENT NAMES • Element names • Case sensitive • Must begin with letter or underscore character • May not contain blank spaces • Can not begin with “xml” • Name should appear in opening and closing tag • Example: <Artist>Miles Davis</Artist> New Perspectives on XML, 2nd Edition Tutorial 1

  26. EMPTY ELEMENTS • Empty element = element with no content • May contain attributes • HTML Example: <br/> <img src="url" alt="some_text"/> • VoiceXML Example: </break strength = “strong”> attribute New Perspectives on XML, 2nd Edition Tutorial 1

  27. ELEMENTS • Nested elements are called child elements. • Elements must be nested correctly. Child elements must be enclosed within their parent elements. • Example: <album>Kind of Blue <track>So What (:22)</track> <track>Blue in Green (5:37)</track> </album> New Perspectives on XML, 2nd Edition Tutorial 1

  28. ELEMENTS AND ATTRIBUTES • All elements must be nested within a single document element, called the root element. There can be only one root element. New Perspectives on XML, 2nd Edition Tutorial 1

  29. WORKING WITH ATTRIBUTES • An attribute is a feature or characteristic of an element. Attributes are text strings and must be placed in single or double quotes. The syntax is: <album attribute=“value”> … </element_name> Do not use curley quotes! New Perspectives on XML, 2nd Edition Tutorial 1

  30. GWORKING WITH ATTRIBUTES • Attribute name must begin with a letter or underscore (_) • Spaces are not allowed • Do not begin with the test string “xml” • An attribute name can appear only once within an element • Attribute names are case sensitive A frequent error New Perspectives on XML, 2nd Edition Tutorial 1

  31. ELEMENTS AND ATTRIBUTES: ADDING ELEMENTS TO THE JAZZ.XML FILE This figure shows the revised document New Perspectives on XML, 2nd Edition Tutorial 1

  32. CHARACTER REFERENCES • Special characters, such as the symbol for the British pound, can be inserted into your XML document by using a character reference. The syntax is: &#nnn; New Perspectives on XML, 2nd Edition Tutorial 1

  33. CHARACTER REFERENCES • Character is a character reference number or name from the ISO/IEC character set. http://en.wikipedia.org/wiki/ISO/IEC_8859-1 • Character references in XML are the same as in HTML. New Perspectives on XML, 2nd Edition Tutorial 1

  34. CHARACTER REFERENCES This figure shows commonly used character reference numbers New Perspectives on XML, 2nd Edition Tutorial 1

  35. CHARACTER REFERENCES This figure shows the revised Jazz.XML file character reference New Perspectives on XML, 2nd Edition Tutorial 1

  36. PARSED CHARACTER DATA • Parsed character data, or pcdata consists of all those characters that XML treats as parts of the code of XML document • The XML declaration • The opening and closing tags of an element • Empty element tags • Character or entity references • Comments New Perspectives on XML, 2nd Edition Tutorial 1

  37. CDATA SECTIONS • A CDATA (character data) section is a large block of text the XML processor will interpret only as text. • The syntax to create a CDATA section is: <! [CDATA [ Text Block ] ]> New Perspectives on XML, 2nd Edition Tutorial 1

  38. CDATA SECTIONS • In this example, a CDATA section stores several HTML tags within an element named HTMLCODE: <htmlcode> <![CDATA[ <h1>The Jazz Warehouse</h1> <h2>Your Online Store for Jazz Music</h2> ] ]> </htmlcode> New Perspectives on XML, 2nd Edition Tutorial 1

  39. CDATA SECTIONS This figure shows the revised Jazz.XML file CDATA section New Perspectives on XML, 2nd Edition Tutorial 1

  40. PARSING AN XML DOCUMENT New Perspectives on XML, 2nd Edition Tutorial 1

  41. DISPLAYING AN XML DOCUMENT IN A WEB BROWSER • XML documents can be opened in Internet Explorer or in Netscape Navigator. • If there are no syntax errors. IE will display the document’s contents in an expandable/collapsible outline format including all markup tags. • Netscape will display the contents but neither the tags nor the nested elements. New Perspectives on XML, 2nd Edition Tutorial 1

  42. DISPLAYING AN XML DOCUMENT IN A WEB BROWSER New Perspectives on XML, 2nd Edition Tutorial 1

  43. LINKING TO A STYLE SHEET • Unlike HTML documents, XML documents do not include formatting information • Need to link XML document to a style sheet to format the document. • The XML processor will combine the style sheet with the XML document and apply any formatting codes defined in the style sheet to display a formatted document. • Style sheet languages used with XML: • Cascading Style Sheets (CSS) • Extensible Style Sheets (XSL) Also used by html documents New Perspectives on XML, 2nd Edition Tutorial 1

  44. LINKING TO A STYLE SHEET • There are some important benefits to using style sheets: • By separating content from format, you can concentrate on the appearance of the document • Different style sheets can be applied to the same XML document • Any style sheet changes will be automatically reflected in any Web page based upon the style sheet New Perspectives on XML, 2nd Edition Tutorial 1

  45. APPLYING A STYLE TO AN ELEMENT • To create a style sheet to a document, use the following syntax: selector {attribute1:value1; attribute2:value2; …} • selector is an element (or set of elements) from the XML document. • attribute and value are the style attributes and attribute values to be applied to the document. New Perspectives on XML, 2nd Edition Tutorial 1

  46. APPLYING A STYLE TO AN ELEMENT • For example: artist {color:red; font-weight:bold} • will display the text of the artist element in a red boldface type. New Perspectives on XML, 2nd Edition Tutorial 1

  47. CREATING PROCESSING INSTRUCTIONS • The link from the XML document to a style sheet is created using a processing statement. • A processing instruction is a command that gives instructions to the XML parser. New Perspectives on XML, 2nd Edition Tutorial 1

  48. CREATING PROCESSING INSTRUCTIONS • For example: <?xml-stylesheet type=“style” href=“sheet” ?> • Style is the type of style sheet to access and sheet is the name and location of the style sheet. New Perspectives on XML, 2nd Edition Tutorial 1

  49. THE JW.CSS STYLE SHEET This figure shows the cascading style sheet stored in the jw.css file New Perspectives on XML, 2nd Edition Tutorial 1

  50. LINKING TO THE JW.CSS STYLE SHEET This figure shows how to link the JW.css style sheet to the Jazz.xml file processing instruction to access the jw.css style sheet New Perspectives on XML, 2nd Edition Tutorial 1

More Related