xml a single entity
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 PresentationTRANSCRIPT
XMLXMLA Single A Single EntityEntity
xmla single entity
ObjectivesObjectives: understand the data model describe the XML Document describe the XML Schema describe the XML Stylsheet (XSL)
the data model
WineStore
Wine
wineIDwinerystylevintagecountryregioncostpriceinventorydescription
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
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
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
xml Document
• Prolog (XML Declaration)
• Elements
• Attributes
• Rules to follow
• Well-formed XML documents
<?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
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
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
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
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
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
xml Document - elements
<elementName> data </elementName>
<elementName attribute=“value” />(empty tag or empty element)
(example: <img src="Belize.gif" />)
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>
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
NetBeansNetBeans
select ‘New Project’
right click on the newly created
project
select a new XML document
you can also select file/folder and choose XML => XML document
if we had already written an XML schemabut, we will first just write an
XML Document
the start of an XML document- note the .xml extension
xml schema• Prolog
• Element Declarations
• Simple Type
• Complex Type
• Attribute Declarations
• Datatype Declarations
•Valid XML documents
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
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">
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">
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
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>
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>
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')
<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
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
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)
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
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