Intro to XML Lecture..

Download Report

Transcript Intro to XML Lecture..

Introduction to XML
Part 2
Related Standards


XML documents and DTDs provide
foundation for an Internet document
paradigm – do not provide all necessary
features!
Need for XML standards (some of which
are still under development)
Standard Efforts
Standard
Abbreviation
Specification Status
Purpose
XML Namespaces
Namespaces
Recommendation
Prevent overlap of
names used by
different software
XML Linking
Language
XLink
Working Draft
Flexible document
linking
Extensible Stylesheet
Language
XSL
Working Draft
Flexible document
presentation
XSL Transformations
XSLT
Working Draft
Easy transformation
of XML content from
one data format to
another
XML Schema
N/A
Working Draft
More extensive
document definition
rules than DTDs
XML Namespaces 



XML is based on elements, each is distinguished
by unique element name
Applications process a document they associate
element content with corresponding element
name
Naming collisions are problematic – for example
both Accounting and Fullfillment applications use
term ‘status’ to signify different meanings
Using XML Namespaces developers can qualify
the use of ‘status’ element in reconciliation
document
XML Namespaces - Example
<acct:customer xmlns:acct=“http://www.foocompany.com/names/acct-REV10”>
<acct:name>Bar Corporation</acct:name>
<acct:addressee>Accounts Payable – Bar Corporation</acct:addressee>
<acct:order acct:reference=“5566-1010”>
<acct:status>invoice</acct:status>
</acct:order>
</acct:customer>
<ful:customer xmlns:ful=“http://www.foocompany.com/names/ful-REV10”>
<ful:name>Bar Corporation</ful:name>
<ful:addressee>Loading Dock</ful:addressee>
<ful:order ful:reference=“A98755656”>
<ful:status>shipped</ful:status>
</ful:order>
</ful:customer>


Namespaces attached to
element/attribute with colon :
First time use namespace, associate
namespace prefix with namespace
name use reserved XML attribute
‘xmlns’



xmlns:acct
xmlns:ful
Repetition?
Default Namespace
<customer xmlns=“http://www.foocompany.com/names/acct-REV10”>
<name>Bar Corporation</name>
<addressee>Accounts Payable – Bar Corporation<addressee>
<order reference=“5566-1010”>
<status>invoice</status>
</order>
</customer>
<customer xmlns=“http://www.foocompany.com/names/ful-REV10”>
<name>Bar Corporation</name>
<addressee>Loading Dock</addressee>
<order reference=“A98755656”>
<status>shipped</status>
</order>
</customer>
XML Linking Language - XLink


Similar to HTML linking but XLink
enables people to specify links with
multiple target documents by using
XLink namespaces
Two forms – simple and extended
Simple XLink
<BarCorpLink
xlink:form=“simple”
xlink:inline=“true”
xlink:ref=http://www.foocompany.com/customers/barcorp.xml
xlink:role=“link record”
xlink:title=“Bar Corporation”
xlink:show=“new”
xlink:actuate=“user”
xlink:content-role=“link BarCorp record”
xlink:content-title=“Link to Bar Corporation Customer
Record”>Bar Corporation
</BarCorpLink>
Extended XLink
<BarCorpOrderTrackingLink
xlink:form=“extended”
xlink:inline=“false”
xlink:role=“track order”
xlink:content-role=“track BarCorp”>
<Invoice
xlink:form=“locator”
xlink:href=“BarCorpInvoice.xml”
xlink:title=“Bar Corporation Invoice”
xlink:actuate=“user/>
<Shipment
xlink:form=“locator”
xlink:href=“BarCorpShipment.xml”
xlink:title=“Bar Corporation Shipment”
xlink:actuate=“user/>
</BarCorpOrderTrackingLink>
Extensible Stylesheet Language XSL


Used for formatting document display
Three primary requirements for solution




Define formatting templates that apply to an element and
its subelements



Apply formatting rules to elements
Usable with different display technologies
Document consumer may control application of stylesheets
Select particular elements by using “xsl” namespace
Instructions for formatting use “fo” namespace
Common practice is to use XSL template syntax but
directly insert HTML tags – XSL is used simply as
transformation language (source doc – HTML)
XSL Example
<xsl:template match=“address”
<fo:block>
fo:font-size=“large”
fo:font-weight=“bold”
fo:font-family=“Arial”
fo:line-height=“2”
<xsl:appy-templates/>
</fo:block>
</xsl:template>
<xsl:template match=“address[@ADDTYPE=“ship”]>
<fo:block>
fo:font-size=“small”
fo:font-weight=“normal”
fo:font-family=“Timesl”
fo:line-height=“1”
<xsl:appy-templates/>
</fo:block>
</xsl:template>
XSL Transformations - XSLT



XSLT is used to transform data from
one format to another
Used when two companies want to
exchange same information but apply
own internal DTD
Provides
mechanism
to
support
customised data flow – delivers data to
each application in format it desires
XSLT Example
Ex 1
<order currency=“USD”>
…
</order>
Ex 2
<order>
<currency>USD</currency>
…
</order>
XSLT code
<xsl:template match=“/”>
<xsl:for-each select=“order”
<order>
<currency>
<xsl:value-of select=“@currency”/>
</currency>
</order>
</xsl:for-each>
</xsl:template>
XML Schema


Using XML Schema instead of DTDs to specify
the content of XML documents offers
advantages of using XML syntax and
enforcing datatype restrictions on element
content and attribute values
Additional features to DTD, such as ability to
define recurring blocks of elements or
attributes once and then reuse definition
many times
XML Tools
Applications
Content Management
Tools
Authoring Tools
Web Infrastructure
Development Tools
Fundamental Components
Relationship of Major Tools
Fundamental Components


Determining factor of XML’s success is
availability
of
fundamental
software
components
that
provide
processing
documents and related standards
XML parsers – typically embedded in
applications.
It reads in physical files
associated with a document and converts the
document text into programming constructs
accessible to application logic


Tree Based
Event Based
Tree-based Parser
XML DTD
V
a
l
i
d
Tree-Based
Parser
XML
Document
Document
Tree
Application
Logic
Uses App
Prog
Interface
(API)
•Effective for apps that need random access to doc element
•However, building a complete tree for every doc is expensive in
terms of memory
•Event-based parsers avoid this as they do not create data structure
for entire document
Event-based Parsers
XML DTD
V
a
l
i
d
Event-Based
Parser
Parsing event
Application
Logic
Data Request
XML
Document
•Event-based parsers send parsing events directly to application logic
(beg and end of element but not its attributes)
•If application logic interested in element it requests additional data from
parser
•Effective when application needs only sequential access to certain kinds of
elements
Web Browsers





Internet Explorer
Netscape Navigator
Modzilla Firefox
W3C – Amaya Web browser – derived
for testing XML documents
Download for FREE

http://www.w3c.org/Amaya
XML Editor


Windows Notepad or WordPad
Microsoft XML Notepad
http://msdn.microsoft.com/xml/notepad/intro.asp

XML writer – available from Wattle
Software
http://www.xmlwriter.com/

Macintosh – Emile editor
http://www.in-progress.com/emile/
Special XML characteristics





Less than symbol (<) - &lt;
Greater than symbol (>) - &gt;
Quote symbol (“) - &quot;
Apostrophe symbol (‘) - &apos;
Ampersand symbol (&) - &amp;
Real world XML







WML – Web pages for
mobile devices
XMLNews – news stories
CDF – Web channels
OSD – descriptions of
software
OFX – financial information
(EFT, etc.)
RDF – descriptions of info in
web pages (helps to aid
search engines)
MathML – mathematical
equations








P3P – Web privacy policies
RELML – real estate listings
HRMML – human resource
infomration (resumes, etc.)
VoxML – voice response
scripts (Press 1 for this,
Press 2 for that, etc.)
VML – vector graphics
SVG – vector graphics
SMIL – multimedia
presentations
3DML – three-dimensional
virtual worlds
Application Areas












Information accessibility and sharing
Information distribution capabilities
Document life cycle and content management
Accumulating knowledge from employees (tacit and explicit)
Searching knowledge repositories, such as database systems
and the Internet
Knowledge categorisation systems and limitations of
classifications
Workflow systems and integration barriers
Application integration
System architecture standardisation and compatibility
Customized publishing
File configuration and logging
Electronic commerce