0% found this document useful (0 votes)
16 views

XML

The document provides a comprehensive guide on XML and web services, covering topics such as XML file creation, DTD implementation, XML schema, CSS integration, and XSL transformation. It includes step-by-step instructions for creating XML documents, defining elements and attributes, and applying stylesheets. Additionally, it demonstrates practical examples like an address book and a bookstore catalog.

Uploaded by

matebearagaw6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

XML

The document provides a comprehensive guide on XML and web services, covering topics such as XML file creation, DTD implementation, XML schema, CSS integration, and XSL transformation. It includes step-by-step instructions for creating XML documents, defining elements and attributes, and applying stylesheets. Additionally, it demonstrates practical examples like an address book and a bookstore catalog.

Uploaded by

matebearagaw6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

XML & WEB SERVICES

▪ Simple Xml File Creation-Elements


▪ Simple Xml File Creation-Attributes
▪ Internal Dtd Implementation
▪ External Dtd Implementation
▪ Xml Schema
▪ Cascading Style Sheet
▪ Xsl –Transformation
▪ Xsl Formatting
▪ Xpath Implementation
▪ Xml Document Class
▪ Xml Parser Error Class
▪ Xml Binding In Dataset 5
▪ Web Services
1) SIMPLE XML FILE FOR ADDRESS BOOK

Objective: -creating a simple XML document


Step 1: open VSCode.
Step 2: define root element as addbook
Step 3: Define Element as details.
Step 4: define sub element like name,DOB,city,state,pincode, work.
Step 5: define attribute for the work as title and company.
Step 6: close all the tag of subsequent element
Step 7. save the file with .xml extension.
Step 7: Open Browser and open the XML file.

<?xml version="1.0"?>
<addbook>
<details>
<name>John Smith</name>
<DOB>2-january-1978</DOB>
<city>Chennai</city>
<state>Tamilnadu</state>
<pincode>600089</pincode>
<work title="Project Manager" company="TCS" city="Chennai"></work>
<phoneno>984002561</phoneno>
<email>[email protected]</email>
</details>
<details>
<name>Annie</name>
<DOB>30-March-1982</DOB>
<city>Ville Parle</city>
<state>Mumbai</state>
<pincode>876001</pincode>
<work title="HR" company="Wipro" city="Mumbai"></work>
<phoneno>9600560190</phoneno>
<email>[email protected]</email>
</details>
</addbook>

SIMPLE XML DOCUMENT-ATTRIBUTES


<ADDRESSBOOK>
<PERSON1
Name="N Krishnamoorthy"
Age="45"
Dob="06-02-1976"
Mobile="944339443"
Mail="[email protected]"
Streetname="Thiruneermalai Road"
Houseno="303"
Area="Thirumudivakkam"
Pincode="600044"
City="Chennai"
State="Tamilnadu"
/>
<PERSON2
Name="Balavinayagam"
Age="27"
Dob="09-06-1990"
Mobile="9600365435"
Mail="[email protected]"
Streetname="North Car Street"
Houseno="77/99a"
Area="Rockfort"
Pincode="600002"
City="tiruchirappalli"
State="Tamilnadu"
/>
<PERSON3
Name="Sushmitha"
Age="47"
Dob="09-02-1970"
Mobile="9789548789"
Mail="[email protected]"
Streetname="Haneefa Colony"
Houseno="548"
Area="Vaniyambadi"
Pincode="625689"
City="Vaniyambadi"
State="Tamilnadu"
/>
</ADDRESSBOOK>

INTERNAL DTD IMPLEMENTATION


Objective: Create an XML file using the Internal DTD:
Step 1: Open <!DOCTYPE declare root element as ‘bookstore’.
Step 2: Declare elements name, topic into bookstore.
Step 3: Declare elements name, ISBN attribute of book into topic.
Step 4: Elements name, title, author as PCDATA.
Step 5: Root element consist of Mike’s store as name value, topic consist of xml as name value,
ISBN is 120-90-100 attribute of book, title include some contents, Mike Jervis as author value
<?xml version="1.0"?>
<!DOCTYPE bookstore [
<!ELEMENT bookstore (name,topic+)>
<!ELEMENT topic (name,book*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT book (title,author)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ATTLIST book ISBN CDATA "0">
]>
<bookstore>
<name>Mike's Store</name>
<topic>
<name>XML</name>
<book ISBN="120-90-100">
<title>Mike's Guide To DTD's and XML Schemas</title>
<author>Mike Jervis</author>
</book>
</topic>
</bookstore>

EXTERNAL DTD IMPLEMENTATION


Goal: Create an external DTD and implement it in XML file.
Algorithm:
Step 1: Open VSCode.
Step 2: Create a DTD file for element and sub elements.
Step 3: Save the file as. DTD extension.
Step 4: Create a new XML file
Step 5: Implement the DTD file with syntax
[!DOCTYPE SYSTEM “filename”]
Step 6: save the file with .xml extension.
Step 7: Run the XML file in Browser.
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE Combomeal SYSTEM <!ELEMENT Combomeal (burger,fries,drink)>
"DTD1.dtd"> <!ENTITY COLA "Pepsi" >
<Combomeal> <!ELEMENT burger(name,bun)>
<burger> <!ELEMENT name (#PCDATA)>
<name>TASTY BURGER</name> <!ELEMENT bun (meat,cheese,chick)>
<bun bread="white"> <!ATTLIST bun bread (white|wheat)
<meat/> #REQUIRED>
<cheese/> <!ELEMENT meat EMPTY>
<chick/> <!ELEMENT cheese EMPTY>
</bun> <!ELEMENT chick EMPTY>
</burger> <!ELEMENT fries EMPTY>
<fries size="large"/> <!ATTLIST fries size (small|medium|large)
<drink size="large"></drink> #REQUIRED>
</Combomeal> <!ELEMENT drink (#PCDATA)>
<!ATTLIST drink size (small|medium|large)
#REQUIRED>

XML SCHEMA
Objective: Creating a XML Schema
Step 1: open VSCode for creating .dtd file for xml schema definition
Step 2: define the data types of elements which is to be defined in xml file.
Step 3: close the root element of .dtd file and save it.
Step 4: Open another VSCode for xml file
Step 5: define respected element as defined in the .dtd file and define the value.
Step 6. close all the subsequent elements tag.
Step 7: save the file with .xml extension
Step 8: Open Browser and open the XML file.
<?xml version="1.0"?> <?xml version="1.0"?>
<note xmlns="http://www.w3cschools.com" <xs:schema>
xmlns:xsi="http://www.w3.org/2001/XMLNS <xmlns:xs="http://www.w3.org/2001/XML
schema_instance" NS schema"
xsi:xmlSchemaLocation="http:/w3cschoools.c target
om note.xsd"> namespace="http://www.w3schools.com
<to>Tove</to> element form default="qualified">
<from>Jani</from> <xs:element name="to"type="xs:string"/>
<heading>Reminder</heading> <xs:element
<body>don't forgot me</body> name="heading"type=xs:string"/>
</note> <xs:element
name="body"type="xs:string"/>
</xs:sequence>
</xs:complex type>
</xs:element>
</xs:schema>

CASCADING STYLE SHEET

Objective: create an xml file to implement css concept.


Step 1: open VSCode.
Step 2: write css code for the elements and sub elements and save it with .css extension.
Step 3: Create a new XML file and implement the css file in XML file. Save it with .css
extension.
Step 4: Open Browser and open the XML file.
<?xml version="1.0"?> bookstore
<?xml-stylesheet type="text/css" href="books.css"?> {
<bookstore> border-style:double;
<book> Book Detail </book> background-color:green;
<title> Title: ANSI C </title> font-family:algerian;
<author> Author : Balagurusamy </author> display:block;
<rs> Price : 250 </rs> }
</bookstore> book
{
height:50px;
font-size:150%;
foreground-color:red;
margin-left:300px;
text-decoration:underline;
}
title
{
height:50px;
font-size:150%;
margin-left:300px;
}
author
{
height:50px;
font-size:250%;
margin-left:300px;
text-decoration:underline;
}
price
{
height:50px;
font-size:150%;
margin-left:300px;
}

XSL TRANSFORMATION
To create a simple XSLT transformation from XSL to XML.
Step-1: Create a XSLT document using VSCode.
Step-2: Using XSLT document, we can create a style sheet like Font Style, Font Size,
bgcolor,..etc. and write the following code: :“cdcatalog.xsl”
Step-3: Save the document as“ Filename.xsl”.
Step-4: Then create a XML document.
Step-5: Create a Link with the XSLT document using href tag=”Filename.xsl” and write the
following code: “Simpxsl.xml”
Step-6: Save the document as “Simpxsl.xml”.
Step-7: Then execute the xml file and view the output:

<?xml version="1.0" encoding="UTF- <?xml version="1.0" encoding="UTF-8" ?>


8" ?> <xsl:stylesheet version="1.0"
<?xml-stylesheet type="text/xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
href="cdcatalog.xsl"?> <xsl:template match="/">
<catalog> <html>
<cd> <body>
<title>Empire Burlesque</title> <h2>My CD Collection</h2>
<artist>Bob Dylan</artist> <table border="1">
<country>USA</country> <trbgcolor="#9acd32">
<company>Columbia</company> <th style="text-align:left">Title</th>
<price>10.90</price> <th style="text-align:left">Artist</th>
<year>1985</year> </tr>
</cd> <xsl:for-each select="catalog/cd">
<cd> <tr>
<title>Hide your heart</title> <td><xsl:value-of select="title"/></td>
<artist>Bonnie Tyler</artist> <td><xsl:value-of select="artist"/></td>
<country>UK</country> </tr>
<company>CBS Records</company> </xsl:for-each>
<price>9.90</price> </table>
<year>1988</year> </body>
</cd> </html>
<cd> </xsl:template>
<title>Greatest Hits</title> </xsl:stylesheet>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin
records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a
woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy
Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>JornHoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midtomnatten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>

XSL TRANSFORMATION-BOOK SHOP


Objective: To create a simple XSLT transformation from XSL to XML.
Step-1: Create a XSLT document using VSCode.
Step-2: Using XSLT document, we can create a style sheet like Font Style, Font Size, bgcolor,..etc. and
write the following code:
Step-3: Save the document as :“style.xsl”.
Step-4: Then create a XML document.
Step-5: Create a Link with the XSLT document using href tag=”style.xsl” and write the following code:
Step-6: Save the document as “Book.xml”.
Step-7: Then execute the xml file and view the output:

<?xml version="1.0"?> //XSLT DOCUMENT


<?xml-stylesheet type="text/xsl" <?xml version="1.0" encoding="UTF-8"?>
href="style.xsl"?> <xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transfo
<BooksforYou> rm"
<Book BookID = "1000"> version="1.0" >
<Title>If Tomorrow Comes</Title> <xsl:template match="/">
<Rate>275</Rate> <html>
<Author>Krishna Kumar</Author> <body background="tech.gif">
<Publication>Pearson</Publication> <h1 align="center">
<ISBN>111-222-333</ISBN> <font color="blue">Books at your own Cyber Shoppe</font>
</Book> </h1>
<Book BookID ="1001"> <table border="4" cellpadding="10" cellspacing="5"
<Title>.NET Expert Guide</Title> align="center"
<Rate>475</Rate> bgcolor="lightgreen" bordercolor="green">
<Author>James</Author> <tbody>
<Publication>Microsoft <tr>
Press</Publication> <th>Book ID</th>
<ISBN>121-222-333</ISBN> <th>Title</th>
</Book> <th>Rate</th>
<Book BookID ="1002"> <th>Author</th>
<Title>C Projects</Title> <th>Publication</th>
<Rate>275</Rate> <th>ISBN</th>
<Author>YashwantP.Kanetkar</Autho </tr>
r> <xsl:for-each select="BooksforYou/Book">
<Publication>BPB <tr>
Publications</Publication> <td><xsl:value-of select="@BookID"/></td>
<ISBN>111-232-333</ISBN> <td><xsl:value-of select="Title"/></td>
</Book> <td><xsl:value-of select="Rate"/></td>
<Book BookID ="1003"> <td><xsl:value-of select="Author"/></td>
<Title>Let us C</Title> <td><xsl:value-of select="Publication"/></td>
<Rate>225</Rate> <td><xsl:value-of select="ISBN"/></td>
<Author>YashwantP.Kanetkar</Autho </tr>
r> </xsl:for-each>
<Publication>BPB </tbody>
Publications</Publication> </table>
<ISBN>111-222-353</ISBN> </body>
</Book> </html>
<Book BookID ="1004"> </xsl:template>
<Title>Com and Beyond in </xsl:stylesheet>
VC++</Title>
<Rate>375</Rate>
<Author>YashvantP.Kanetkar</Author
>
<Publication>BPB
Publications</Publication>
<ISBN>111-555-333</ISBN>
</Book>
</BooksforYou>

You might also like