Exp 5 and 6 WT
Exp 5 and 6 WT
Objective: Writing program in XML for creation of DTD, which specifies set of rules. Create
a style sheet in CSS/ XSL & display the document in internet explorer .
Theory:
XML Document Type Declaration, commonly known as DTD, is a way to describe precisely the
XML language. DTDs check the validity of structure and vocabulary of an XML document against
the grammatical rules of the appropriate XML language.
An XML document can be defined as:
• Well-formed: If the XML document adheres to all the general XML rules such as tags
must be properly nested, opening and closing tags must be balanced, and empty tags
must end with '/>', then it is called as well-formed.
OR
• Valid: An XML document said to be valid when it is not only well-formed, but it also
conforms to available DTD that specifies which tags it uses, what attributes those tags
can contain, and which tags can occur inside other tags, among other properties.
Types:
DTD can be classified on its declaration basis in the XML document, such as:
• Internal DTD
External DTD
•
When a DTD is declared within the file it is called Internal DTD and if it is declared in a
separate file it is called External DTD.
We will learn more about these in the chapter DTD Syntax
Syntax
Basic syntax of a DTD is as follows:
<!DOCTYPE element DTD identifier
[
declaration1
declaration2
........
]>
Syntax
The syntax of internal DTD is as shown:
where root-element is the name of root element and element-declarations is where you declare the
elements.
Example
Following is a simple example of internal DTD:
External DTD
In external DTD elements are declared outside the XML file. They are accessed by specifying the
system attributes which may be either the legal .dtd file or a valid URL. To reference it as external
DTD, standalone attribute in the XML declaration must be set as no. This means, declaration
includes information from the external source.
Syntax
Following is the syntax for external DTD:
Example
The following example shows external DTD usage:
XSLT
EXtensible Stylesheet Language Transformation commonly known as XSLT is a way to transform the XML document into other formats such as
XHTML.
<xsl:template> defines a way to reuse templates in order to generate the desired output
for nodes of a particular type/context.various template are used with the template like
name, match,mode ,priority.
<xsl:value-of> tag puts the value of the selected node as per XPath expression, as text.
Declaration:
Following is the syntax declaration of <xsl:value-of> element.
<xsl:value-of
select = Expression
disable-output-escaping = "yes" | "no" >
</xsl:value-of>
Declaration
Following is the syntax declaration of <xsl:for-each> element
<xsl:for-each
select = Expression >
</xsl:for-each>
Declaration
Following is the syntax declaration of <xsl:sort> element.
<xsl:sort
select = string-expression
lang = { nmtoken }
data-type = { "text" | "number" | QName }
order = { "ascending" | "descending" } case-
order = { "upper-first" | "lower-first" } >
</xsl:sort>
Declaration
Following is the syntax declaration of <xsl:if> element.
<xsl:if
test = boolean-expression >
</xsl:if>
<xsl:choose> tag specifies a multiple conditional tests against the content of nodes in
conjunction with the <xsl:otherwise> and <xsl:when> elements.
Declaration
Following is the syntax declaration of <xsl:choose> element.
<xsl:choose >
</xsl:choose>
Output:
In Internet Explorer
Title Artist
Empire Burlesque Bob Dylan
Hide your heart Bonnie Tyler
2.XML
Theory:
• Import the packages: Requires that you include the packages containing the JDBC
classes needed for database programming. Most often, using import java.sql.* will suffice.
• Register the JDBC driver: Requires that you initialize a driver so you can open a
communication channel with the database.
• Open a connection: Requires using the DriverManager.getConnection() method to create
a Connection object, which represents a physical connection with the database.
• Execute a query: Requires using an object of type Statement for building and submitting
an SQL statement to the database.
• Extract data from result set: Requires that you use the appropriate ResultSet.getXXX()
method to retrieve the data from the result set.
• Clean up the environment: Requires explicitly closing all database resources versus
relying on the JVM's garbage collection.
STEPS:
//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
//STEP 6: Clean-up environment
rs.close();
stmt.close();
conn.close();
}catch(SQLException
se){ //Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{ if(stmt!=null)
stmt.close();
}catch(SQLException
se2){ }// nothing we can do
try{ if(conn!=null)
conn.close();
}catch(SQLException
se){ se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end FirstExample