Sie sind auf Seite 1von 9

EXERCISE 3 AIM: 3.

1 Create an XML document and XML schema to store information about books and create the DTD files 3.2 Write an XSLT program to extract book titles, authors, publications, book rating from the books XML document and use formatting. 3.3 Use Microsoft DOM to navigate and extract information from the books XML document. Books.xml <!ELEMENT Catalogue (book)> <!ELEMENT Book (BookNo, Title, Author, Price)> <!ELEMENT BookNo (#PCDATA)> <!ELEMENT Title (#PCDATA)> <!ELEMENT Author (#PCDATA)> <!ELEMENT Price (#PCDATA)> create a DTD for Book <?xml version="1.0"?> <!DOCTYPE book SYSTEM "z:\labxml\ADDRESSBOOK.DTD"> <library> <!as in address book.xml of exercise 1.5 --> </library> BOOK.DTD <!ELEMENT library (book)> <!ELEMENT book (novel,technical,management,fiction,devotional)> <!ELEMENT novel (detective)> <!ELEMENT detective (name,author,price,publication,page,review)> <!ELEMENT name (#PCDATA)> <!ELEMENT author (fa,sa)> <!ELEMENT fa (fname,lname,royalty,qualification,address,specialization)> <!ELEMENT fname (#PCDATA)> <!ELEMENT lname (#PCDATA)> <!ELEMENT royalty (#PCDATA)> <!ELEMENT qualification (#PCDATA)> <!ELEMENT address (#PCDATA)> <!ELEMENT specialization (#PCDATA)>

<!ELEMENT sa (fname,lname,royalty,qualification,address,specialization)> <!ELEMENT fname (#PCDATA)> <!ELEMENT lname (#PCDATA)> <!ELEMENT royalty (#PCDATA)> <!ELEMENT qualification (#PCDATA)> <!ELEMENT address (#PCDATA)> <!ELEMENT specialization (#PCDATA)> <!ELEMENT price (#PCDATA)> <!ELEMENT publication (pname,addr)> <!ELEMENT pname (#PCDATA)> <!ELEMENT addr (#PCDATA)> <!ELEMENT page (#PCDATA)> <!ELEMENT review (date,by,reviewno,comment)> <!ELEMENT date (#PCDATA)> <!ELEMENT by (byperson1,byperson2,byperson3,byperson4)> <!ELEMENT byperson1 (#PCDATA)> <!ELEMENT byperson2 (#PCDATA)> <!ELEMENT byperson3 (#PCDATA)> <!ELEMENT byperson4 (#PCDATA)> <!ELEMENT reviewno (#PCDATA)> <!ELEMENT comment (#PCDATA)> <!ELEMENT romance (name,author,price,publication,page,review)> <!--Same Structure as in detective( )--> <!ELEMENT comic (name,author,price,publication,page,review)> <!--Same Structure as in detective( )--> <!ELEMENT technical (name,author,price,publication,page,review)> <!--Same Structure as in detective( )--> <!ELEMENT technical (name,author,price,publication,page,review)> <!--Same Structure as in detective( )--> <!ELEMENT management (name,author,price,publication,page,review)> <!--Same Structure as in detective( )--> <!ELEMENT fiction (name,author,price,publication,page,review)> <!--Same Structure as in detective( )--> <!ELEMENT devotional (name,author,price,publication,page,review)> <!--Same Structure as in detective( )-->

Create XML Schema for Book.xml <?xml version="1.0"?> <xsd:schema xmlns:xsd="www.xyz.org"> <xsd:element name="library"> <xsd:complexType> <xsd:sequence> <xsd:element name="book"> <xsd:complexType> <xsd:sequence> <xsd:element name="novel"> <xsd:complexType> <xsd:sequence> <xsd:element name="detective"> <xsd:complexType> <xsd:sequence> <xsd:element name="bname" Type="xsd:string"/> <xsd:element name="author"> <xsd:complexType> <xsd:sequence> <xsd:element name="fa"> <xsd:complexType> <xsd:sequence> <xsd:element name="fname" Type="xsd:string"/> <xsd:element name="lname" Type="xsd:string"/> <xsd:element name="royalty" Type="xsd:string"/> <xsd:element name="qualification" Type="xsd:string"/> <xsd:element name="address"> <xsd:complexType> <xsd:sequence> <xsd:element name="add1" Type="xsd:string"/> <xsd:element name="add2" Type="xsd:string"/> <xsd:element name="add3" Type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="specialization" Type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="sa"> <xsd:complexType>

<xsd:sequence> <xsd:element name="fname" Type="xsd:string"/> <xsd:element name="lname" Type="xsd:string"/> <xsd:element name="royalty" Type="xsd:string"/> <xsd:element name="qualification" Type="xsd:string"/> <xsd:element name="address"> <xsd:complexType> <xsd:sequence> <xsd:element name="add1" Type="xsd:string"/> <xsd:element name="add2" Type="xsd:string"/> <xsd:element name="add3" Type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="specialization" Type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="price" Type="xsd:string"/> <xsd:element name="publication"> <xsd:complexType> <xsd:sequence> <xsd:element name="pname" Type="xsd:string"/> <xsd:element name="addr" Type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="page" Type="xsd:string"/> <xsd:element name="review"> <xsd:complexType> <xsd:sequence> <xsd:element name="date" Type="xsd:string"/> <xsd:element name="by"> <xsd:complexType> <xsd:sequence> <xsd:element name="byperson1" Type="xsd:string"/> <xsd:element name="byperson2" Type="xsd:string"/> <xsd:element name="byperson3" Type="xsd:string"/> <xsd:element name="byperson4" Type="xsd:string"/> </xsd:sequence>

</xsd:complexType> </xsd:element> <xsd:element name="reviewno" Type="xsd:string"/> <xsd:element name="comment" Type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name=romance> <!--Same as in detective--> </xsd:element> <xsd:element name=comic> <!--Same as in detective--> </xsd:element> </xsd:element> <xsd:element name=technical> <!--Same as in detective--> </xsd:element> <xsd:element name=management> <!--Same as in detective--> </xsd:element> <xsd:element name=fiction> <!--Same as in detective--> </xsd:element> <xsd:element name=devotional> <!--Same as in detective--> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element>

OUTPUT

CREATE A XSL FOR BOOK DETAILS XML DOCUMENT <?xml version="1.0" ?> <?xml:stylesheet type="text/xsl" href="book.xsl"?> XML Stylesheet Language (book.xsl) <?xsl version ="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h3>my book novels </h3> <table border="1"> <tr bgcolor="#9acd32"> <th> name </th> <th> price </th> <th>publication</th> <th>noofpages</th> </tr> <xsl:for-each select="book">

<xsl:for-each select="novels"> <xsl:for-each select="romance"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="price"/></td> <td><xsl:value-of select="publication"/></td> <td><xsl:value-of select="noofpages"/></td> </tr> </xsl:for-each> </xsl:for-each> </xsl:for-each> </table> <h3>my book technical </h3> <table border="1"> <tr bgcolor="#9acd32"> <th> name </th> <th> price </th> <th>publication</th> <th>noofpages</th> </tr> <xsl:for-each select="book"> <xsl:for-each select="technical"> <xsl:for-each select="romance"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="price"/></td>

<td><xsl:value-of select="publication"/></td> <td><xsl:value-of select="noofpages"/></td> </tr> </xsl:for-each> </xsl:for-each> </xsl:for-each> </table> <h3>my book for management </h3> <table border="1">

<tr bgcolor="#9acd32"> <th> name </th> <th> price </th> <th>publication</th> <th>noofpages</th> </tr> <xsl:for-each select="book"> <xsl:for-each select="management"> <xsl:for-each select="romance"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="price"/></td> <td><xsl:value-of select="publication"/></td> <td><xsl:value-of select="noofpages"/></td> </tr> </xsl:for-each> </xsl:for-each> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

OUTPUT my book novels Name price publication noofpages McKinsey 1024 Sherlock 150 homse

my book technical Name price publication noofpages Indian 1048 C for out-of-the-box Thinkers 981

my book for management name price publication noofpages 350 You can win 250 WinWin Publications

Das könnte Ihnen auch gefallen