blob: 252b1a44dcaf0f08872ee12db5462effbc0e0a1f [file] [log] [blame]
syeshinbefd53e2005-07-27 18:16:40 +00001<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4<html>
5<head>
syeshinaaa21932005-09-22 17:13:22 +00006<!-- /*******************************************************************************
7 * Copyright (c) 2000, 2005 IBM Corporation and others.
8 * All rights reserved. This program and the accompanying materials
9 * are made available under the terms of the Eclipse Public License v1.0
10 * which accompanies this distribution, and is available at
11 * http://www.eclipse.org/legal/epl-v10.html
12 *
13 * Contributors:
14 * IBM Corporation - initial API and implementation
15 *******************************************************************************/ -->
16<link rel="stylesheet" type="text/css" href="../../org.eclipse.wst.doc.user/common.css" />
syeshinbefd53e2005-07-27 18:16:40 +000017<title>XML file associations with DTDs and XML schemas</title>
syeshin66078272005-09-20 16:53:38 +000018</head>
syeshinbefd53e2005-07-27 18:16:40 +000019<body id="cxmlcat"><a name="cxmlcat"><!-- --></a>
20
21<h1 class="topictitle1">XML file associations with DTDs and XML schemas</h1>
22<div><p>There are two different ways to associate XML files with DTDs or
23XML schemas.</p><ol><li>Direct association - The XML file contains either the name of a DTD in
24its doctype declaration (for example, &lt;!DOCTYPE root-element SYSTEM " <var class="varname">dtdfile.dtd</var>"
25&gt;, where <var class="varname">dtdfile.dtd</var> is the name of the DTD file) or it
26contains the path of an XML schema in the schemaLocation attribute of the
27XML file root element (for example, &lt;xsi:schemaLocation="http://www.ibm.com
28 <var class="varname">schema.xsd</var>"&gt;, where <var class="varname">schema.xsd</var> is
29the name of the XML schema.</li>
30<li>XML Catalog entry  - You can register DTD and XML schema files in
31the XML Catalog and associate them with a <var class="varname">Key</var> that represents
32them. You can then refer to a DTD or XML schema file <var class="varname">Key</var> from
33an XML file instead of referring directly to the DTD or XML schema file. An
34XML Catalog entry contains two parts - the Key (which represents the DTD or
35XML schema) and a URI (which contains information about the DTD or XML schema
36location).</li>
37</ol>
38<div class="skipspace"><h4 class="sectiontitle">How an association works </h4><b>Associating an XML
39file with a DTD </b><div class="p">If an XML file is associated with a DTD, a DOCTYPE
40tag such as the following is included in the XML file:<pre>&lt;!DOCTYPE root-name PUBLIC "<var class="varname">InvoiceId</var>" "<var class="varname">C:\mydtds\Invoice.dtd</var>"&gt;</pre>
41</div>
42<p><var class="varname">InvoiceId</var> is the public identifier of
43the DTD file. It is used to associate the XML file with a DTD file (in this
44case, the DTD file is <var class="varname">Invoice.dtd</var>). If the public identifier
45InvoiceId corresponds to the <var class="varname">Key</var> of the XML Catalog entry
46for Invoice.dtd, then the <var class="varname">URI</var> of the XML Catalog entry
47(which contains information about the location of Invoice.dtd) is used to
48locate the DTD. Otherwise, the DOCTYPE's system identifier ( <var class="varname">"C:\mydtds\Invoice.dtd"</var>),
49which refers directly to the file system location of the DTD, is used to locate
50the DTD. </p>
51<p> <b>Note</b>: You can also use a system identifier as
52a Key in an XML Catalog entry. If you use a system identifier as a Key, a
53DOCTYPE tag such as the following is included in an XML file:</p>
54<pre>&lt;!DOCTYPE Root-name SYSTEM "<var class="varname">MyDTD.dtd</var>"&gt; </pre>
55<p>where <var class="varname">MyDTD.dtd</var> is the system identifier that corresponds
56to the Key of an XML Catalog entry.</p>
57</div>
58<div class="skipspace"><b>Associating an XML file with an XML schema</b><p>If an XML file
59is associated with an XML schema, one or more schema location attributes are
60included in the XML file. The information in the schemaLocation is provided
61as a "hint" to the XML processor. Examples of schemaLocation attributes are
62shown below: </p>
63<div class="p"> <b>Example 1 </b><pre>&lt;purchaseOrder xmlns="http://www.ibm.com"
64xsi:schemaLocation="http://www.ibm.com C:\myschemas\PurchaseOrder.xsd"&gt;
65&lt;shipTo country="US"&gt; 
66...</pre>
67 </div>
68<div class="p"><b>Example 2 </b><pre>&lt;purchaseOrder xmlns="http://www.ibm.com"
69xsi:schemaLocation="http://www.ibm.com PO.xsd"&gt;
70&lt;shipTo country="US"&gt; 
71....</pre>
72 </div>
73<p>In Example 1, the schemaLocation 'hint' ('C:\myschemas\PurchaseOrder.xsd')
74refers directly to the file system location or URI of the XML schema. In this
75case, the schema file will be located by the XML processor directly.</p>
76<p>In
77Example 2, the schemaLocation 'hint' ('PO.xsd') refers to an XML Catalog entry.
78PO.xsd corresponds to the <var class="varname">Key</var> of the XML Catalog entry
79for PurchaseOrder.xsd, and the URI of the XML Catalog entry (which contains
80information about the location of PurchaseOrder.xsd) will be used to located
81the XML schema.</p>
82<p>In both examples, <samp class="codeph">http://www.ibm.com</samp> in
83the <samp class="codeph">xsi:schemaLocation</samp> tag is a URI that identifies the namespace
84for the XML schema. </p>
85<div class="p">You can also use a namespace as a Key for
86an XML Catalog entry. If you use a namespace as a Key, a schemaLocation tag
87such as the following is included in an XML file:<pre>&lt;purchaseOrder xmlns:="www.ibm.com" 
88 xsi:schemaLocation="http://www.ibm.com po/xsd/PurchaseOrder.xsd "&gt;</pre>
89</div>
90<p>The
91schemaLocation attribute points to both the Key and the actual location of
92the schema.</p>
93<p><b>DTD or XML schema resides on a remote server</b></p>
94<p>Several
95functions in the XML editor, such as validation and content assist, require
96the availability of a DTD or an XML schema. The product documentation provides
97usage information for cases when the DTD or XML schema resides on your local
98machine. However, in many cases, the DTD or XML schema may reside on a remote
99server, for example:</p>
100<p><samp class="codeph">&lt;!DOCTYPE Catalog PUBLIC "abc/Catalog"
101"http://xyz.abc.org/dtds/catalog.dtd"&gt;</samp></p>
102<p>Normally, this case
103poses no problem, because the DTD or XML schema can be retrieved from the
104remote server. However, if you are behind a firewall, and do not have a SOCKSified
105system, the workbench currently does not provide a way for you to specify
106a socks server for retrieving a DTD or XML schema. If you are unable to SOCKSify
107your system, the workaround for this problem is to retrieve a copy of the
108DTD or XML schema (using a Web browser, for example) and save that copy on
109your local machine. Then, you can either place a local copy in the same project
110as your XML file, or use the XML Catalog to associate a public identifier
111with the DTD's (local) location.</p>
112<p><b>Note</b>: If you have an XML file
113associated with an XML schema or DTD that is elsewhere in the network, and
114you are working on a machine disconnected from the network, you can follow
115the steps described above if you want to use content assist or validate your
116XML file. </p>
117</div>
118<div class="skipspace"><h4 class="sectiontitle">Advantages of XML Catalog entry associations</h4><p>If
119you create a direct association between an XML file and an XML schema or DTD
120file, any time you change the location of the schema or DTD you have to track
121down and update all of the referencing XML files with the new location of
122the DTD or schema. If, however, you associate an XML file with an XML schema
123or DTD Key, then, when you change the location of the schema or DTD, you only
124have to update the XML Catalog entry, instead of each individual XML file. </p>
125<p>For
126example, you have a DTD called "Building.dtd", which is associated with five
127XML files - Office.xml, House.xml, Apartment.xml, Bank.xml, and PostOffice.xml.
128You move the DTD file Building.dtd to a new location. If you have a direction
129association between Building.dtd and all the XML files, you will have to update
130the &lt;DOCTTYPE&gt; declaration in each XML file to reflect the new location
131of Building.dtd.  If, however, you have an XML Catalog association, and
132all the XML files just refer to the Key of Building.dtd, then you only have
133to update the URI and all the XML files will point to the new location of
134Building.dtd.</p>
135</div>
136<div class="skipspace"><h4 class="sectiontitle">Updating an entry in the XML Catalog</h4><p>After you have
137updated an entry in the XML Catalog, you may need to refresh the XML editor
138view so that it uses the new information. To do this, click the <span class="uicontrol">Reload
139Dependencies</span> toolbar button <img src="../images/rldgrmr.gif" /> and
140the view will be updated using the current XML Catalog settings. You only
141need to refresh the XML editor view when you have an XML file open that references
142the XML Catalog entry that was updated.</p>
143<p>For more information, refer
144to the related concepts and tasks below.</p>
145<p>(c) Copyright 2001, World Wide
146Web Consortium (Massachusetts Institute of Technology, Institut National de
147Recherche en Informatique et en Automatique, Keio University).</p>
148</div>
149</div>
150
151<div>
152<blockquote>
153<div class="ulchildlink"><b><a href="../topics/txmlcat.html">Adding an entry to the XML Catalog</a></b><br />
154</div>
155<div class="ulchildlink"><b><a href="../topics/tedtgram.html">Updating XML files with changes made to DTDs and schemas</a></b><br />
156If you make changes to a DTD file or XML schema associated with
157an XML file (that is currently open), click <span class="uicontrol">XML &gt; Reload Dependencies</span> to
158update the XML file with these changes.</div>
159</blockquote>
160<p><b class="relconceptshd">Related concepts</b><br />
161<a href="../topics/cwxmledt.html" title="The XML editor is a tool for creating and viewing XML files">XML editor</a><br />
162</p>
163<p><b class="reltaskshd">Related tasks</b><br />
164<a href="../topics/tedtcnst.html" title="In the Design view, when you edit an XML file that has a set of constraints (that is, a set of rules) defined by a DTD or an XML schema, you can turn the constraints on and off to provide flexibility in the way you edit, but still maintain the validity of the document periodically.">Editing with DTD or XML schema constraints</a><br />
165<a href="../topics/tedtdoc.html" title="The DOCTYPE declaration in an XML file is used at the beginning of it to associate it with a DTD file. You can edit your DOCTYPE declaration to change the DTD file your XML file is associated with.">Editing your DOCTYPE declaration</a><br />
166<a href="../topics/txmlcat.html" title="Adding an entry to the XML Catalog"></a><br />
167<a href="../topics/tedtgram.html" title="If you make changes to a DTD file or XML schema associated with an XML file (that is currently open), click XML &gt; Reload Dependencies to update the XML file with these changes.">Updating XML files with changes made to DTDs and schemas</a><br />
168<a href="../topics/tedtsch.html" title="Your namespace information is used to provide various information about the XML file, such as the XML schema it is associated with. ">Editing your namespace information</a><br />
169<a href="../topics/tedtproc.html" title="A processing instruction is a syntax in XML for passing instructions along to the application using an XML document.">Editing your XML processing instructions</a><br />
170<a href="../topics/txedtdes.html" title="The XML editor has a Design view, which represents the XML file simultaneously as a table and a tree. This helps make navigation and editing easier. Content and attribute values can be edited directly in the table cells, while pop-up menus on the tree elements give alternatives that are valid for that particular element.">Editing in the Design view</a><br />
171<a href="../topics/txedtsrc.html" title="You can use the Source view to view and work with a file's source code directly.">Editing in the Source view</a><br />
172</p>
syeshinaaa21932005-09-22 17:13:22 +0000173</div>
syeshinbefd53e2005-07-27 18:16:40 +0000174</body>
175</html>