1 / 38

XML A Single Entity

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.

ganesa
Télécharger la présentation

XML A Single Entity

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. XML A Single Entity

  2. xml a single entity • Objectives: • understand the data model • describe the XML Document • describe the XML Schema • describe the XML Stylsheet (XSL)

  3. the data model • Wine • wineID • winery • style • vintage • country • region • cost • price • inventory • description WineStore

  4. 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

  5. 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

  6. 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

  7. xml Document • Prolog (XML Declaration) • Elements • Attributes • Rules to follow • Well-formed XML documents

  8. <?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> prolog root element parent element sibling elements child element

  9. 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

  10. 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 declaration back

  11. 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

  12. 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

  13. 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

  14. xml Document - elements <elementName> data </elementName> <elementName attribute=“value” /> (empty tag or empty element) (example: <img src="Belize.gif" />)

  15. xml Document - attributes <cost currency='USdollars'>7.50</cost> • aid in modifying the content of a given element • provide additional or required information • contained within the element's opening tag

  16. xml Document - Rules well-formed XML - abides by rules of syntax • 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 "-->"

  17. NetBeans select ‘New Project’

  18. select a new XML document right click on the newly created project you can also select file/folder and choose XML => XML document

  19. if we had already written an XML schema but, we will first just write an XML Document

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

  21. xml schema • Prolog • Element Declarations • Simple Type • Complex Type • Attribute Declarations • Datatype Declarations • Valid XML documents

  22. 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

  23. xml schema - prolog the XML declaration: <?xml version=“1.0” encoding=“UTF-8”?> the Schema declaration: (from chapter) <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema elementFormDefault="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">

  24. 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">

  25. 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

  26. 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>

  27. 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>

  28. 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')

  29. xml schema - Reference <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

  30. 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

  31. xml stylesheet (xsl) • 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.

  32. 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

  33. 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

More Related