Академический Документы
Профессиональный Документы
Культура Документы
1. XML
2. Basic XML Concepts
3. Defining XML Data Formats
XML is not
A replacement for HTML
(but HTML can be generated from XML)
A presentation format
(but XML can be converted into one)
A programming language
(but it can be used with almost any language)
A network transfer protocol
(but XML may be transferred over a network)
A database
(but XML may be stored into a database)
Usage of XML
XML is used in many aspects of web development, often
to simplify data storage and sharing.
XML Separates Data from HTML
If you need to display dynamic data in your HTML document, it will take a lot
of work to edit the HTML each time the data changes. With XML, data can be
stored in separate XML files. This way you can concentrate on using
HTML/CSS for display and layout, and be sure that changes in the underlying
data will not require any changes to the HTML.
With a few lines of JavaScript code, you can read an external XML file and
update the data content of your web page.
Usage of XML
XML Simplifies Data Transport
One of the most time-consuming challenges for developers is to exchange data
between incompatible systems over the Internet. Exchanging data as XML
greatly reduces this complexity, since the data can be read by different
incompatible applications.
XML by Example
<article>
<author>Gerhard Weikum</author>
<title>The Web in 10 Years</title>
</article>
XML by Example
this is XML, too:
<t108>
<x87>Gerhard Weikum</x87>
<g10>The Web in 10 Years</g10>
</t108>
XML by Example
and what about this XML document:
<data>
ch37fhgks73j5mv9d63h5mgfkds8d984lgnsmcns983
</data>
Clients
XML2HTML
XML2WML
XML2PDF
Converters
Database with
XML documents
Buyer
XML
Adapter
Legacy
System
(e.g., SAP
R/2)
XML
(BMECat, ebXML, RosettaNet, BizTalk, )
Order
XML
Adapter
Legacy
System
(e.g.,
Cobol)
XML
Basic XML Concepts
XML Standards by the W3C
XML Documents
Namespaces
XML Documents
Whats in an XML document?
XML defines certain rules for its syntax that specify how
to create or structure an XML document.
The syntax used to create an XML document is called
Markup syntax
Declaration
Elements
Attributes
Tree
comments
XML Documents
<?xml version=1.0 encoding=UTF-8
standalone=yes?>
<books>
<book>
<subject standard="class V">History</subject>
<author>D.P.Mishra</author>
<publisher>FGB</publisher>
<price>Rs200/-</price>
</book>
XML Documents
For creating XML document following points should
always in mind
1. XML doc must have starting and ending tags
2. XML tags are case sensitive
3. XML elements must be properly nested
4. XML doc must have one root element.
5. XML attributes values must be enclosed in double
quotes.
End Tag
Element
Content of
the Element
(Subelements
and/or Text)
Attributes with
name and value
XML Element
1. Name can start with letters or the underscore(_)
2. After the first character number, characters,- (hyphen), . (period) can be use in
element.
3. Name cannot contain space.
4. Element cannot contain the :
5. There cannot be a space after the opening character(<).
Nested Element:- the elements which contain other elements are known as nested
element.
Empty Element:- written without an end tag.
<items> <item item-id =1 /> </items>
author
title
text
number=1
Gerhard
Weikum
abstract
title=
In order
The Web
in 10 years
section
The
index
Web
provides
DTD
<?xml version=1.0
encoding=UTF-8
standalone=yes?>
<!DOCTYPE student[
<!ELEMENT student_info (ad)* >
<!ELEMENT ad (rollno, name, college, brch, year,
emid)>
<!ELEMENT rollno (#PCDATA)>
<student_info>
<!ELEMENT name (#PCDATA)>
<ad>
<!ELEMENT college (#PCDATA)>
<rollno>Rollno : 3012010302</rollno>
<!ELEMENT brch (#PCDATA)>
<name>Name : Kabir</name>
<!ELEMENT year (#PCDATA)>
<college>College : OPJIT</college>
<brch>Branch : CSE</brch>
<!ELEMENT emid (#PCDATA)>
<year>Year : 2008</year>
]>
<emid>Email ID : kabir@hotmail.com</emid>
</ad> </student _info>
Namespaces
<library>
<description>Library of the CS Department</description>
<book bid=HandMS2000>
<title>Principles of Data Mining</title>
<description>
Short introduction to <em>data mining</em>, useful
for the IRDM course
</description>
</book>
</library>
Namespaces
Namespaces
Name space
<section>
<sectionInfo>
<secID>S001</secID>
<name>Sales</name>
</sectionInfo>
<sectionInfo>
<secID>S002</secID>
<name>Development</nam
e>
</sectionInfo>
</section>
Section XML
Document
<employeeList> <personList>
<empID>E0000001</empID>
<name>Sales</name>
<name>John Smith</name>
</personList>
<personList>
<empID>E0000002</empID>
<name>Development</nam>
<name>Ichiro
Tanaka</name>
</personList>
</employeeList>
employeeListXML Document
<employee> <personInfo>
<empID>E0000001</empID>
<secID>S001</secID>
<name>John Smith</name>
</personInfo> <personInfo>
<empID>E0000002</empID>
<secID>S002</secID>
<name>Ichiro Tanaka</name>
</personInfo>
</employee>
Name space
Name space
<emp:employee xmlns:emp="urn:corp:emp">
<emp:personInfo>
.
</emp:personInfo>
</emp:employee>
In this example, we have declared the namespace prefix as "emp", and the
namespace identifier (URI) as "urn:corp:emp". This means that element names
and attribute names with the "emp" prefix (including the employee element) all
belong to the urn:corp:emp namespace
Namespace Syntax
<dbs:book xmlns:dbs=http://www-dbs/dbs>
Prefix as abbrevation
of URI
<sec:section
xmlns:sec="urn:corp:sec">
<sec:sectionInfo>
<sec:secID>S001</sec:secID>
<sec:name>Sales</sec:name>
</sec:sectionInfo>
<sec:sectionInfo>
<sec:secID>S002</sec:secID>
<sec:name>Development</sec:n
ame> </sec:sectionInfo>
</sec:section>
Section XML
Document
<emp:employee
xmlns:emp="urn:corp:emp">
<emp:personInfo>
<emp:empID>E0000001</emp
:empID>
<emp:secID>S001</emp:secI
D> <emp:name>John
Smith</emp:name>
</emp:personInfo>
<emp:personInfo>
<emp:empID>E0000002</emp
:empID>
<emp:secID>S002</emp:secI
D> <emp:name>Ichiro
Tanaka</emp:name>
</emp:personInfo>
</emp:employee>
Employee XML Document
<list:employeeList xmlns:list="urn:corp:list"
xmlns:emp="urn:corp:emp"
xmlns:sec="urn:corp:sec"> <list:personList>
<emp:empID>E0000001</emp:empID>
<sec:name>Sales</sec:name> <emp:name>John
Smith</emp:name> </list:personList>
<list:personList>
<emp:empID>E0000002</emp:empID>
<sec:name>Development</sec:name>
<emp:name>Ichiro Tanaka</emp:name>
</list:personList> </list:employeeList>>
employeeListXML Document
Default Namespace
example
article
(title,author+,text)>
title
(#PCDATA)>
author
(#PCDATA)>
text
(abstract,section*,literature?)>
abstract
(#PCDATA)>
section
(#PCDATA|index)+>
literature (#PCDATA)>
index
(#PCDATA)>
Content of the text element may
the title element contain zero or more section
Content of
is parsed character data
c
exactly one such element
c+ one or more
c* zero or more
c? zero or one
attribute name
attribute type
attribute default
string data
(A1||An)
enumeration of all possible values of the
attribute (each is XML name)
ID
unique XML name to identify the element
IDREF refers to ID attribute of some other element
(intra-document link)
IDREFS
list of IDREF, separated by white space
plus some more
CDATA
Attribute Examples
<ATTLIST publication type (journal|inproceedings) #REQUIRED
pubid ID #REQUIRED>
<ATTLIST cite
cid
IDREF #REQUIRED>
<ATTLIST citation
ref
IDREF #IMPLIED
cid
ID #REQUIRED>
<publications>
<publication type=journal pubid=Weikum01>
<author>Gerhard Weikum</author>
<text>In the Web of 2010, XML <cite cid=12/>...</text>
<citation cid=12 ref=XML98/>
<citation cid=15>...</citation>
</publication>
<publication type=inproceedings pubid=XML98>
<text>XML, the extended Markup Language, ...</text>
</publication>
</publications>
Attribute Examples
<ATTLIST publication type (journal|inproceedings) #REQUIRED
pubid ID #REQUIRED>
<ATTLIST cite
cid
IDREF #REQUIRED>
<ATTLIST citation
ref
IDREF #IMPLIED
cid
ID #REQUIRED>
<publications>
<publication type=journal pubid=Weikum01>
<author>Gerhard Weikum</author>
<text>In the Web of 2010, XML <cite cid=12/>...</text>
<citation cid=12 ref=XML98/>
<citation cid=15>...</citation>
</publication>
<publication type=inproceedings pubid=XML98>
<text>XML, the extended Markup Language, ...</text>
</publication>
</publications>
keywords
Root element
Internal DTD:
<?xml version=1.0?>
<!DOCTYPE article [
<!ELEMENT article (title,author+,text)>
...
<!ELEMENT index (#PCDATA)>
]>
<article>
...
</article>
Flaws of DTDs
XML Schemas
54
55
56
DTD
Define elements ,
attributes and entities
Does not support Name
spaces
Does not follow the
XML syntax
Lacks strong typing
capabilities
Schema
Define the structure of
an element with more
feature such as data
type and conditions.
Provide support Name
spaces
Follow the XML
syntax
Support simple and
complex data types
Simple Type
Date
Integer
String
Customer built types
In DTD we used #PCDATA to capture a name, a date or
practically anything.
Complex Type
<xsd:simpleType name=zipcodeType>
<xsd:restriction base=xsd:string>
<xsd:pattern value=\d{5}(-\d{4}? />
</xsd:restriction>
<xsd:simpleType>
This type limits the content of elements (zipcodeType)
to a string with 5 digits, an optional hyphen and 4 extra
digits.
<xsd:complexType name=endType>
<xsd:sequence>
<xsd:element name=animal
type=animalType minOccurs=1
maxOccurs=unbounded/>
</xsd:sequence>
<xsd:complexType>
Defines endType. It contains another element
animal defined with another complex type
animalType to define a particular element
Code.xsd
<xsd:element name=gestation
type=xsd:timeDuration/>
(represent a certain amount of time)
Code.xml
<gestation>P3M15D</gestation>
(PnYnMnDTnHnMnS)
n - non negative
Period
Code.xsd
xsd:element name=bedtime type=xsd.time:/>
Code.xml
<bedtime>20:15:05-05:00>/bedtime>
Additional xsd:time
xsd:time (hh:mm:ss.sss)
xsd:timeInstant (CCYY-MM-DDTh:mm:ss.sss)
xsd:date CCYY-MM-DD
xsd:month (CCYY-MM
xsd:year (CCYY)
xsd:century (CC)
xsd:recurringDate
xsd:recurringDay
Number Type
xsd:decimal
xsd:integer
xsd:positiveinteger
xsd:negativeinteger
xsd:float
xsd:double
<items>
<item>
<title>Wheel</title>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Cam</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</items>
</shipOrder>
<xsd:complexTypename="cdItems">
<xsd:elementname="item"minOccurs="0"
maxOccurs="unbounded"type="cdItem"/>
</xsd:complexType>
<xsd:complexTypename="cdItem">
<xsd:elementname="title"type="xsd:string"/>
<xsd:elementname="quantity
type="xsd:positiveInteger"/>
<xsd:elementname="price"type="xsd:decimal"/>
</xsd:complexType>
</xsd:schema>
XPath
XPath is the solution to finding information in an XML
document. XPath uses expressions to find elements, attributes,
and other information in XML file . For example If an XML
document that contained a bunch of favorite books, each with
author children elements, by XPath expression we ncan find all
the authors of your favorite books!
XPath is a syntax for defining parts of an
XML document
XPath uses path expressions to navigate in
XML documents
XPath contains a library of standard functions
XPath is a major element in XSLT
XPath is also used in XQuery, XPointer and
XLink
XPath is a W3C recommendation
XPath expressions
Abc.xml
<inventory>
<drink>
<lemonade supplier="mother" id="1">
<price>$2.50</price>
<amount>20</amount>
</lemonade>
<pop supplier="store" id="2">
<price>$1.50</price>
<amount>10</amount>
</pop>
</drink>
<snack>
<chips supplier="store" id="3">
<price>$4.50</price>
<amount>60</amount>
<calories>180</calories>
</chips>
</snack>
</inventory>
Elements of XPath
An XPath expression usually is a location path that
consists of location steps, separated by /:
/article/text/abstract:
XSLT
XSLT Element
xsl:apply-templates
Example:
output
Explanation
<html>
<body>
<p><b>Jack</b></p>
<p><b>Harry</b></p>
<p><b>Rebecca</b></p>
<p><u>Mr. Bean</u></p>
</body>
</html>
XLink
XLink Scope
Element Conformance
Application Conformance
Element Conformance
Application Conformance
Links:
simple
extended
Link - simple
Defines an outbound link from a local resource to a remote
resource.
Similar to HTML references
<a href=uri> </a> or <img href=uri>
Attributes
<mytag
xlink:type=simple
xlink:role=role_uri
xlink:href=ref_uri
xlink:show=new
xlink:actuate=onLoad>
</mytag>
</doc>
Role definition
Linked resource
Instruction to open the link in a new
window when the link is traversed
Link - extended
resource
locator
arc
arc
Attributes
from specifies the label of starting resources for a transversal
to specifies the label of ending resources for a transversal
show describes how the href resource is to be presented on
transversal
actuate describes when the transversal to href resource is to
happen
arcrole URI of a resource that describes the role of the arc
title a human readable description of the element
title
Behavior attribute
Semantic attribute
extended - Link
Example
XML Document
<doc xmlns:xlink=/xlink>
<order xlink:type=extended >
<car xlink:type=resource xlink:label=c1>Porsche </car>
<car xlink:type=resource xlink:label=c1>Ferrari </car>
<account xlink:type=locator xlink:label=a1
xlink:href=http://www.chargeme.com/cgi/citibank-12-3123
xlink:title=Brian Temple/>
<location xlink:type=resource xlink:label=d1>
<attn>Matthias Hauswirth</attn>
<street></street> <zip>80303</zip>
</ location >
<charge_to xlink:type=arc xlink:from=c1 xlink:to=a1
xlink:title=Brian pays/>
<deliver_to xlink:type=arc xlink:from=c1 xlink:to=d1/>
</order>
</doc>
Bank
Account
XPointer
So, instead of linking to the entire document (as with XLink), XPointer
allows you to link to specific parts of the document.
To link to a specific part of a page, add a number sign (#) and an
XPointer expression after the URL in the xlink:href attribute,
like this:
xlink:href="http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler'))"
The expression refers to the element in the target document, with the id
value of "Rottweiler
XPointer also allows a shorthand method for linking to an element
with an id. You can use the value of the id directly, like this:
xlink:href="http://dog.com/dogbreeds.xml#Rottweiler".
XML Parser
AJAX
1. XML
2. Working of AJAX
AJAX
The term AJAX (Asynchronous JavaScript and XML) has been
around for three years created by Jesse James Garrett in 2005.
The technologies that make Ajax work, however, have been
around for almost a decade. Ajax makes it possible to update a
page without a refresh. Using Ajax, we can refresh a particular
DOM object without refreshing the full page.
In Jesse Garretts original article that coined the term, it was
AJAX. The X in AJAX really stands for XML Http Request
though, and not XML. Jesse later conceded that Ajax should be a
word and not an acronym and updated his article to reflect his
change in heart. So Ajax is the correct casing. As its name
implies, Ajax relies primarily on two technologies to work:
JavaScript and the XMLHttpRequest. Standardization of the
browser DOM (Document Object Model) and DHTML also play
3.