Module#5 XML Prof. Ashish Revar
Module#5 XML Prof. Ashish Revar
XML
Prof. Ashish Revar
<?xml version="1.0"?>
<book>
<title>Developing Web
Application</title>
<author>Ralph Moseley</author>
<price>500</price>
</book>
<bookstore>
<book isbn=>
<title></title>
<author></author>
<price></price>
</book>
<book>
</book>
<bookstore>
Elements : <price>500</price>
Attributes : <book isbn=2960-5>
Entities : <, >, &
PCDATA : parsed character data
10
11
<?xml version="1.0"?>
<!DOCTYPE NEWSPAPER [
<!ELEMENT NEWSPAPER (ARTICLE+)>
<!ELEMENT ARTICLE (HEADLINE,BODY)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
]>
<NEWSPAPER>
13
<?xml version="1.0"?>
<!DOCTYPE NEWSPAPER SYSTEM
news.dtd>
<NEWSPAPER>
14
15
16
17
18
19
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="heading"
type="xs:string"/>
<xs:element name="body"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
20
<?xml version="1.0"?>
<note
xmlns="http://www.domain.com"
xmlns:xsi="http://www.w3.org/2001/XMLSch
ema-instance"
xsi:schemaLocation="http://www.domain.co
m/note.xsd">
<heading>Reminder</heading>
<body>Don't forget me this
weekend!</body>
</note>
21
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
22
23
25
26
27
XSL Transformations
XSLT is used to transform an XML document into
another XML document, or another type of
document that is recognized by a browser, like
HTML and XHTML. Normally XSLT does this by
transforming each XML element into an (X)HTML
element.
Add-remove elements, Rearrange-sort elements,
perform tests, etc
28
29
<?xml version="1.0"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>19</price>
</cd>
</catalog>
30
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Trans
form">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
31
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of
select="title"/></td>
<td><xsl:value-of
select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
32
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"
href="cdcatalog.xsl"?>
<catalog>
33
34
35
/bookstore/book[1]
/bookstore/book[last()]
/bookstore/book[last()-1]
/bookstore/book[position()<3]
/bookstore/book[price>35.00]
36
37
38
39
40
41
42
43
<xsl:template match="cd">
<p>
<xsl:apply-templates
select="title"/>
<xsl:apply-templates
select="artist"/>
</p>
</xsl:template>
44
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
45