Introduction to XML - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Introduction to XML

Description:

HTML is a language specifically designed for displaying ... File extension: .CSS. Benefits of ... href='books.css' type='text/css' ? Books Book ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 27
Provided by: cob
Learn more at: https://faculty.sfsu.edu
Category:
Tags: xml | css | introduction

less

Transcript and Presenter's Notes

Title: Introduction to XML


1
Introduction to XML
  • ISYS 464

2
HTML vs XML
  • HTML is a language specifically designed for
    displaying information in browser. It doesnt
    carry information about the structure of the
    content held within its page.
  • XML (Extensible MarkUp Language) is a language
    used to represent data in a form that does not
    rely on any particular proprietary technology.
    It uses user-defined tags to give meaningful
    names to data elements. With XML, we separate the
    data content from the data presentation.

3
HTML
ltbodygt lth1gtMy Favorite Booklt/h1gt lth1gtISBN -
1-34567-04-01lt/h1gt ltH1gtAuthorslt/H1gt lth3gtJohn
Smithlt/h1gt lth3gtPeter Chenlt/h1gt lth1gtPrice
45.00lt/h1gt lth1gtDescription This is a grerat
booklt/h1gt lt/bodygt
4
XML
lt?xml version"1.0" ?gt ltBooksgt ltBookgt ltISBNgt1-3456
7-04-01lt/ISBNgt ltAuthorsgt ltAuthorNamegtJohn
Smithlt/AuthorNamegt ltAuthorNamegtPeter
Chenlt/AuthorNamegt ltAuthorNamegtDavid
Chaolt/AuthorNamegt lt/Authorsgt ltPricegt
45.00lt/Pricegt ltDescriptiongtThis is a grerat
booklt/Descriptiongt lt/Bookgt ltBookgt ltISBNgt1-34567-04
-02lt/ISBNgt ltAuthorsgt ltAuthorNamegtAdam
Smithlt/AuthorNamegt lt/Authorsgt ltPricegt
25.00lt/Pricegt ltDescriptiongtThis is a second
great booklt/Descriptiongt lt/Bookgt lt/Booksgt
5
XML Document
  • Well-formed documents
  • Documents comply with the rules of XML syntax.
  • Valid documents
  • Documents that are well-formed and comply with a
    XML schema or Document Type Definition (DTD is a
    file containing the rules used to define the
    document).

6
Well-Formed Documents
  • There is only one root node.
  • All elements must have a start tag and an end tag
    (except for an empty element, see example below)
    Elements must be nested correctly.
  • If an element has an attribute, the attribute
    value must be quoted.
  • An empty element with an attribute
  • ltprice US49 /gt
  • Note XML is case sensitive.

7
XML Documents
  • The XML declaration
  • lt?xml version1.0 ?gt
  • Note xml should be in lower case.
  • Namespaces
  • Define a namespace xmlnsuri where the Uniform
    Resource Identifier is a unique identifier and is
    often a URL.
  • Use a namespace to make a tag unique
  • ltnamespace TagNamegt
  • Elements
  • Each start-tag/end-tag pair, with the data that
    lies between them, is an element.
  • Ex. ltAuthorNamegtJohn Smithlt/AuthorNamegt
  • The start and end tag must be in the same case.

8
  • Attributes Elements can have attributes. These
    are values that are passed to the application,
    but not constitute part of the content of the
    element. Attributes are included as part of the
    elements start tag, and values must be enclosed
    in quote marks.
  • ltFood healthyyesgtSpinachlt/Foodgt
  • ltFood healthyyes tastynogtCarrotlt/Foodgt

9
  • Comments
  • lt!--This is a comment --gt
  • Processing instructions These allow documents to
    contain instructions for applications using XML
    data.
  • lt?NameOfTargetApplication Instructions for
    application?gt

10
Tree View of XML
Books
Book
Book
ISBN
Authors
Price
Description
ISBN
Authors
Price
Description
Author
Author
Author
11
Valid Documents
  • Well-formed documents that conform to an XML
    schema or DTD.
  • XML parsers are programs that are able to
    validate an XML document against schema or DTD.
  • XML parsers are included in IE5 and Netscapt 6
    and onwards.

12
XML SchemaDefinition of an XML Document
  • Namespaces Allow element names to be qualified
    to avoid name collisions.
  • Complex and simple types
  • Elements that contains other elements are complex
    type.
  • Cardinality
  • minOccurs 0 for optional element.
  • maxOccurs specified number or unbounded
  • Compositor
  • Sequence defines an ordered sequence of
    subelements.
  • Choice defines a choice between several possible
    elements.
  • Constraints
  • Uniqueness contraint

13
VS.Net Tools for XML Document and Schema
  • Dataset schema
  • XML Schema
  • XML Document

14
Style Sheets
  • XSL Extensible Stylesheet Language
  • Tell the browser how to display the XML document.
  • With a style sheet, all of the style rules are
    kept in one file and the source document simply
    links to this file.
  • File extension .CSS

15
Benefits of Using Style Sheets
  • Improve document clarity No tags such as ltfontgt
    in an XML document.
  • Allow you to modify the presentation of several
    pages by altering just one file.
  • Allow you to present the same data in different
    ways for different purposes.
  • Reduce download time by caching the style sheet
    on the client.

16
  • Browser screen structure
  • Page
  • Area
  • Block Flow Object Taking up the whole line.
  • In-Line Flow Object Several in-line objects may
    be on the same line.

17
lt?xml version"1.0" ?gt lt?xmlstylesheet
href"books.css" type"text/css"
?gt ltBooksgt ltBookgt ltbtitlegtMy Favorite
Booklt/btitlegt ltISBNgt1-34567-04-01lt/ISBNgt ltAuthors
gt ltAuthorNamegtJohn Smithlt/AuthorNamegt ltAuthorN
amegtPeter Chenlt/AuthorNamegt lt/Authorsgt ltPricegt
45.00lt/Pricegt ltDescriptiongtThis is a grerat
booklt/Descriptiongt lt/Bookgt ltBookgt ltbtitlegtMy
Second Favorite Booklt/btitlegt ltISBNgt1-34567-04-02lt
/ISBNgt ltAuthorsgtAdam Smithlt/Authorsgt ltPricegt
25.00lt/Pricegt ltDescriptiongtThis is a second
great booklt/Descriptiongt lt/Bookgt lt/Booksgt
18
btitle displayblock font-family Aerial,
Helvetica font-weight bold font-size
20pt color 9370db text-align
center ISBN displayblock font-family
Aerial, Helvetica font-weight
bold font-size 12pt color
c71585 text-align left Authors display
inline font-family Aerial, Helvetica font-sty
le italic font-size 10pt color
9370db text-align left
19
Price displayblock font-family Aerial,
Helvetica font-size 12pt color
ff1010 text-align left Description
displayblock font-family Aerial,
Helvetica font-size 12pt color
ff1010 text-align left
20
Demo
  • ASPNet/FavoriteBook.htm

21
Styling XML with XSLT
  • XSLT Extensible Stylesheet Language Transforms
  • XSLT provides a means of transforming one XML
    document into HTML or another XML document.

22
Creating XML From DataSet
  • DataSet object
  • WriteXML(xml file path and name)
  • WriteXMLSchema(xml schema path and name)
  • DemoASPNet/XMLWrite.ASPX

23
dim strConn as string "ProviderMicrosoft.Jet.OLE
DB.4.0Data Source c\sales2k.mdb" dim objConn
as new OledbConnection(strConn) dim strSQL as
string "select from customer" dim objDataSet
as new Dataset() dim objAdapter as new
OledbDataAdapter(strSQL, objConn) objAdapter.Fill(
objDataSet, "Cust") dim objDataView as new
DataView(objDataSet.tables("Cust")) dgCustomer.Dat
asourceobjDataView dgCustomer.DataBind() objDataS
et.writeXML("c\inetpub\wwwroot\testWriteXML.XML")

24
Reading Data into a DataSet from an XML File
  • Dataset object
  • ReadXMLSchema(file path and name)
  • ReadXML(file path and name)
  • Demo ASPNet/XMLRead.aspx

25
dim objDataSet as new Dataset() objDataSet.ReadXML
("c\inetpub\wwwroot\testWriteXML.XML") dim
objDataView as new DataView(objDataSet.tables("Cus
t")) dgCustomer.DatasourceobjDataView dgCustomer
.DataBind() end sub
26
XML Query Languages
  • X-Query
  • XPath
  • SQL/XML
Write a Comment
User Comments (0)
About PowerShow.com