XML IST 421.

Slides:



Advertisements
Similar presentations
XML I.
Advertisements

XML 6.3 DTD 6. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:  Elements.
History Leading to XHTML
XML Document Type Definitions ( DTD ). 1.Introduction to DTD An XML document may have an optional DTD, which defines the document’s grammar. Since the.
Document Type Definition DTDs CS-328. What is a DTD Defines the structure of an XML document Only the elements defined in a DTD can be used in an XML.
Document Type Definitions
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
A Technical Introduction to XML Transparency No. 1 XML quick References.
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
Tutorial 11 Creating XML Document
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Introduction to XML This material is based heavily on the tutorial by the same name at
Copyright © 2003 Pearson Education, Inc. Slide 2-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
Basics of HTML Shashanka Rao. Learning Objectives 1. HTML Overview 2. Head, Body, Title and Meta Elements 3.Heading, Paragraph Elements and Special Characters.
Tutorial 3: XML Creating a Valid XML Document. 2 Creating a Valid Document You validate documents to make certain necessary elements are never omitted.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
Validating DOCUMENTS with DTDs
Document Type Definitions Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
August Chapter 2 - Markup and Core Concepts Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.
XML Syntax - Writing XML and Designing DTD's
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
Lecture 6 XML DTD Content of.xml fileContent of.dtd file.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
XML Documents Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Comments PI Document.
IS432 Semi-Structured Data Lecture 2: DTD Dr. Gamal Al-Shorbagy.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
An Introduction to XML Sandeep Bhattaram
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Understanding How XML Works Ellen Pearlman Eileen Mullin Programming the.
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
1/11 ITApplications XML Module Session 3: Document Type Definition (DTD) Part 1.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax presents… XML Syntax v2.0.
Well Formed XML The basics. A Simple XML Document Smith Alice.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
Document Type Definition (DTD) Eugenia Fernandez IUPUI.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
CH 9 Attribute Declaration 1. Objective What is an attribute Declaring attributes Declaring multiple attribute Alternatives to default attributes values.
CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.
Extensible Markup Language (XML) Pat Morin COMP 2405.
XML intro. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display.
XML BASICS and more…. What is XML? In common:  XML is a standard, simple, self-describing way of encoding both text and data so that content can be processed.
Unit 4 Representing Web Data: XML
Creating a Well-Formed Valid Document
Tutorial 9 Working with XHTML
Document Type Definition DTDs
The XML Language.
Session III Chapter 6 – Creating DTDs
Chapter 7 Representing Web Data: XML
Creating an XML Document
Tutorial 9 Working with XHTML
New Perspectives on XML
14 XML.
Session II Chapter 6 – Creating DTDs
Allyson Falkner Spokane County ISD
Document Type Definition (DTD)
Review of XML IST 421 Spring 2004 Lecture 5.
Presentation transcript:

XML IST 421

XML eXtensible Markup Language Used for digital representation of documents Store, process, search, transmit, display and print documents www.w3c.org/xml - current information about XML

XML Basic building block is the element, defined by tags Root element contains all of the other elements Attributes describe properties of elements XML uses delimiters to differentiate character data Less than < and greater than > called a tag

XML Elements Name the contents of the element. Typically in pairs with a start and end tag. Some elements take attributes. The structure describes the relationship between the elements. Example: <order_no>101</order_no>

XML Elements Letters Digits Underscore character Dot Hyphen May start with a letter or an underscore May consist of: Letters Digits Underscore character Dot Hyphen Cannot start with the string “xml”

XML Elements XML names are case sensitive unlike HTML tags which are not Must have one root element Similar to the <HTML>; </HTML> in html type of document Programmer defines a root name First line must be xml declaration <?xml version=“1.0”?> (Note: ? Means information is passed)

XML Comments <!-- ………--> Any text desired can be placed within the <!-- -- > Example: <!-- Updated Apr 3 -->

XML Processing Instructions Enables the passing of information to another application Format: <?… ?> Specifies version. Example: <?xml version “1.0”?>

Let’s Practice Open an editor Declare the XML version as “1.0” Create a Root Element, called class_listing Note that every element must have both a beginning and ending tag Save as: class_listing.xml Add some other elements! Create data within each element! Test this in the browser.

Review the Practice XML data is hierarchical Elements contained within other elements are called children Elements that contain children are called parent elements – nesting Each XML document contains a root element Element names describe the data

Components of XML Documents XML Declaration First line of document Declaration tag begins with: <?xml version=“1.0” encoding=“UTF-8” standalone=“no”?> May contain 3 attributes: version=“1.0” encoding=“UTF-8” (default if not given) standalone=“yes” or standalone=“no” (default) UTF-8 = 8-bit Unicode character-encoding scheme. Others are UTF-16, UTF-32, and ISO-10646-UCS-2.

Attributes Attributes may be attached to elements Attributes have: Names Values Name is separated from value by “=“ sign Value must have “ “ around it

Attributes Creates additional information It is often information about the ELEMENT content Nesting an ELEMENT within others may accomplish the same purpose

Let’s Practice Add attribute to define categorize of student status <student status=“sr”> Add this attribute to all students Remember to save with .xml extension.

XML Entities Entities are used as placeholders for content Two types of entities: General Parameter

XML General Entities Placeholders for any information contained in the root element Three types: Character – used in place of special characters Content – used to mark the place of a common block of content that you type often Unparsed – used for binary or nontext data like images or video clips

Character Entities Some tag delimiter characters have special meaning in XML <?xml version=“1.0”?> <equation> 50 < 100 </equation> Causes a syntax error

Character Entities Solve problem by using character entities: > > < < “ " ‘ &apos;

Content Entities Used to mark the place of a common block of content that you type often or that may change Internal entities – defined as part of the DTD within the XML document Example: <!DOCTYPE class_listing [ <!ENTITY campus "Harrisburg"> ]> <class_campus>Penn State &campus;</class_campus> External entities – information saved in an external file with a .xml extension

Unparsed Entities Used for binary or nontext data like images or video clips <!ENTITY picture SYSTEM “sunset.gif” NDATA GIF> NDATA = notation data The unparsed entity declaration tells the processing system not to parse the data but rather to pass it through as is.

Well-Formed XML Document that adheres to XML syntax rules – well formed Rules: Must contain only one root element All elements must have a start and end tag Elements must be nested properly and cannot overlap <book><chapter> … </book></chapter>

Well-Formed XML Rules (cont.) All attributes must have a value and must be enclosed in quotes <student status=“sr”> Attributes must be placed in the start tag of an element and may appear only once Element names are case-sensitive <STUDENT> vs. </student>

Well-Formed XML Rules (cont.) Certain markup characters are reserved such as < and >. Must use a character entity instead Element names may start with letters or an underscore; names may contain only letters, numbers, hyphens, periods, and underscore Element names may not start with xml

XML Parser XML Parser is a program that checks an XML document to ensure it follows the rules and is well formed. Nonvalidating parser – looks for syntax errors according to the language rules Validating parser – checks your document against a DTD or schema Like compilers, one error may cause many messages

Lab Create an XML document for the following: Camping Trip Gear List The following is a list of items that are essential on any camping trip: Flashlight Hiking boots Sleeping bag Pocket knife Bug spray Compass Hatchet Lantern Shovel Tent Bucket Ground cloth

Document Type Definition (DTD)

DTD Add rules to an XML document that enforce structure Document Type Definition(DTD) XML Schema

DTD Validates a document against its model, i.e. declares what is legal Define the elements your document can contain Define the order in which elements appear Require that certain elements appear Define the allowed number of occurrences of a given element Define the type of data an element can contain Define child elements for a given element Define the attributes for each of your elements Assign constraints to the attribute values

DTD XML documents do not have to include a DTD DTD becomes a way to validate a document and guarantees consistency DTD is important when sharing an XML document with other programs A document is valid if it conforms to a DTD An XML document may not be valid and yet be well-formed XML code

DTD There are 2 kinds of DTD declarations: Internal DTD – provided as part of the document External DTD – an external file The syntax and rules for defining the 2 are the same

Element Declarations If you use a DTD with your XML document, DTD must declare all elements used Syntax for declaring an element: <!ELEMENT element_name (content model)>

Element Declarations <?xml version=“1.0”? standalone=“yes”?> <!DOCTYPE merchant_name [ <!ELEMENT merchant_name (#PCDATA)> ]> <merchant_name>Giant Foods</merchant_name>

Content Models for Elements Text: Supports text or character data <!ELEMENT item (#PCDATA)> Elements: Supports content that is another element <!ELEMENT item (element_name)> PCDATA stands for parsed character data Data type is not yet known

Content Models for Elements Mixed content: Supports both text and other elements. <!ELEMENT item (#PCDATA|element_name)> #PCDATA must be first in declaration

Content Models for Elements Empty: Supports an element that has no content <!ELEMENT item (EMPTY)> Any: May contain text or elements <!ELEMENT item (ANY)>

<?xml version=“1.0”?> <invoice> <merchant_name>Giant Foods</merchant_name> <merchant_address> <street>123 Any Street</street> <city>Harrisburg</city> <state>PA</state> </merchant_address> <sales_date>04-10-03</sales_date> <items_purchased> <item price=“2.35” quantity=“1”>Milk</item> <item price=“0.99” quantity=“1”>Eggs 12 count</item> <item price=“2.65” quantity=“1”>Tropicana Orange Juice</item> </items_purchased> </invoice>

Internal DTD <?xml version=“1.0”?> <!DOCTYPE invoice[ <!ELEMENT invoice (merchant_name, merchant_address, sales_date, items_purchased)> <!ELEMENT merchant_name (#PCDATA )> <!ELEMENT merchant_address (street, city, state)> <!ELEMENT street (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)> <!ELEMENT sales_date (#PCDATA)> <!ELEMENT items_purchased (item*)> <!ELEMENT item (#PCDATA)> <!ATTLIST item price NMTOKEN #REQUIRED quantity NMTOKEN #REQUIRED> ]>

DTD Guidelines Special symbols to indicate how many times an element may appear. An * indicates a unit may appear as many times as needed or not at all An + indicates a unit must appear at least once and as many times as needed An ? Indicates the unit can appear only once An , indicates the elements must appear in the order specified

Attributes Syntax for a DTD attribute declaration <!ATTLIST element_name attribute_name data_type default_value attribute_name data_type default_value > Can be located anywhere in the DTD but it is good practice to keep it close to the corresponding element

Attribute Data Types CDATA ID Stands for character/string data Contains any combination of characters except “<“ or “&” Is simple and easy to use ID Defined to have a value that is unique, like a key Must start with a letter

Attribute Data Types IDREF NMTOKEN or NMTOKENS Define an attribute that refers to one of the ID attributes NMTOKEN or NMTOKENS Data typing NMTOKEN type attributes may not contain any white space NMTOKENS type attributes may contain white space May consist of letters, numbers, hyphens, periods, underscores, and colons.

Attribute Default Values #REQUIRED: attribute must contain some value #IMPLIED: attribute has no default value and may be omitted #FIXED fixedvalue: attribute must always be set to the value, fixedvalue Default: merely type a default value instead of the above

DTD Comments Comments may be written in the DTD in the same fashion as for an XML document <!-- This is a comment for a DTD -->

External DTD’s Make sure the standalone value in the XML declaration is set to “no” DTD declaration must tell the parser where to find the DTD file <!DOCTYPE invoice SYSTEM “invoice.dtd”> <!DOCTYPE invoice SYSTEM “http://www.personal.psu.edu/invoice.dtd”>

XML Schemas May 2001, W3C released XML Schema Language recommendation Covers structure Covers data types Alternative to DTD’s More powerful method to describe and set constraints on XML components

Homework Create a DTD for your XML document for the Camping Trip Gear List The following is a list of items that are essential on any camping trip: Flashlight Hiking boots Sleeping bag Pocket knife Bug spray Compass Hatchet Lantern Shovel Tent Bucket Ground cloth