Transcript Document

XML
Outline
1
XML
2
DTD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
"http://java.sun.com/dtd/web-app_2_3.dtd ">
<web-app>
<!-- Servlet definitions -->
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<!-- Servlet mappings -->
<servlet-mapping>
<servlet-name>welcome</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
Lines 1-5 comprise the Prolog. Line 1
is the XML declaration. “version” &
“encoding” are attributes.
2.3//EN"
Document Type Definition. Either a
DTD or Schema is used by a parser
The Body of the xml doc starts with
to validate the xml doc.
the root element. An element consists
A comment.
of<servlet>
a start tag,
end of
tagthe
& <web-app>
everything
is aanchild
inelement
between.
and a parent to <servletname> & <servlet-class>. Well-formed
xml docs follow a strict parent-child
hierarchy.
The xml doc ends with the
closing tag of the root element.
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
• DOCTYPE refers to web-app, the root element – this is the definition
for this web-app document
• PUBLIC means the DTD is available on the Internet. Locally-stored
DTDs would instead use the SYSTEM keyword, followed by the
local path, e.g., “C:\Windows\Desktop\web-app_2_3.dtd”
• "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN“ is
the “Formal Public Identifier” used with PUBLIC DTDs
– The dash ( - ) indicates the DTD has not been approved by a Standards
body, such as ISO. Approved Standard DTDs use a plus sign here ( + ).
– Sun Microsystems, Inc. is the name of the owner who maintains the
DTD.
– DTD is the document type and Web Application 2.3 is a label that
describes the document.
– EN is the two-letter abbreviation for the language the DTD is written in.
Here, it’s English.
• “http://java.sun.com/dtd/web-app_2_3.dtd“ specifies the URL
where the parser may find a copy of the DTD. Let’s take a look at this
DTD.