XML Basics II
-
Upload
shielobolasco -
Category
Documents
-
view
225 -
download
0
Transcript of XML Basics II
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 1/23
XML Basics IIXML Basics II
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 2/23
XML Basics : Review XML Basics : Review
� Extensible Markup Language
� Tag-based syntax, very much like HTML
�
You get to make up your own tags (or you can usean existing tag set to solve a particular problem)
� XML does not replace HTML
� XML is used to structure and describe information
� XML can be used as a way to interchange data
between disparate systems
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 3/23
Related XML TechnologiesRelated XML Technologies
� XPath ² eX tensible Path Language
± Used to extract data from inside an XML file
± Uses a path-like syntax, similar to directory or folder paths like´drive:/folder/folder/fileµ
� XSLT ² eX tensible Stylesheet Language Transformation
± Styling language that takes an XML file and ´transformsµ it intosomething else like, HTML, PDF, ASCII or even another XML file
� XQuery ² used to perform query functions on XML data,
similar to SQL for databases� XPointer and XLink ² used for creating hyperlinks to XML
documents and arbitrary points within XML documents
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 4/23
Tools for Working with XML Tools for Working with XML
� Simple Text Editor ² Notedpad, Textpad, Bbedit ± Simple to use, no frill editing
� A dobe Dreamweaver
± Good XML editing features: color coding, tag completion
± Can check XML file for well-formedness and validate it against a givenDocument Type Definition or Schema
� A ltova XMLSpy
± Advanced XML tool, intended for professional use
± XSLT debugging and XPath expression testing
� Microsoft Visual Web Developer Express
± Free, and has great XML editing features: tag completion, color coding,real time validation
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 5/23
Describing Information : Business CardDescribing Information : Business Card
Typical information found on a Business Card
Juan Dela Cruz
(02) 567-2345(02) 567-7644
(02) 567-1234
(home)
(work)
(fax)
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 6/23
Describing Information with XMLDescribing Information with XML
Same business card data, expressed in XML
<BusinessCard>
<Name> Juan Dela Cruz</Name>
<Phone type=³home´>(02) 567-2345</Phone>
<Phone type=³work´>(02) 567-7644</Phone>
<Phone type=fax´>(02) 567-1234</Phone>
<Email>[email protected]</Email>
</BusinessCard>
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 7/23
Advantages of XML Advantages of XML
� Content is separate from any notion of
presentation
�
Information can be easily read and understood� XML is an open format that can be processed
by any XML-aware application, like a browser,
word processor, spreadsheet, etc.
� XML data can be exchanged between systemsthat were never designed to do so
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 8/23
Potential Drawbacks of XMLPotential Drawbacks of XML
� XML is not especially good at handling very largeamounts of data
� XML can quickly become difficult to read if a lot of
information is included in one file
� Certain types of data (images, other binary data) are notrepresented well in XML
�
XML·s simplicity makes it easy to get in over your headpretty quickly
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 9/23
What have we done so far? What have we done so far?
� Started XML basic structure
� Identify the Character References
�Use the CDATA
� Incorporate a CSS document
� Tree Structure of XML Vocabularies
± Hierarchical relationships between elements: ParentElement, Child Element and Sibling Element
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 10/23
Working with XMLN
amespaces Working with XMLN
amespaces
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 11/23
XML NamespacesXML Namespaces
� Have the form <html<html xmlnsxmlns=³http://www.w3.org/1999/xhtml´>=³http://www.w3.org/1999/xhtml´>
� What are namespaces?
± It provide a way to prevent tags with same names but different meanings
from colliding with each other
<table>
<tr>
<td>Product</td>
<td>Price</td>
</tr>
<tr>
<td>Coffee Table</td>
<td>199.99</td>
</tr>
</table>
<table sku=³1429815132´>
<type>Coffee Table</type>
<price>199.99</price>
<instock>yes</instock>
<material>maple</material>
</table>
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 12/23
XML NamespacesXML Namespaces�
Namespaces solve this problem<table
xmlns:´http://www.w3.org/tr/xhtml´
xmlns:furn=³http://www.furniture.org/tables´>
<tr>
<td>Product</td>
<td>Price</td></tr>
<tr><td>
<furn:table sku=³1429815132´>
<furn:type>Coffee Table</furn:type>
</furn:table>
</td><td>
<furn:table sku=³1429815132´> <furn:price>199.99 </furn:price>
</furn:table>
</td></tr>
</table>
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 13/23
XML NamespacesXML Namespaces
� Namespace is a defined collection of element
and attribute names.
�
Applying a namespace to an XML documentinvolves two steps:
± Declaring the namespace
± Identifying the elements and attributes within thedocument that belong to that namespace.
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 14/23
Adding a Namespace to a Style Sheet Adding a Namespace to a Style Sheet
� To declare a namespace in a style sheet, add the following rule tothe stylesheet file:
± Syntax: @namespace prefix url(uri);
± Example:
@namespace furn url(http://furniture.org/table);
� Applying a Namespace to a Selector
± Syntax: prefix\:selector {attribute:value «}
± Example: furn\:type {width: 150px} or
furn\:* {font-size: 12pt}
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 15/23
In Combining XML and HTMLIn Combining XML and HTML
� Don·t forget this:<html xlmns=³http://www.w3.org/1999/xhtml´
xlmns:furn=³http://furniture.org/table´>
<head>
<title> Jazz Furniture </title>
<link rel=³stylesheet´ href=³report.css´ type=³text/css´/>
<link rel=³stylesheet´ href=³table.css´ type=³text/css´ />
</head>
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 16/23
Working with Data Islands Working with Data Islands
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 17/23
Data IslandsData Islands
�� Data IslandsData Islands are a feature of Internet Explorer
� Embed XML information directly into a web
page and then connect (or ´bindµ) it to layoutelements
� Uses the <XML><XML> tag to enclose the data
�
The datasrcdatasrc and dataflddatafld attributes are used todefine a binding to the XML data
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 18/23
HTML TemplateHTML Template<html>
<head>
<title>XML Data Binding</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border=³1´>
<tr>
<th>Photo</th>
<th>Description</th>
<th>Type</th>
</tr>
<tr>
<td> <img /> </td><td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
Photo Description Type
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 19/23
Data Island within HTML DocData Island within HTML Doc<items>
<item id=³item1´>
<name>Mocha</name>
<type>Coffee</type>
<photo>photos/mocha.jpg</photo>
</item>
<item id=³item2´>
<name>Frappucino</name>
<type>Coffee</type>
<photo>photos/frap.jpg</photo>
</item>
<item id=³item3´>
<name>Earl Grey</name>
<type>Tea</type><photo>photos/earl.jpg</photo>
</item>
</items>
Insert this into the HTML Doc(copy and paste is you have
already the xml file)
. . .
<body>
<items>
<item id=³item1´>
<name>Mocha</name>
<type>Coffee</type>
<photo>photos/mocha.jpg</photo>
</item>
. . .
. . .
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 20/23
Add the Add the <XML><XML>
<body>
<xml id=³<xml id=³myXmlDataSourcemyXmlDataSource´>´>
<items>
<item>
<name> Mocha </name>
«
«
</xml></xml>
«
«
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 21/23
Use theUse the datasrcdatasrc
<table datasrcdatasrc=³#=³#myXmlDataSourcemyXmlDataSource ´border=³1´>
<tr>
<th>Photo</th>
<th>Description</th>
<th>Type</th>
</tr>
«
«
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 22/23
Use theUse the dataflddatafld
«
<tr>
<td><img datasrc= ³#myXmlDataSource´datasrc= ³#myXmlDataSource´
datafld=³photodatafld=³photo´ /> </td><td><span datasrc= ³#myXmlDataSource´datasrc= ³#myXmlDataSource´
datafld=³name´datafld=³name´> </td>
<td><span datasrc= ³#myXmlDataSource´datasrc= ³#myXmlDataSource´
datafld=³type´datafld=³type´></td></tr>
</table>
«
8/6/2019 XML Basics II
http://slidepdf.com/reader/full/xml-basics-ii 23/23
Data Island outside HTML Doc
<xml id=³ExternalSource´ src=³items.xml´src=³items.xml´>
. . .
<table datasrc=³#ExternalSource´datasrc=³#ExternalSource´>
. . .<td><span datasrc= ³#ExternalSource´datasrc= ³#ExternalSource´
datafld=³name´datafld=³name´></td>
<td><img datasrc= ³#ExternalSource´datasrc= ³#ExternalSource´
datafld=³photo´datafld=³photo´></td>