syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 1 | <?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> |
syeshin | aaa2193 | 2005-09-22 17:13:22 +0000 | [diff] [blame] | 6 | <!-- /******************************************************************************* |
| 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" /> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 17 | <title>XML file associations with DTDs and XML schemas</title> |
syeshin | 6607827 | 2005-09-20 16:53:38 +0000 | [diff] [blame] | 18 | </head> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 19 | <body id="cxmlcat"><a name="cxmlcat"><!-- --></a> |
| 20 | |
| 21 | <h1 class="topictitle1">XML file associations with DTDs and XML schemas</h1> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 22 | <div><p>When an XML file is associated with a DTD or XML schema, it is |
| 23 | bound by any structural rules contained in the DTD or XML schema. To be considered |
| 24 | a valid XML file, a document must be accompanied by a DTD or an XML schema, |
| 25 | and conform to all of the declarations in the DTD or the XML schema.</p> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 26 | <div><p>There are two different ways to associate XML files with DTDs or |
| 27 | XML schemas.</p><ol><li>Direct association - The XML file contains either the name of a DTD in |
| 28 | its doctype declaration (for example, <!DOCTYPE root-element SYSTEM " <var class="varname">dtdfile.dtd</var>" |
| 29 | >, where <var class="varname">dtdfile.dtd</var> is the name of the DTD file) or it |
| 30 | contains the path of an XML schema in the schemaLocation attribute of the |
| 31 | XML file root element (for example, <xsi:schemaLocation="http://www.ibm.com |
| 32 | <var class="varname">schema.xsd</var>">, where <var class="varname">schema.xsd</var> is |
| 33 | the name of the XML schema.</li> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 34 | <li>XML Catalog entry - You can register DTD and XML schema files in |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 35 | the XML Catalog and associate them with a <var class="varname">Key</var> that represents |
| 36 | them. You can then refer to a DTD or XML schema file <var class="varname">Key</var> from |
| 37 | an XML file instead of referring directly to the DTD or XML schema file. An |
| 38 | XML Catalog entry contains two parts - the Key (which represents the DTD or |
| 39 | XML schema) and a URI (which contains information about the DTD or XML schema |
| 40 | location).</li> |
| 41 | </ol> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 42 | <div class="skipspace"><h4 class="sectiontitle">How an association works</h4><b>Associating an XML |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 43 | file with a DTD </b><div class="p">If an XML file is associated with a DTD, a DOCTYPE |
| 44 | tag such as the following is included in the XML file:<pre><!DOCTYPE root-name PUBLIC "<var class="varname">InvoiceId</var>" "<var class="varname">C:\mydtds\Invoice.dtd</var>"></pre> |
| 45 | </div> |
| 46 | <p><var class="varname">InvoiceId</var> is the public identifier of |
| 47 | the DTD file. It is used to associate the XML file with a DTD file (in this |
| 48 | case, the DTD file is <var class="varname">Invoice.dtd</var>). If the public identifier |
| 49 | InvoiceId corresponds to the <var class="varname">Key</var> of the XML Catalog entry |
| 50 | for Invoice.dtd, then the <var class="varname">URI</var> of the XML Catalog entry |
| 51 | (which contains information about the location of Invoice.dtd) is used to |
| 52 | locate the DTD. Otherwise, the DOCTYPE's system identifier ( <var class="varname">"C:\mydtds\Invoice.dtd"</var>), |
| 53 | which refers directly to the file system location of the DTD, is used to locate |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 54 | the DTD.</p> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 55 | <p> <b>Note</b>: You can also use a system identifier as |
| 56 | a Key in an XML Catalog entry. If you use a system identifier as a Key, a |
| 57 | DOCTYPE tag such as the following is included in an XML file:</p> |
| 58 | <pre><!DOCTYPE Root-name SYSTEM "<var class="varname">MyDTD.dtd</var>"> </pre> |
| 59 | <p>where <var class="varname">MyDTD.dtd</var> is the system identifier that corresponds |
| 60 | to the Key of an XML Catalog entry.</p> |
| 61 | </div> |
| 62 | <div class="skipspace"><b>Associating an XML file with an XML schema</b><p>If an XML file |
| 63 | is associated with an XML schema, one or more schema location attributes are |
| 64 | included in the XML file. The information in the schemaLocation is provided |
| 65 | as a "hint" to the XML processor. Examples of schemaLocation attributes are |
| 66 | shown below: </p> |
| 67 | <div class="p"> <b>Example 1 </b><pre><purchaseOrder xmlns="http://www.ibm.com" |
| 68 | xsi:schemaLocation="http://www.ibm.com C:\myschemas\PurchaseOrder.xsd"> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 69 | <shipTo country="US"> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 70 | ...</pre> |
| 71 | </div> |
| 72 | <div class="p"><b>Example 2 </b><pre><purchaseOrder xmlns="http://www.ibm.com" |
| 73 | xsi:schemaLocation="http://www.ibm.com PO.xsd"> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 74 | <shipTo country="US"> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 75 | ....</pre> |
| 76 | </div> |
| 77 | <p>In Example 1, the schemaLocation 'hint' ('C:\myschemas\PurchaseOrder.xsd') |
| 78 | refers directly to the file system location or URI of the XML schema. In this |
| 79 | case, the schema file will be located by the XML processor directly.</p> |
| 80 | <p>In |
| 81 | Example 2, the schemaLocation 'hint' ('PO.xsd') refers to an XML Catalog entry. |
| 82 | PO.xsd corresponds to the <var class="varname">Key</var> of the XML Catalog entry |
| 83 | for PurchaseOrder.xsd, and the URI of the XML Catalog entry (which contains |
| 84 | information about the location of PurchaseOrder.xsd) will be used to located |
| 85 | the XML schema.</p> |
| 86 | <p>In both examples, <samp class="codeph">http://www.ibm.com</samp> in |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 87 | the <samp class="codeph">xsi:schemaLocation</samp> tag is a URI that identifies |
| 88 | the namespace for the XML schema.</p> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 89 | <div class="p">You can also use a namespace as a Key for |
| 90 | an XML Catalog entry. If you use a namespace as a Key, a schemaLocation tag |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 91 | such as the following is included in an XML file:<pre><purchaseOrder xmlns:="www.ibm.com" |
| 92 | xsi:schemaLocation="http://www.ibm.com po/xsd/PurchaseOrder.xsd "></pre> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 93 | </div> |
| 94 | <p>The |
| 95 | schemaLocation attribute points to both the Key and the actual location of |
| 96 | the schema.</p> |
| 97 | <p><b>DTD or XML schema resides on a remote server</b></p> |
| 98 | <p>Several |
| 99 | functions in the XML editor, such as validation and content assist, require |
| 100 | the availability of a DTD or an XML schema. The product documentation provides |
| 101 | usage information for cases when the DTD or XML schema resides on your local |
| 102 | machine. However, in many cases, the DTD or XML schema may reside on a remote |
| 103 | server, for example:</p> |
| 104 | <p><samp class="codeph"><!DOCTYPE Catalog PUBLIC "abc/Catalog" |
| 105 | "http://xyz.abc.org/dtds/catalog.dtd"></samp></p> |
| 106 | <p>Normally, this case |
| 107 | poses no problem, because the DTD or XML schema can be retrieved from the |
| 108 | remote server. However, if you are behind a firewall, and do not have a SOCKSified |
| 109 | system, the workbench currently does not provide a way for you to specify |
| 110 | a socks server for retrieving a DTD or XML schema. If you are unable to SOCKSify |
| 111 | your system, the workaround for this problem is to retrieve a copy of the |
| 112 | DTD or XML schema (using a Web browser, for example) and save that copy on |
| 113 | your local machine. Then, you can either place a local copy in the same project |
| 114 | as your XML file, or use the XML Catalog to associate a public identifier |
| 115 | with the DTD's (local) location.</p> |
| 116 | <p><b>Note</b>: If you have an XML file |
| 117 | associated with an XML schema or DTD that is elsewhere in the network, and |
| 118 | you are working on a machine disconnected from the network, you can follow |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 119 | the steps described previously if you want to use content assist or validate |
| 120 | your XML file. </p> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 121 | </div> |
| 122 | <div class="skipspace"><h4 class="sectiontitle">Advantages of XML Catalog entry associations</h4><p>If |
| 123 | you create a direct association between an XML file and an XML schema or DTD |
| 124 | file, any time you change the location of the schema or DTD you have to track |
| 125 | down and update all of the referencing XML files with the new location of |
| 126 | the DTD or schema. If, however, you associate an XML file with an XML schema |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 127 | or DTD Key, then, when you change the location of the schema or DTD, you only |
| 128 | have to update the XML Catalog entry, instead of each individual XML file.</p> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 129 | <p>For |
| 130 | example, you have a DTD called "Building.dtd", which is associated with five |
| 131 | XML files - Office.xml, House.xml, Apartment.xml, Bank.xml, and PostOffice.xml. |
| 132 | You move the DTD file Building.dtd to a new location. If you have a direction |
| 133 | association between Building.dtd and all the XML files, you will have to update |
| 134 | the <DOCTTYPE> declaration in each XML file to reflect the new location |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 135 | of Building.dtd. If, however, you have an XML Catalog association, and |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 136 | all the XML files just refer to the Key of Building.dtd, then you only have |
| 137 | to update the URI and all the XML files will point to the new location of |
| 138 | Building.dtd.</p> |
| 139 | </div> |
| 140 | <div class="skipspace"><h4 class="sectiontitle">Updating an entry in the XML Catalog</h4><p>After you have |
| 141 | updated an entry in the XML Catalog, you may need to refresh the XML editor |
| 142 | view so that it uses the new information. To do this, click the <span class="uicontrol">Reload |
| 143 | Dependencies</span> toolbar button <img src="../images/rldgrmr.gif" /> and |
| 144 | the view will be updated using the current XML Catalog settings. You only |
| 145 | need to refresh the XML editor view when you have an XML file open that references |
| 146 | the XML Catalog entry that was updated.</p> |
| 147 | <p>For more information, refer |
| 148 | to the related concepts and tasks below.</p> |
| 149 | <p>(c) Copyright 2001, World Wide |
| 150 | Web Consortium (Massachusetts Institute of Technology, Institut National de |
| 151 | Recherche en Informatique et en Automatique, Keio University).</p> |
| 152 | </div> |
| 153 | </div> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 154 | <div><div class="relconcepts"><strong>Related concepts</strong><br /> |
| 155 | <div><a href="../topics/cwxmledt.html" title="The XML editor is a tool for creating and viewing XML files.">XML editor</a></div><br/> |
| 156 | <div><strong>Related tasks</strong><br/> |
| 157 | <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."> |
| 158 | Editing with DTD or XML schema constraints</a></div> |
| 159 | <div> |
| 160 | <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 DOCTYPE declarations</a></div> |
| 161 | <div> |
| 162 | <a href="../topics/txmlcat.html" title="An XML Catalog entry contains two parts - a Key (which represents a DTD or XML schema) and a Uniform Resource Identifier (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> |
| 163 | <div> |
| 164 | <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 > 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> |
| 165 | <div> |
| 166 | <a href="../topics/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> |
| 167 | <div> |
| 168 | <a href="../topics/tedtproc.html" title="If you have instructions you want to pass along to an application using an XML document, you can use a processing instruction.">Editing XML processing instructions</a></div> |
| 169 | <div> |
| 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></div> |
| 171 | <div> |
| 172 | <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></div> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 173 | </div> |
syeshin | d0bdb8e | 2005-10-27 17:44:14 +0000 | [diff] [blame] | 174 | </div></body> |
syeshin | befd53e | 2005-07-27 18:16:40 +0000 | [diff] [blame] | 175 | </html> |