XBEL file of links generated from Akara content
RSS feed

Style

(Cookies required)
Powered by 4Suite

4Suite supports OASIS TR9401 Catalogs and XML Catalogs in text and XML form, as long as you have PyExpat installed (most systems do).

TR9401 and XML Catalogs are used to map public IDs to URIs. They are most commonly used to map a DTD entity's public ID to the URI of a local file, so that instead of fetching DTDs that live on remote web sites, parsers can have the option of using local files.

For example, an XML document might contain

<!DOCTYPE foo
  PUBLIC "-//WIDGETSINC//DTD For foo-Type Documents//EN"
  "http://widgetsinc.com.net/dtds/foo.dtd">

The system ID here (the widgetsinc.com.net URL) points to a fallback URI to use if the parser's resolver can't find a better URI by looking up the public ID (that first quoted string following PUBLIC) in a catalog.

Take the following XML catalog, saved as xcatalog.xml

<!DOCTYPE catalog
  PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
         "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
         prefer="public">

  <public publicId="-//4Suite//Sample entity 1 V1.0//EN"
          uri="file:ent1.xml"/>

</catalog>

A quick note here: The use of "file:ent1.xml" is somewhat sloppy and prone to misinterpretation. You really should use a URI like like "file:///full/path/to/ent1.xml". Use forward slashes in the path, even on Windows systems.

The following is the ent1.xml it references:

<?xml version='1.0' encoding='utf-8'?>
<foo/>

The following sample code demonstrates using this catalog and resource

SRC = """\
<?xml version='1.0'?>
<!DOCTYPE x [
  <!ENTITY inc PUBLIC "-//4Suite//Sample entity 1 V1.0//EN" "http://bogus.com/include1.xml">
]>
<x>&inc;</x>"""

# a dummy base URI for resolving relative URI refs in SRC.
# There are no relative URI refs to resolve in this case,
# but we still want to satisfy the InputSource API
SRC_URI = "file:///test.xml"

from Ft.Lib import Uri
from Ft.Xml.Catalog import Catalog
from Ft.Xml.Domlette import Print
from Ft.Xml.InputSource import InputSourceFactory

# set up the catalog
CATALOG_FILE = 'xcatalog.xml'
cat_file_uri = Uri.OsPathToUri(CATALOG_FILE, attemptAbsolute=1)
cat = Catalog(cat_file_uri)

#Use it
factory = InputSourceFactory(catalog=cat)
factory.fromString(SRC, SRC_URI)
doc = reader.parse(isrc)
Print(doc)

The output is:

<?xml version="1.0" encoding="utf-8"?>
<x>
<foo/>
</x>

For somewhat outdated discussion see the threads containing:


Comments

Re: XML Catalogs   Respond to this comment
 
By luis miguel on 2003-11-29

There is no Catalog module in Ft.Xml now :-(

>>> from Ft.Xml.Catalog import Catalog

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in -toplevel-
    from Ft.Xml.Catalog import Catalog
ImportError: cannot import name Catalog

>>> Ft.Xml.__version__
'1.0b1'