DOCTYPE: How to postpone DTD location resolution at runtime

Discussion in 'XML' started by Jesse, Dec 12, 2007.

  1. Jesse

    Jesse Guest

    Hi all,

    my application reads and validate an XML file with a specific DTD. The two
    are defined in separate files (no local declaration of the DTD in the XML).

    The location of both the XML and the DTD is resolved at runtime. Indeed, due
    to various deployment issues, the location of both files cannot be
    statically defined. Even the relative path from the XML to its DTD cannot be
    ensured.

    Is there a way to parameter the DOCTYPE declaration to allow runtime setting
    of the path to the DTD ?

    For example using environment variables, with something like:
    <!DOCTYPE greeting SYSTEM "$PATH_TO_DTD/hello.dtd">

    If it exists, this is very likely to be a paser specific feature, toggled
    via org.xml.sax.XMLReader setProperty or setFeature. However, I cannot find
    anything relevant at
    http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html, nor at
    http://xerces.apache.org/xerces2-j/features.html or
    http://xerces.apache.org/xerces2-j/properties.html.

    Indeed, I am using the XERCES SAX parser.

    Thanks in advance,

    JC.
     
    Jesse, Dec 12, 2007
    #1
    1. Advertising

  2. Jesse wrote:

    > Is there a way to parameter the DOCTYPE declaration to allow runtime setting
    > of the path to the DTD ?
    >
    > For example using environment variables, with something like:
    > <!DOCTYPE greeting SYSTEM "$PATH_TO_DTD/hello.dtd">


    You could use a PUBLIC indentifier instead and resolve that in your
    application. I think for that you can set up an EntityResolver which
    returns an InputSoure:
    <URL:http://www.saxproject.org/apidoc/org/xml/sax/EntityResolver.html>




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 12, 2007
    #2
    1. Advertising

  3. In article <fjp4vt$84p$>, Jesse <> wrote:

    >Is there a way to parameter the DOCTYPE declaration to allow runtime setting
    >of the path to the DTD ?
    >
    >For example using environment variables, with something like:
    > <!DOCTYPE greeting SYSTEM "$PATH_TO_DTD/hello.dtd">


    If you can change the call to the parser you should be able to set up
    an entity resolver to map it however you want to.

    More portably, you could use a catalog (google for "xml catalogs").
    You would either use a public identifier instead of a system
    identifier, or choose some prefix for your URL that would be resolved
    by the catalog.

    For example, you could use:

    <!DOCTYPE greeting SYSTEM "http://example.com/hello.dtd">

    and have a catalog containing

    <!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.0//EN" "catalog.dtd">

    <catalog>
    <rewriteSystem systemIdStartString= "http://example.com/"
    rewritePrefix= "file:///path-to-dtd-directory/" />
    </catalog>

    which would map the DTD location to file:///path-to-dtd-directory/hello.dtd.

    Most parsers that support catalogs allow you to specify the catalog
    location with an environment variable (e.g. XML_CATALOG_FILES), so you
    could create a catalog on the fly and set the variable to point to it.

    -- Richard
    --
    :wq
     
    Richard Tobin, Dec 12, 2007
    #3
  4. Jesse

    Jesse Guest

    Thanks !

    "Martin Honnen" <> wrote in message
    news:4760194b$0$13110$-online.net...
    > Jesse wrote:
    >
    >> Is there a way to parameter the DOCTYPE declaration to allow runtime
    >> setting of the path to the DTD ?
    >>
    >> For example using environment variables, with something like:
    >> <!DOCTYPE greeting SYSTEM "$PATH_TO_DTD/hello.dtd">

    >
    > You could use a PUBLIC indentifier instead and resolve that in your
    > application. I think for that you can set up an EntityResolver which
    > returns an InputSoure:
    > <URL:http://www.saxproject.org/apidoc/org/xml/sax/EntityResolver.html>
    >
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    Jesse, Dec 13, 2007
    #4
  5. Jesse

    Jesse Guest

    Thanks !

    "Richard Tobin" <> wrote in message
    news:fjpp6i$24e$...
    > In article <fjp4vt$84p$>, Jesse <>
    > wrote:
    >
    >>Is there a way to parameter the DOCTYPE declaration to allow runtime
    >>setting
    >>of the path to the DTD ?
    >>
    >>For example using environment variables, with something like:
    >> <!DOCTYPE greeting SYSTEM "$PATH_TO_DTD/hello.dtd">

    >
    > If you can change the call to the parser you should be able to set up
    > an entity resolver to map it however you want to.
    >
    > More portably, you could use a catalog (google for "xml catalogs").
    > You would either use a public identifier instead of a system
    > identifier, or choose some prefix for your URL that would be resolved
    > by the catalog.
    >
    > For example, you could use:
    >
    > <!DOCTYPE greeting SYSTEM "http://example.com/hello.dtd">
    >
    > and have a catalog containing
    >
    > <!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.0//EN"
    > "catalog.dtd">
    >
    > <catalog>
    > <rewriteSystem systemIdStartString= "http://example.com/"
    > rewritePrefix= "file:///path-to-dtd-directory/" />
    > </catalog>
    >
    > which would map the DTD location to
    > file:///path-to-dtd-directory/hello.dtd.
    >
    > Most parsers that support catalogs allow you to specify the catalog
    > location with an environment variable (e.g. XML_CATALOG_FILES), so you
    > could create a catalog on the fly and set the variable to point to it.
    >
    > -- Richard
    > --
    > :wq
     
    Jesse, Dec 13, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Headless
    Replies:
    5
    Views:
    390
    Headless
    Sep 1, 2003
  2. Replies:
    0
    Views:
    350
  3. Frank Millman
    Replies:
    23
    Views:
    632
    Steven D'Aprano
    Jun 13, 2007
  4. Righard van Roy

    Postpone evaluation of argument

    Righard van Roy, Feb 10, 2012, in forum: Python
    Replies:
    3
    Views:
    167
    88888 Dihedral
    Feb 11, 2012
  5. Larry Lindstrom
    Replies:
    19
    Views:
    1,305
    Jonathan N. Little
    Jun 12, 2012
Loading...

Share This Page