Archive

Posts Tagged ‘XSD’

WST Assignment #3


This third assignment has given me a lot of experiences the very first impact is that, we have to use the C#and ISS server(to which I’m unfamiliar). By now you would have understood that I might have used SQL server database as back end(Yes).
The second experience is that power of the Visual Basic editor, it has a lot of support for the developer, makes the things much easier.
People most of the times get scared of XSD(XML Schema Definition) successor of the DTD but it is very easy to write. I would like to share the XSD file I wrote for this assignment. It is very simple and easy to understand.

 

<?xml version=”1.0″ encoding=”Windows-1252″?>
<xs:schema attributeFormDefault=”unqualified” elementFormDefault=”qualified” xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;
<xs:element name=”Profile”>
<xs:complexType>
<xs:sequence>

<xs:element name=”Name”>
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:pattern value=”([a-zA-Z ])+”/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name=”RollNo”>
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:pattern value=”([a-zA-Z0-9])+”/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name=”PhoneNo”>
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:length value=”13″/>
<xs:pattern value=”[+]([0-9])*”>
</xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name=”Email”>
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:pattern value=”\w+([\-\+\.’]\w+)*@\w+([\-.]\w+)*\.\w+([\-.]\w+)*”>
</xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name=”CollegeAddress”>
<xs:complexType>
<xs:sequence>
<xs:element name=”RoomNo” type=”xs:string” />
<xs:element name=”Hostel” type=”xs:string” />
<xs:element name=”College” type=”xs:string” />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”PermanentAddress”>
<xs:complexType>
<xs:sequence>
<xs:element name=”H.No” type=”xs:string” />
<xs:element name=”Town” type=”xs:string” />
<xs:element name=”Dist” type=”xs:string” />
<xs:element name=”State” type=”xs:string” />
<xs:element name=”Pin” >
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:length value=”6″/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”Interests” type=”xs:string” />
<xs:element name=”Hobbies” type=”xs:string” />
<xs:element name=”AboutMe” type=”xs:string” />
<xs:element name=”Image” type=”xs:string” />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

 

 

I’ve used \w+([\-\+\.’]\w+)*@\w+([\-.]\w+)*\.\w+([\-.]\w+)* this for the email pattern. If my email pattern written in .xm. is file is not of this regular expression XSD file shows errors in the validation. For this XML validation I used the validateXML-1.1-bin.jar file. In order to validate the XML file using the validateXML-1.1-bin.jar validator we should use the following tag in the  present XML file
<Profile xsi:noNamespaceSchemaLocation=”profile.xsd” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”&gt;

in the above syntax the profile specifies the root element of the XML file. The profile.xsd specifies the .xsd file we want to apply to that.

the validation command to work with it is:

java -jar validateXML-1.1-bin.jar   -in profile.xml

 

Advertisements

XML+XSLT=(xHTML,HTML,pdf etc.,)


XSL: XML Style-Sheet Language

XML is mainly used to give a raw XML file to give some shape. By including one stylesheet tag to XML file we can give much nicer look.

<?xml-stylesheet type=”text/xsl” href=”profile.xsl”?>

The above tag adds all the styles defined in the profile.xsl to the xml in which is written.

XSLT: XML Style-Sheet Language Transformation

Basically XML is not much human interactive so it is very much needed to transform xml to human interactive file like HTML or XHTML or pdf etc.,

Why XSLT only?

We can use any programming languages like C, C++, Java or Python etc., to transform XML file content to interactive representation in the form of html, xhtml or pdf etc., but the XSLT was written to be light weight and very easy to do the transformation.  It is a w3 standard.

XSLT Engine:

There are two different ways of transformation one is at the client side and the other is at the server side. When we want to do the transformation at the client side browser(Both xml and xsl files have to sent to the client’s browser). In this method the client  must have the XSLT engine installed but we cannot guarantee that. Hence forth we go for much promising method of transforming the file at the server side itself and sending that file to the client browser.

There are many XSLT engines, among them some I’m mentioning below, you can also download them

Saxon

MSXML

AltovaXML

I’ve worked with the Saxon which is an open source XSLT engine. We can download the jar file, after downloading the jar file we have to use the below command to apply style to the xml file.

Java –jar saxon9he.jar –s:profile.xml –xsl:profile.xsl –o:profile.xhtml

In the above command you can replace the source files profile.xml and profile.xsl with your own source xml and xsl files. The output profile.xhtml signifies with which name you want to create the output file

Here is an example transformation:

XML File(profile.xml)

<?xml version=”1.0″?>

<?xml-stylesheet type=”text/xsl” href=”profile.xsl”?>

<Profile>

<Name>Chittampally Vasanth Raja</Name>

<RollNo>10IT05F</RollNo>

<PhoneNo>+91 9999999999</PhoneNo>

<Email>abcdef@gmail.com</Email>

<CollegeAddress> NITK Surathkal</CollegeAddress>

<PermanentAddress>  Andhrapradesh </PermanentAddress>

<Interests>Learning New Technolgy</Interests>

<Hobbies>Blogging</Hobbies>

<AboutMe>hard working, enthusiastic, sociable, cheerful, optimistic and always willing to learn new thing</AboutMe>

<Image>10IT05F.png</Image>

</Profile>

XSL File:(Profile.xsl)

<?xml version=”1.0″?>

<xsl:stylesheet

version=”1.0″

xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

<xsl:output method=”xml”

doctype-system=”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;

doctype-public=”-//W3C//DTD XHTML 1.0 Transitional//EN” indent=”yes”/>

<xsl:template match=”/”>

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<title>Profile Page</title>

<body bgcolor=”#FAFAD2″>

<table align=”center” width=”100%” >

<table border=”1″ align=”center”>

<tr>

<th colspan=”3″ bgcolor=”#9acd32″>Profile </th>

</tr>

<tr>

<td>Name</td>

<td><xsl:value-of select=”Profile/Name”/></td>

<td rowspan=”9″><xsl:text disable-output-escaping=”yes”>&lt;img src=”</xsl:text><xsl:value-of select=”Profile/Image” />” alt=”Vasanth Raja photograph <xsl:text disable-output-escaping=”yes”>” /&gt;</xsl:text>

</td>

</tr>

<tr>

<td>Roll Number</td>

<td><xsl:value-of select=”Profile/RollNo” /></td>

</tr>

<tr>

<td>Phone Number</td>

<td><xsl:value-of select=”Profile/PhoneNo” /></td>

</tr>

<tr>

<td>Email</td>

<td><xsl:value-of select=”Profile/Email” /> </td>

</tr>

<tr>

<td>College Address</td>

<td>

<table>

<tr>

<td><xsl:value-of select=”Profile/CollegeAddress/RoomNo”/></td>

</tr>

<tr>

<td><xsl:value-of select=”Profile/CollegeAddress/Hostel”/> </td>

</tr>

<tr>

<td><xsl:value-of select=”Profile/CollegeAddress/College”/></td>

</tr>

</table>

</td>

</tr>

<tr>

<td>Permanent Address</td>

<td><table>

<tr>

<td>House No:</td>

<td> <xsl:value-of select=”Profile/PermanentAddress/H.No”/></td>

</tr>

<tr>

<td>Town:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/Town” /></td>

</tr>

<tr>

<td>District:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/Dist” /></td>

</tr>

<tr>

<td>State:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/State” /></td>

</tr>

<tr>

<td>Pin Code:</td>

<td><xsl:value-of select=”Profile/PermanentAddress/Pin” /></td>

</tr>

</table>

</td>

</tr>

<tr>

<td>Interests</td>

<td><xsl:value-of select=”Profile/Interests”/></td>

</tr>

<tr>

<td>Hobbies</td>

<td><xsl:value-of select=”Profile/Hobbies”/></td>

</tr>

<tr>

<td>About Me</td>

<td><xsl:value-of select=”Profile/AboutMe”/></td>

</tr>

</table>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

My first video ever I uploaded to Youtube!!


This is the first video which I’ve ever uploaded to Youtube. This video gives brief idea about the various technologies, XML, XHTML,XSL, XSLT, XSD, Schema, DTD, Validation, Stylesheets (CSS)., RSS, DOM which constitute a very complex web sites.