include namespace declarations

M

maxwell

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
 
J

Joseph Kesselman

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?
 
M

McSwell

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"

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top