blob: c50b8a2dd14de47b1828cd35c05702dca858069b [file] [log] [blame]
kpriceef160682006-08-29 18:08:31 +00001<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html lang="en-us" xml:lang="en-us">
syeshinbefd53e2005-07-27 18:16:40 +00003<head>
kpriceef160682006-08-29 18:08:31 +00004<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
kpriceb59c9f62008-04-02 21:24:37 +00005<meta name="copyright" content="Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: IBM Corporation - initial API and implementation" />
6<meta name="DC.rights.owner" content="(C) Copyright 2000, 2008" />
kpriceef160682006-08-29 18:08:31 +00007<meta content="public" name="security" />
8<meta content="index,follow" name="Robots" />
9<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
10<meta content="concept" name="DC.Type" />
11<meta name="DC.Title" content="XML file associations with DTDs and XML schemas" />
12<meta name="abstract" content="When an XML file is associated with a DTD or XML schema, it is bound by any structural rules contained in the DTD or XML schema. To be considered a valid XML file, a document must be accompanied by a DTD or an XML schema, and conform to all of the declarations in the DTD or the XML schema." />
13<meta name="description" content="When an XML file is associated with a DTD or XML schema, it is bound by any structural rules contained in the DTD or XML schema. To be considered a valid XML file, a document must be accompanied by a DTD or an XML schema, and conform to all of the declarations in the DTD or the XML schema." />
kpriceb59c9f62008-04-02 21:24:37 +000014<meta content="XML catalog, overview, XML files, associations" name="DC.subject" />
15<meta content="XML catalog, overview, XML files, associations" name="keywords" />
kpricedb43fb32008-07-23 20:16:44 +000016<meta scheme="URI" name="DC.Relation" content="tedtcnst.html" />
17<meta scheme="URI" name="DC.Relation" content="tedtdoc.html" />
18<meta scheme="URI" name="DC.Relation" content="txmlcat.html" />
19<meta scheme="URI" name="DC.Relation" content="tedtgram.html" />
20<meta scheme="URI" name="DC.Relation" content="tedtcnst.html" />
21<meta scheme="URI" name="DC.Relation" content="tedtsch.html" />
22<meta scheme="URI" name="DC.Relation" content="txmlcat.html" />
23<meta scheme="URI" name="DC.Relation" content="tedtgram.html" />
24<meta scheme="URI" name="DC.Relation" content="tedtproc.html" />
25<meta scheme="URI" name="DC.Relation" content="cwxmledt.html" />
26<meta scheme="URI" name="DC.Relation" content="txedtdes.html" />
27<meta scheme="URI" name="DC.Relation" content="txedtsrc.html" />
kpriceef160682006-08-29 18:08:31 +000028<meta content="XHTML" name="DC.Format" />
29<meta content="cxmlcat" name="DC.Identifier" />
30<meta content="en-us" name="DC.Language" />
31<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
syeshinbefd53e2005-07-27 18:16:40 +000032<title>XML file associations with DTDs and XML schemas</title>
syeshin66078272005-09-20 16:53:38 +000033</head>
syeshinbefd53e2005-07-27 18:16:40 +000034<body id="cxmlcat"><a name="cxmlcat"><!-- --></a>
35
kpriceef160682006-08-29 18:08:31 +000036
syeshinbefd53e2005-07-27 18:16:40 +000037<h1 class="topictitle1">XML file associations with DTDs and XML schemas</h1>
kpriceef160682006-08-29 18:08:31 +000038
39
40
41
syeshind0bdb8e2005-10-27 17:44:14 +000042<div><p>When an XML file is associated with a DTD or XML schema, it is
43bound by any structural rules contained in the DTD or XML schema. To be considered
44a valid XML file, a document must be accompanied by a DTD or an XML schema,
45and conform to all of the declarations in the DTD or the XML schema.</p>
kpriceef160682006-08-29 18:08:31 +000046
47<p>There are two different ways to associate XML files with DTDs or XML schemas.</p>
48
49<ol>
50<li>Direct association - The XML file contains either the name of a DTD in
kpriceb59c9f62008-04-02 21:24:37 +000051its doctype declaration (for example, &lt;!DOCTYPE root-element SYSTEM "<var class="varname">dtdfile.dtd</var>"
52&gt;, where <var class="varname">dtdfile.dtd</var> is the name of the DTD file) or it
syeshinbefd53e2005-07-27 18:16:40 +000053contains the path of an XML schema in the schemaLocation attribute of the
kpriceb59c9f62008-04-02 21:24:37 +000054XML file root element (for example, &lt;xsi:schemaLocation="http://www.ibm.com/<var class="varname">schema.xsd</var>"&gt;,
55where <var class="varname">schema.xsd</var> is the name of the XML schema.</li>
kpriceef160682006-08-29 18:08:31 +000056
57<li>XML Catalog entry - You can register DTD and XML schema files in the XML
kpriceb59c9f62008-04-02 21:24:37 +000058Catalog and associate them with a Key that represents them. You can then
59refer to a DTD or XML schema file Key from an XML file instead of referring
60directly to the DTD or XML schema file. An XML Catalog entry contains two
61parts - the Key (which represents the DTD or XML schema) and a URI (which
62contains information about the DTD or XML schema location).</li>
kpriceef160682006-08-29 18:08:31 +000063
syeshinbefd53e2005-07-27 18:16:40 +000064</ol>
kpriceef160682006-08-29 18:08:31 +000065
66<div class="section"><h4 class="sectiontitle">How an association works</h4><strong>Associating an XML file
67with a DTD </strong><div class="p">If an XML file is associated with a DTD, a DOCTYPE tag such
68as the following one 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;
69</pre>
syeshinbefd53e2005-07-27 18:16:40 +000070</div>
kpriceb59c9f62008-04-02 21:24:37 +000071<p>InvoiceId is the public identifier of the DTD file. It
72is used to associate the XML file with a DTD file (in this case, the DTD file
73is Invoice.dtd). If the public identifier InvoiceId corresponds to the Key
74of the XML Catalog entry for Invoice.dtd, then the URI of the
75XML Catalog entry (which contains information about the location of Invoice.dtd)
76is used to locate the DTD. Otherwise, the DOCTYPE's system identifier ("C:\mydtds\Invoice.dtd"),
syeshinbefd53e2005-07-27 18:16:40 +000077which refers directly to the file system location of the DTD, is used to locate
syeshind0bdb8e2005-10-27 17:44:14 +000078the DTD.</p>
kpriceb59c9f62008-04-02 21:24:37 +000079<div class="note"><span class="notetitle">Note:</span> You can also use a system identifier as a Key in an XML
80Catalog entry. If you use a system identifier as a Key, a DOCTYPE tag such
81as the following one is included in an XML file:</div>
82<pre>&lt;!DOCTYPE Root-name SYSTEM "MyDTD.dtd"&gt; </pre>
83<p>where
84MyDTD.dtd is the system identifier that corresponds to the Key of an XML Catalog
85entry.</p>
syeshinbefd53e2005-07-27 18:16:40 +000086</div>
kpriceef160682006-08-29 18:08:31 +000087
88<div class="section"><strong>Associating an XML file with an XML schema</strong><p>If an XML file
syeshinbefd53e2005-07-27 18:16:40 +000089is associated with an XML schema, one or more schema location attributes are
90included in the XML file. The information in the schemaLocation is provided
kpriceef160682006-08-29 18:08:31 +000091as a "hint" to the XML processor. The following examples show schemaLocation
kpriceb59c9f62008-04-02 21:24:37 +000092attributes:</p>
kpriceef160682006-08-29 18:08:31 +000093<div class="p"> <strong>Example 1 </strong><pre>&lt;purchaseOrder xmlns="http://www.ibm.com"
syeshinbefd53e2005-07-27 18:16:40 +000094xsi:schemaLocation="http://www.ibm.com C:\myschemas\PurchaseOrder.xsd"&gt;
syeshind0bdb8e2005-10-27 17:44:14 +000095&lt;shipTo country="US"&gt;
syeshinbefd53e2005-07-27 18:16:40 +000096...</pre>
97 </div>
kpriceef160682006-08-29 18:08:31 +000098<div class="p"><strong>Example 2 </strong><pre>&lt;purchaseOrder xmlns="http://www.ibm.com"
syeshinbefd53e2005-07-27 18:16:40 +000099xsi:schemaLocation="http://www.ibm.com PO.xsd"&gt;
syeshind0bdb8e2005-10-27 17:44:14 +0000100&lt;shipTo country="US"&gt;
syeshinbefd53e2005-07-27 18:16:40 +0000101....</pre>
102 </div>
103<p>In Example 1, the schemaLocation 'hint' ('C:\myschemas\PurchaseOrder.xsd')
104refers directly to the file system location or URI of the XML schema. In this
105case, the schema file will be located by the XML processor directly.</p>
106<p>In
107Example 2, the schemaLocation 'hint' ('PO.xsd') refers to an XML Catalog entry.
108PO.xsd corresponds to the <var class="varname">Key</var> of the XML Catalog entry
109for PurchaseOrder.xsd, and the URI of the XML Catalog entry (which contains
110information about the location of PurchaseOrder.xsd) will be used to located
111the XML schema.</p>
112<p>In both examples, <samp class="codeph">http://www.ibm.com</samp> in
kpriceef160682006-08-29 18:08:31 +0000113the <samp class="codeph">xsi:schemaLocation</samp> tag is a URI that identifies the namespace
114for the XML schema.</p>
115<div class="p">You can also use a namespace as a Key for an XML
116Catalog entry. If you use a namespace as a Key, a schemaLocation tag such
117as the following one is included in an XML file:<pre>&lt;purchaseOrder xmlns:="www.ibm.com"
syeshind0bdb8e2005-10-27 17:44:14 +0000118xsi:schemaLocation="http://www.ibm.com po/xsd/PurchaseOrder.xsd "&gt;</pre>
syeshinbefd53e2005-07-27 18:16:40 +0000119</div>
120<p>The
121schemaLocation attribute points to both the Key and the actual location of
122the schema.</p>
kpriceef160682006-08-29 18:08:31 +0000123<p><strong>DTD or XML schema resides on a remote server</strong></p>
syeshinbefd53e2005-07-27 18:16:40 +0000124<p>Several
125functions in the XML editor, such as validation and content assist, require
126the availability of a DTD or an XML schema. The product documentation provides
127usage information for cases when the DTD or XML schema resides on your local
kpriceef160682006-08-29 18:08:31 +0000128machine. However, in many cases, the DTD or XML schema can reside on a remote
syeshinbefd53e2005-07-27 18:16:40 +0000129server, for example:</p>
130<p><samp class="codeph">&lt;!DOCTYPE Catalog PUBLIC "abc/Catalog"
131"http://xyz.abc.org/dtds/catalog.dtd"&gt;</samp></p>
132<p>Normally, this case
133poses no problem, because the DTD or XML schema can be retrieved from the
134remote server. However, if you are behind a firewall, and do not have a SOCKSified
135system, the workbench currently does not provide a way for you to specify
136a socks server for retrieving a DTD or XML schema. If you are unable to SOCKSify
137your system, the workaround for this problem is to retrieve a copy of the
138DTD or XML schema (using a Web browser, for example) and save that copy on
139your local machine. Then, you can either place a local copy in the same project
140as your XML file, or use the XML Catalog to associate a public identifier
141with the DTD's (local) location.</p>
kpriceb59c9f62008-04-02 21:24:37 +0000142<div class="note"><span class="notetitle">Note:</span> If you have an XML file associated
143with an XML schema or DTD that is elsewhere in the network, and you are working
144on a machine disconnected from the network, you can follow the steps described
145previously if you want to use content assist or validate your XML file. </div>
syeshinbefd53e2005-07-27 18:16:40 +0000146</div>
kpriceef160682006-08-29 18:08:31 +0000147
148<div class="section"><h4 class="sectiontitle">Advantages of XML Catalog entry associations</h4><p>If
syeshinbefd53e2005-07-27 18:16:40 +0000149you create a direct association between an XML file and an XML schema or DTD
150file, any time you change the location of the schema or DTD you have to track
151down and update all of the referencing XML files with the new location of
152the DTD or schema. If, however, you associate an XML file with an XML schema
kpriceef160682006-08-29 18:08:31 +0000153or DTD Key, then, when you change the location of the schema or DTD, you only
154have to update the XML Catalog entry, instead of each individual XML file.</p>
syeshinbefd53e2005-07-27 18:16:40 +0000155<p>For
kpriceb59c9f62008-04-02 21:24:37 +0000156example, you have a DTD called Building.dtd, which is associated with five
syeshinbefd53e2005-07-27 18:16:40 +0000157XML files - Office.xml, House.xml, Apartment.xml, Bank.xml, and PostOffice.xml.
158You move the DTD file Building.dtd to a new location. If you have a direction
159association between Building.dtd and all the XML files, you will have to update
160the &lt;DOCTTYPE&gt; declaration in each XML file to reflect the new location
kprice8ca223b2007-04-05 03:35:57 +0000161of Building.dtd. If, however, you have an XML Catalog association, and all
162the XML files just refer to the Key of Building.dtd, then you only have to
163update the URI and all the XML files will point to the new location of Building.dtd.</p>
syeshinbefd53e2005-07-27 18:16:40 +0000164</div>
kpriceef160682006-08-29 18:08:31 +0000165
166<div class="section"><h4 class="sectiontitle">Updating an entry in the XML Catalog</h4><p>After you have
167updated an entry in the XML Catalog, you might need to refresh the XML editor
168view so that it uses the new information. To do this, click the <span class="uicontrol">Reload
169Dependencies</span> toolbar button <img src="../images/rldgrmr.gif" alt="This graphic is the Reload Dependencies toolbar button" /> and
syeshinbefd53e2005-07-27 18:16:40 +0000170the view will be updated using the current XML Catalog settings. You only
171need to refresh the XML editor view when you have an XML file open that references
172the XML Catalog entry that was updated.</p>
173<p>For more information, refer
kpriceef160682006-08-29 18:08:31 +0000174to the related tasks.</p>
syeshinbefd53e2005-07-27 18:16:40 +0000175</div>
kpriceef160682006-08-29 18:08:31 +0000176
syeshinbefd53e2005-07-27 18:16:40 +0000177</div>
kpriceef160682006-08-29 18:08:31 +0000178
syeshind0bdb8e2005-10-27 17:44:14 +0000179<div><div class="relconcepts"><strong>Related concepts</strong><br />
kpricedb43fb32008-07-23 20:16:44 +0000180<div><a href="cwxmledt.html" title="The XML editor is a tool for creating and viewing XML files.">XML editor</a></div>
syeshinbefd53e2005-07-27 18:16:40 +0000181</div>
kpriceef160682006-08-29 18:08:31 +0000182<div class="reltasks"><strong>Related tasks</strong><br />
kpricedb43fb32008-07-23 20:16:44 +0000183<div><a href="tedtcnst.html" title="In the Design view, when you edit an XML file that has a set of constraints or 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></div>
184<div><a href="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 DOCTYPE declarations</a></div>
185<div><a href="txmlcat.html" title="An XML Catalog entry contains two parts - a Key (which represents a DTD or XML schema) and a Location (similar to a URI, which contains information about a DTD or XML schema's location). You can place the Key in an XML file. When the XML processor encounters it, it will use the XML Catalog entry to find the location of the DTD or XML schema associated with the Key">Adding entries to the XML Catalog</a></div>
186<div><a href="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. The changes will be reflected in the guided editing mechanisms available in the editor, such as content assist.">Updating XML files with changes made to DTDs and schemas</a></div>
187<div><a href="tedtsch.html" title="Your namespace information is used to provide various information about the XML file, such as the XML schema and namespace it is associated with. If desired, you can change the schema and namespace your XML file is associated with or add a new association. Modifying any associations can impact what content is allowed in the XML file.">Editing namespace information</a></div>
188<div><a href="tedtproc.html" title="If you have instructions you want to send to an application using an XML document, you can use a processing instruction.">Editing XML processing instructions</a></div>
189<div><a href="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></div>
190<div><a href="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></div>
kpriceef160682006-08-29 18:08:31 +0000191</div>
192</div>
193
194</body>
syeshinbefd53e2005-07-27 18:16:40 +0000195</html>