xml a single entity

38
XML XML A Single A Single Entity Entity

Upload: ganesa

Post on 14-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

XML A Single Entity. xml a single entity. Objectives : understand the data model describe the XML Document describe the XML Schema describe the XML Stylsheet (XSL). the data model. Wine wineID winery style vintage country region cost price inventory description. WineStore. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: XML A Single Entity

XMLXMLA Single A Single EntityEntity

Page 2: XML A Single Entity

xmla single entity

ObjectivesObjectives: understand the data model describe the XML Document describe the XML Schema describe the XML Stylsheet (XSL)

Page 3: XML A Single Entity

the data model

WineStore

Wine

wineIDwinerystylevintagecountryregioncostpriceinventorydescription

Page 4: XML A Single Entity

xml Document XML - a markup language capable of describing many different kinds of data

primary purpose - to facilitate the sharing of data across different systems

defined in a formal way

allows programs to modify and validate documents without prior knowledge of their form

picked out from Wikipedia

Page 5: XML A Single Entity

xml schema

an XML Document

provides a template for an XML Document

governs the structure and content

ensures validity of an XML Document

confidence in data transfer

Page 6: XML A Single Entity

xml Stylesheet eXtensible Stylesheet Language (XSL)

allows for the structured format of the XML Document to be presented visually

allows for a single XML document to have a variety of display designs

Page 7: XML A Single Entity

xml Document

• Prolog (XML Declaration)

• Elements

• Attributes

• Rules to follow

• Well-formed XML documents

Page 8: XML A Single Entity

<?xml version="1.0" encoding="UTF-8"?> <wineStore> <wine> <wineID>1</wineID> <winery>Ravenswood</winery> <style>Zinfandel</style> <vintage>2003</vintage> <country>United States</country> <region>Sonoma County, California</region> <cost currency='USdollars'>12.50</cost> <price currency='USdollars'>20.75</price> <inventory>35</inventory> <description>This 2003 Zinfandel has huge, jammy, inky, slightly porty aromas infused with black pepper, vanilla and hints of tar, smoke and coffee blend. A very broad, intense wine with huge fruit, lots of those luscious Dry Creek bing cherry and sweet plum characters.</description> </wine></wineStore>

prologroot element

parent element

child element

siblingelements

Page 9: XML A Single Entity

xml Document - prolog<?xml version="1.0" encoding="UTF-8"?>

basic XML Document:prolog = XML declaration

xml   =   this is an XML document

version="1.0"   =   XML 1.0 is the W3C recommend version

encoding="UTF-8"   =   the character encoding used in the document (UTF 8 corresponds to 8-bit ASCII characters)

back

Page 10: XML A Single Entity

xml Document - root element

<wineStore> …. </wineStore>

the XML document's major theme

must have exactly one and only one root element

all other elements are contained within the one root element

follows the XML declarationback

Page 11: XML A Single Entity

xml Document - parent element

<wine> …. </wine>

any element that contains other elements, child elements

<wineStore> is also a parent element with <wine> as its child element

an element can be a parent element to some elements as well as a child element to another element back

Page 12: XML A Single Entity

xml Document - child element

<style> …. </style>

any element that is contained within another element, the parent element

<style> is a child element of <wine>

<winery>, <vintage>, <country>, <price>, etc. are all also child elements of <wine>

back

Page 13: XML A Single Entity

xml Document - sibling elements

any elements that share a common parent element

<wineID>, <winery>, <vintage>, <style>, <country>, <region>, <cost>, <price>, <inventory>, and <description> are all sibling elements

Page 14: XML A Single Entity

xml Document - elements

<elementName> data </elementName>

<elementName attribute=“value” />(empty tag or empty element)

(example: <img src="Belize.gif" />)

Page 15: XML A Single Entity

xml Document - attributes

• aid in modifying the content of a given element• provide additional or required information • contained within the element's opening tag

<cost currency='USdollars'>7.50</cost>

Page 16: XML A Single Entity

xml Document - Rules

first line = XML Declaration

root element contains all other elements

every element must have an opening tag and a closing tag

attribute values should have quotation marks around them and no spaces

empty tags or empty elements must have a space and a slash (/) at the end of the tag

Comments in the XML language begin with "<!--" and end with "-->"

well-formed XML - abides by rules of syntax

Page 17: XML A Single Entity

NetBeansNetBeans

select ‘New Project’

Page 18: XML A Single Entity
Page 19: XML A Single Entity
Page 20: XML A Single Entity

right click on the newly created

project

select a new XML document

you can also select file/folder and choose XML => XML document

Page 21: XML A Single Entity
Page 22: XML A Single Entity

if we had already written an XML schemabut, we will first just write an

XML Document

Page 23: XML A Single Entity

the start of an XML document- note the .xml extension

Page 24: XML A Single Entity

xml schema• Prolog

• Element Declarations

• Simple Type

• Complex Type

• Attribute Declarations

• Datatype Declarations

•Valid XML documents

Page 25: XML A Single Entity

xml schema

A schema defines:

• the structure of the document • the elements • the attributes • the child elements • the order of elements • the names and contents of all elements • the data type for each element

Page 26: XML A Single Entity

xml schema - prologthe XML declaration:<?xml version=“1.0” encoding=“UTF-8”?>

the Schema declaration:(from chapter)

<xsd:schemaxmlns:xsd=http://www.w3.org/2001/XMLSchemaelementFormDefault="unqualified“>

(from NetBeans)

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://xml.netbeans.org/examples/targetNS" targetNamespace="http://xml.netbeans.org/examples/targetNS" xmlns=http://xml.netbeans.org/examples/targetNS elementFormDefault="qualified">

Page 27: XML A Single Entity

xml schema - element declarations

define the elements in the schema

include:• the element name • the element data type (optional)

basic element declaration format: <xsd:element name="name" type="type">

Page 28: XML A Single Entity

xml schema - element declarations

Two types:

• Simple Type • do NOT have Child Elements • do NOT have Attributes

• Complex Type • can have Child Elements • can have Attributes

Page 29: XML A Single Entity

xml schema- Complex type - child elements

<xsd:element name="wineStore"> <xsd:complexType> <xsd:sequence> <xsd:element name="wine" type="wineDescription" /> </xsd:sequence> </xsd:complexType> </xsd:element>

Page 30: XML A Single Entity

xml schema- Complex type

- attributes

<xsd:element name="cost" type="xsd:decimal"> <xsd:complexType> <xsd:attribute name="currency" type="xsd:string" /> </xsd:complexType> </xsd:element>

Page 31: XML A Single Entity

minOccurs = "1" maxOccurs="unbounded"

Occurrence Indicators:- minOccurs = the minimum number of times an element can occur (here it is 1 time)- maxOccurs = the maximum number of times an element can occur (here it is an unlimited number of times, 'unbounded')

Page 32: XML A Single Entity

<wineStore xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xsi:schemaLocation='http://xml.netbeans.org/examples/targetNS file:/ C:/Documents and Settings/Viji Kannan/Desktop/TheWineStore/wineStoreSchema.xsd'>

these attributes are added to the root element in the XML document

xml schema - Reference

Page 33: XML A Single Entity

xml stylesheet (xsl)

• a means to transform and format the contents of an XML document for display

• separates the data and the presentation logic

• multiple views of the same data can be created using different stylesheets

Page 34: XML A Single Entity

node tree – a hierarchical representation of the entire XML document – each node represents a piece of the XML document, such as an element, attribute or some text content• contains predefined “templates” that contain instructions on what to do with the nodes• uses the match attribute to relate XML element nodes to the templates, and transform them into the resulting document.

xml stylesheet (xsl)

Page 35: XML A Single Entity

XSL - prolog<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/>

• the XML declaration • the stylesheet declaration • the namespace declaration • the output document format

Page 36: XML A Single Entity

XSL - templates• the <xsl:template> element is used to create templates that describe how to display elements and their content

• each template within an XSL describes a single node – to identify which node a given template is describing, use the 'match' attribute

• <xsl:template> defines the start of a template and contains rules to apply when a specified node is matched

Page 37: XML A Single Entity
Page 38: XML A Single Entity