XML Outline 1 XML 2 DTD
The xml doc ends with the closing tag of the root element. Lines 1-5 comprise the Prolog. Line 1 is the XML declaration. “version” & “encoding” are attributes. 1 <?xml version="1.0" encoding="ISO-8859-1"?> 2 3 <!DOCTYPE web-app 4 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 5 "http://java.sun.com/dtd/web-app_2_3.dtd "> 6 7 <web-app> 8 9 <!-- Servlet definitions --> 10 <servlet> 11 <servlet-name>welcome</servlet-name> 12 <servlet-class>WelcomeServlet</servlet-class> 13 </servlet> 14 15 <!-- Servlet mappings --> 16 <servlet-mapping> 17 <servlet-name>welcome</servlet-name> 18 <url-pattern>/welcome</url-pattern> 19 </servlet-mapping> 20 21 </web-app> Document Type Definition. Either a DTD or Schema is used by a parser to validate the xml doc. The Body of the xml doc starts with the root element. An element consists of a start tag, an end tag & everything in between. A comment. <servlet> is a child of the <web-app> element and a parent to <servlet-name> & <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 <!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.