WebTechnology- puducherry university Unit 3
WebTechnology- puducherry university Unit 3
UNIT-III
Web Technologies: Anatomy of xml document - xml markup-working
with elements and attributes - creating valid documents-xml objects.
ActiveX controls: Introduction-Building a basic control - OLE and
ActiveX- HTML and ActiveX-ActiveX Documents.
WEB TECHNOLOGIES
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The Difference between XML and HTML
XML is not a replacement for HTML. XML and HTML were designed with
different goals:
XML Syntax
• An XML document consists of
– Markup
• Tags, which begin with < and end with >
• References, which begin with & and end with ;
– Character, e.g.  
– Entity, e.g. <
» The entities lt, gt, amp, apos, and quot are
recognized in every XML document.
» Other XHTML entities, such as nbsp, are only
recognized in other XML documents if they
are defined in the DTD
– Character data: everything not markup
• Comments
– Begin with <!--
– End -->
• CDATA section
– Special element the entire content of which is interpreted as
character data, even if it appears to be markup
– Begins with <![CDATA[
– Ends with ]]> (illegal except when ending CDATA)
• < and & must be represented by references except
– When beginning markup
– Within comments
– Within CDATA sections
Characteristics of XML.
XML Characteristics:
1. XML Does Not DO Anything
2. With XML You Invent Your Own Tags
3. XML is Not a Replacement for HTML
4. XML is a complement to HTML.
5. XML is a software- and hardware-independent tool for carrying information.
6. XML is a W3C Recommendation
7. XML is Everywhere
8. XML is used in many aspects of web development, often to simplify data
storage and sharing
9. XML Separates Data from HTML
10. XML Simplifies Data Sharing
11. XML Simplifies Data Transport
12. XML Simplifies Platform Changes
13. XML Makes Your Data More Available
14. XML is Used to Create New Internet Languages
15. XML documents form a tree structure that starts at "the root" and
branches to "the leaves".
An Example XML Document
XML documents use a self-describing and simple syntax:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The first line is the XML declaration. It defines the XML version (1.0)
and the encoding used (ISO-8859-1 = Latin-1/West European character
set).
The next line describes the root element of the document (like
saying: "this document is a note"):<note>
The next 4 lines describe 4 child elements of the root (to, from,
heading, and body):
XML Namespaces
XML Namespaces provide a method to avoid element name conflicts.
Name Conflicts
In XML, element names are defined by the developer. This often results in a
conflict when trying to mix XML documents from different XML applications.
This XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
If these XML fragments were added together, there would be a name conflict.
Both contain a <table> element, but the elements have different content and
meaning.
An XML parser will not know how to handle these differences.
Solving the Name Conflict Using a Prefix
Name conflicts in XML can easily be avoided using a name prefix.
This XML carries information about an HTML table, and a piece of furniture:
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:table xmlns:f="http://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
In the example above, the xmlns attribute in the <table> tag give the h: and
f: prefixes a qualified namespace.
When a namespace is defined for an element, all child elements with the
same prefix are associated with the same namespace.
Namespaces can be declared in the elements where they are used or in the
XML root element:
<root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture">
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
Namespace
Example use of namespace prefix: declaration
The syntax rules of XML are very simple and very strict. The rules are
very easy to learn, and very easy to use.
Because of this, creating software that can read and manipulate XML is
very easy to do.
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The first line in the document - the XML declaration - defines the XML
version and the character encoding used in the document. In this case
the document conforms to the 1.0 specification of XML and uses the
ISO-8859-1 (Latin-1/West European) character set.
The next line describes the root element of the document (like it was
saying: "this document is a note"):
<note>
The next 4 lines describe 4 child elements of the root (to, from, heading, and
body):
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
And finally the last line defines the end of the root element:
</note>
<p>This is a paragraph
<p>This is another paragraph
<p>This is a paragraph</p>
<p>This is another paragraph</p>
Opening and closing tags must therefore be written with the same
case:
<Message>This is incorrect</message>
<message>This is correct</message>
All XML documents must contain a single tag pair to define a root
element.
All other elements must be within this root element.
All elements can have sub elements (child elements). Sub elements
must be correctly nested within their parent element:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Comments in XML
There is nothing special about XML. It is just plain text with the
addition of some XML tags enclosed in angle brackets.
XML elements can have attributes in the start tag, just like HTML.
<img src="computer.gif">
<a href="demo.asp">
Attributes often provide information that is not a part of the data. In the
example below, the file type is irrelevant to the data, but important to the
software that wants to manipulate the element:
<file type="gif">computer.gif</file>
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
There are no rules about when to use attributes, and when to use child
elements. My experience is that attributes are handy in HTML, but in XML you
should try to avoid them. Use child elements if the information feels like data.
XML DTD
Attribute.
CDATA
PCDATA
Elements:
The basic entity is element. The elements are used for defining the
tags .The elements typically consists of opening and closing tags.
Mostly only one element is used to define a single tag.
<!ELEMENT student(name,address,std,marks)>
Attribute:
The attributes are generally used to specify the values of the element.
These are specified within the double quotes.
<flag type=”true”>
CDATA:
CDATA stands for character data. This character data will be parsed by
the parser.
The term CDATA is used about text data that should not be parsed by
the XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" will generate an error because the parser interprets it as the start
of a new element.
"&" will generate an error because the parser interprets it as the start
of an character entity.
Some text, like JavaScript code, contains a lot of "<" or "&" characters.
To avoid errors script code can be defined as CDATA.
Everything inside a CDATA section is ignored by the parser.
A CDATA section starts with "<![CDATA[" and ends with "]]>":
<script>
<![CDATA[
function matchwo(a,b)
Types of DTD:
1. internal DTD
2. External DTD
Internal DTD:
Internal DTD file is within the DTD elements in XML file:
<?xml version=”1.0” encoding=”UTF=8”?>
<!DOCTYPE student[
<!ElEMENT student(name,address,place)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT address(#PCDATA)>
<!ELEMENT place(#PCDATA)>
]>
<student>
<name>ARUN</name>
External DTD:
External DTD file is created and its name must be specified in the
corresponding XML file.
DTD File: (student.dtd)
<!ElEMENT student(name,address,place)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT address(#PCDATA)>
<!ELEMENT place(#PCDATA)>
XML File:( externaldtd.xml)
<?xml version=”1.0” encoding=”UTF=8”?>
<!DOCTYPE student SYSTEM “student.dtd”>
<student>
<name>ARUN</name>
<address>KK NAGAR</address>
<place>Villupuram</place>
</student>
Merits of DTD:
It is used to define the structural components of XML documents.
These are relatively simple and compact.
DTD can be defined inline and external in the XML documents.
Demerits of DTD:
DTD are very basic and hence cannot be much specified for complex
documents.
DTD are not aware of namespace concept.
The DTD cannot define the type of data contained within the XML
documents. Hence using DTD we cannot specify whether the element
is numeric or string data types.
Some XML processor which do not understand DTD elements.
ACTIVEX CONTROLS
3.5 INTRODUCTION
In the static content model, the Web browser, the content, and the content
viewer are all separate objects.
In the dynamic model, the content knows how to execute itself. The Web
browser understands executable content in a generic sense.
Since the downloaded object knows how to render itself, the browser has
no need to worry about helper applications and the like.
Since the browser knows how to deal with executable objects such as Java
applets and ActiveX Controls, the computing power available on the client
side of the client/server equation is exercised more strenuously.
They are easy to employ in containers that are not Web pages
ISAPI filters
ISAPI Applications
The Internet Server Applications Programming Interface (ISAPI)
ISAPI Filters
The Internet Survey Application Programming Interface (ISAPI)
also provides a mechanism for modifying the behavior of the
server in specific ways.
You'll employ ISAPI filters in cases where the default behavior of
the server is inappropriate for the application.
ISAPI filters can modify the behavior of the following server
functions:
Authentication
Compression
Encryption
Logging
Traffic Analysis
You'll be inserting objects and scripts into the HTML documents in this
window.
The scroll icon indicates the start of a script. Pressing the scroll button in
the margin bar opens the Script Wizard, and loads the appropriate script.
ActiveX objects are indicated in the margin bar by a small cube icon.
This iconography indicates the start of an <OBJECT> declaration in the
HTML.
Pressing the ActiveX object button in the gray margin bar brings up a
window containing the object, and a window containing its property sheet.
The Control Pad uses a special icon for insertions of HTML layouts.
HTML layouts are indicated in the margin bar by a small icon containing
the letter A, a circle, and a square.
Pressing this button brings up the HTML Layout editor and its associated
tool bar.
Add a text box to your layout. Select the text control tool from the toolbox,
and then place your cursor over the Layout window.
Select View, Properties, and change the ID and Text properties. Select the
Text property, and add some initialization text.
Save your layout to a file. The file extension for an HTML Layout is .alx.
The ActiveX Control Pad provides a graphical user interface for adding
VBScript to HTML pages and HTML Layouts.
To add VBScripts using the Script Wizard, take the following steps:
Start the ActiveX Control Pad, if its not already running.
Start the Script Wizard. You can do this in two ways: Press the
Script Wizard toolbar button (the one with the scroll icon), or
select Tools, Script Wizard from the menu bar.
From the Event list, expand the txtMessage item and select the KeyDown
event.
Next, expand the txtMessage item on the Action list. Select the ForeColor
property and double-click.
The color selection window comes forward.
Go ahead and select the color that you want to change the txtMessage box
to when a key is pressed and press OK.
You'll see both the object and the action listed in the script List window.
Change the Script Wizard to the Code View by selecting the Code View
radio button. From the Event list, expand the cmdPressMe object, and
select the Click event.
Invoking procedures
The List View displays each of the statements from the script for the event
you're handling.
The List View provides several command buttons for editing the script:
Insert action
Delete action
Move up action
Modify value
The List View is good for making simple scripts quickly and easily.
However, many times the application requires more sophisticated
programming.
The Code View provides developers with a rudimentary editor for including
VBScripts that you hand code.
To take a look at the Code View, select the Code View radio button. Next,
press the right mouse and select New Procedure from the menu.
Typically, you change the name of the procedure to a useful name, and
then code the logic for the procedure.
A CODED PROCEDURE
If you switch back to the List View, or if you open a procedure developed in
the Code View in the List View, the ActiveX Control Pad only shows a
message as shown in figure.
When you close the Script Wizard, the ActiveX Control Pad adds the
Insert the HTML layout that you created in the previous section. To do this
select Edit, Insert HTML Layout from the main menu.
Then select the HTML layout you just created and press Open.
The gray margin bar now shows an HTML Layout button. Pressing this
button launches the Layout editor as described previously.
Save your HTML page to a file.
Now that you've completed the HTML document, you can test your work
using Microsoft Internet Explorer 3.0.
These next steps take you through testing out your HTML document.
Start Microsoft Internet Explorer 3.0.
Inserting an Object
<BR> tag to make a break between the heading and the HTML
Layout.
Add an ActiveX object.
Select Edit, Insert ActiveX Control from the menu bar. Select the