include namespace declarations

Discussion in 'XML' started by maxwell@umiacs.umd.edu, Feb 15, 2008.

  1. Guest

    I am trying to figure out how to include namespace declarations that
    come from another file. As usual for me (I'm hoping readers of this
    list get different mileage, else I'm in trouble :)), while it seems
    conceptually simple, doing it has proven difficult.

    I have a bunch of files that look something like this:
    -----------------------------------
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE book PUBLIC "-//Normal Walsh//DTD XWEB V1.0 in DocBook XML
    V4.2//EN"
    "http://docbook.sourceforge.net/release/litprog/
    current/dtd/ldocbook.dtd">

    <src:fragment id="fragNaturalClasses"
    xmlns:src="http://docbook.sourceforge.net/release/
    litprog/current/dtd/ldocbook.dtd"
    xmlns:ph= "Phonology.xsd"
    >

    <Ph:NCSegment id="ncConsonantLetter">
    [more XML here...]
    -----------------------------------
    All the files contain the same set of xmlns declarations--in fact,
    there are five or six such declarations, although the example above
    only contains two of them (I kept it short for illustration). The id
    of the <src:fragment> element will be different in each file, of
    course.

    What I would like to do is to pull out the namespace declarations into
    a separate place, and include them somehow in all the individual
    files. I've tried several ways to do that, and none of them seem to
    work; or at least xsltproc complains when it tries to process the
    files (e.g. by including them in some other file). My goal is that
    each of these files should be well-formed and valid XML on its own.

    Here's what I've tried:
    1) Creating an entity definition, and "calling" it with e.g.
    '&NamespaceDeclarations;'. But it's not clear how I include the file
    containing the entity definition *before* the root element where the
    entity is first used. <xinclude...> won't work, or at least I can't
    figure out a way to make it work.
    2) Creating a file containing the namespace declarations, and
    xincluding them. But again, you can't have an <xinclude.../> element
    before the root element.
    3) Using cpp (an old C-style preprocessor) to #include the namespace
    declarations. This works, but it's just not the xml way.
    4) xlink: I can't figure out how this would work.

    Is it possible to do what I'm trying to do, namely to put the
    namespace declarations somewhere else--like in a separate file--and
    include them in each individual file's root element?

    Of course it's possible that my whole design is wrong, and that all
    the <src:fragment> elements should be in a single file, with a single
    namespace declaration at the top. But I wanted to modularize it, for
    any number of reasons.

    Mike Maxwell
    CASL/ U MD
     
    , Feb 15, 2008
    #1
    1. Advertising

  2. wrote:
    > What I would like to do is to pull out the namespace declarations into
    > a separate place, and include them somehow in all the individual
    > files.


    If you insist on DTDs, the best thing you can do is probably to lock
    down the namespace declarations as FIXED attribute falues in the DTDs.
    This will work, barely, as long as all code operating on those documents
    preserves the prefixes. But that assumption may fail the first time the
    document gets processed by a properly namespace-aware application.

    ButI really suggest you move to XML Schema. Trying to mix
    namespace-aware processing and DTDs is something of a disaster;
    namespaces assume the choice of prefix doesn't matter, but DTDs treat it
    as part of the element name and want it locked down hard. Schemas were
    designed to work with namespaces and vice versa; DTDs weren't, and the
    XML Namespaces working groups couldn't find a good way to get past that.

    > Is it possible to do what I'm trying to do, namely to put the
    > namespace declarations somewhere else--like in a separate file--and
    > include them in each individual file's root element?


    If you really must go this route... Parameter entity imported into the DTDs?

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Feb 19, 2008
    #2
    1. Advertising

  3. McSwell Guest

    On Feb 19, 5:06 pm, Joseph Kesselman <>
    wrote:
    > wrote:
    > > What I would like to do is to pull out the namespace declarations into
    > > a separate place, and include them somehow in all the individual
    > > files.

    >
    > If you insist on DTDs...


    Sorry, I must not have been clear. I *am* using XML schema, not
    DTDs. But I was really thinking of something that would be done in
    the XML data, not in the schemas. So conceptually, something like

    <src:fragment id="fragNaturalClasses"
    xmlns:src="http://docbook.sourceforge.net/release/litprog/current/dtd/
    ldocbook.dtd"
    <IncludeMyNamespaceDeclarationsHere source="file://foo.bar">
    >


    But now that I look at this, maybe I'm seeing the problem: I'm
    referencing Norm Walsh's literate programming DTD for the
    <src:fragment> element. (And in my original example, there's a
    DOCTYPE declaration immediately above this, which refers to the
    DocBook DTD.) Is that the problem? And then mixing the DocBook DTD
    with my own schemas using the namespaces?

    Mike Maxwell
    CASL/ U MD
     
    McSwell, Feb 20, 2008
    #3
    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. Replies:
    5
    Views:
    14,545
  2. Mads Orbesen Troest

    Namespace declarations appearing in output.

    Mads Orbesen Troest, Apr 19, 2004, in forum: XML
    Replies:
    0
    Views:
    463
    Mads Orbesen Troest
    Apr 19, 2004
  3. Christian Hoertnagl
    Replies:
    1
    Views:
    389
    Martin Honnen
    May 22, 2004
  4. Keith Davies
    Replies:
    2
    Views:
    347
    Keith Davies
    Aug 15, 2004
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    960
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page