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.
There are two different ways to associate XML files with DTDs or XML schemas.
<!DOCTYPE root-name PUBLIC "InvoiceId" "C:\mydtds\Invoice.dtd">
InvoiceId is the public identifier of the DTD file. It is used to associate the XML file with a DTD file (in this case, the DTD file is Invoice.dtd). If the public identifier InvoiceId corresponds to the Key of the XML Catalog entry for Invoice.dtd, then the URI of the XML Catalog entry (which contains information about the location of Invoice.dtd) is used to locate the DTD. Otherwise, the DOCTYPE's system identifier ("C:\mydtds\Invoice.dtd"), which refers directly to the file system location of the DTD, is used to locate the DTD.
<!DOCTYPE Root-name SYSTEM "MyDTD.dtd">
where MyDTD.dtd is the system identifier that corresponds to the Key of an XML Catalog entry.
If an XML file is associated with an XML schema, one or more schema location attributes are included in the XML file. The information in the schemaLocation is provided as a "hint" to the XML processor. The following examples show schemaLocation attributes:
<purchaseOrder xmlns="http://www.ibm.com" xsi:schemaLocation="http://www.ibm.com C:\myschemas\PurchaseOrder.xsd"> <shipTo country="US"> ...
<purchaseOrder xmlns="http://www.ibm.com" xsi:schemaLocation="http://www.ibm.com PO.xsd"> <shipTo country="US"> ....
In Example 1, the schemaLocation 'hint' ('C:\myschemas\PurchaseOrder.xsd') refers directly to the file system location or URI of the XML schema. In this case, the schema file will be located by the XML processor directly.
In Example 2, the schemaLocation 'hint' ('PO.xsd') refers to an XML Catalog entry. PO.xsd corresponds to the Key of the XML Catalog entry for PurchaseOrder.xsd, and the URI of the XML Catalog entry (which contains information about the location of PurchaseOrder.xsd) will be used to located the XML schema.
In both examples, http://www.ibm.com in the xsi:schemaLocation tag is a URI that identifies the namespace for the XML schema.
<purchaseOrder xmlns:="www.ibm.com" xsi:schemaLocation="http://www.ibm.com po/xsd/PurchaseOrder.xsd ">
The schemaLocation attribute points to both the Key and the actual location of the schema.
DTD or XML schema resides on a remote server
Several functions in the XML editor, such as validation and content assist, require the availability of a DTD or an XML schema. The product documentation provides usage information for cases when the DTD or XML schema resides on your local machine. However, in many cases, the DTD or XML schema can reside on a remote server, for example:
<!DOCTYPE Catalog PUBLIC "abc/Catalog" "http://xyz.abc.org/dtds/catalog.dtd">
Normally, this case poses no problem, because the DTD or XML schema can be retrieved from the remote server. However, if you are behind a firewall, and do not have a SOCKSified system, the workbench currently does not provide a way for you to specify a socks server for retrieving a DTD or XML schema. If you are unable to SOCKSify your system, the workaround for this problem is to retrieve a copy of the DTD or XML schema (using a Web browser, for example) and save that copy on your local machine. Then, you can either place a local copy in the same project as your XML file, or use the XML Catalog to associate a public identifier with the DTD's (local) location.
If you create a direct association between an XML file and an XML schema or DTD file, any time you change the location of the schema or DTD you have to track down and update all of the referencing XML files with the new location of the DTD or schema. If, however, you associate an XML file with an XML schema or DTD Key, then, when you change the location of the schema or DTD, you only have to update the XML Catalog entry, instead of each individual XML file.
For example, you have a DTD called Building.dtd, which is associated with five XML files - Office.xml, House.xml, Apartment.xml, Bank.xml, and PostOffice.xml. You move the DTD file Building.dtd to a new location. If you have a direction association between Building.dtd and all the XML files, you will have to update the <DOCTTYPE> declaration in each XML file to reflect the new location of Building.dtd. If, however, you have an XML Catalog association, and all the XML files just refer to the Key of Building.dtd, then you only have to update the URI and all the XML files will point to the new location of Building.dtd.
After you have updated an entry in the XML Catalog, you might need to refresh the XML editor view so that it uses the new information. To do this, click the Reload Dependencies toolbar button and the view will be updated using the current XML Catalog settings. You only need to refresh the XML editor view when you have an XML file open that references the XML Catalog entry that was updated.
For more information, refer to the related tasks.