Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > include namespace declarations

Reply
Thread Tools

include namespace declarations

 
 
maxwell@umiacs.umd.edu
Guest
Posts: n/a
 
      02-15-2008
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"
xmlnsh= "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
 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-19-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
McSwell
Guest
Posts: n/a
 
      02-20-2008
On Feb 19, 5:06 pm, Joseph Kesselman <(E-Mail Removed)>
wrote:
> (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
Using DOM Library to Add Namespace Declarations to Root Element Tag eric.jester@gmail.com Java 5 04-20-2005 10:30 PM
dropping namespace declarations in output Keith Davies XML 2 08-15-2004 06:20 PM
control over location of namespace declarations in XSLT Christian Hoertnagl XML 1 05-22-2004 10:32 AM
Namespace declarations appearing in output. Mads Orbesen Troest XML 0 04-19-2004 05:53 PM



Advertisments