D
D McGilvray
Hi, I've been researching for a while to understand namespaces to find a
solution to my problem. I now have a solution which works in my test
examples, but before I roll it out through my software, I was hoping
someone might tell me if I've fallen into any traps.
Particularly, I would like to know what type of parser I am restricted
to using - will it work for any fully conforming validating parser? Or
are there certain levels of conformity to the specification?
I want to include another XML file within my own. The other DTD has no
support for namespaces. I want to avoid naming conflicts, so I need
namespaces. However, I also require validation because I'll be using
ID/IDREF references extensively.
Here is an example xml file. inc represents the included structure. It
and it's children are not bound to any namespaces. The rest of the
elements are part of my own structure, and belong to the namespace ns.
<ns:doc xmlns:ns="http://dougie/test/">
<ns:a/>
<inc/>
</ns:doc>
This is the rather complex DTD for the included structure contained in
'inc.dtd':
<!ELEMENT inc ANY >
Below is the DTD for my document, which contains inc. The other DTD is
included, which defines its structure. The parameter entity nsp defines
the prefix for the namespace so that it can be overridden. However, when
this is entity is expanded, it is surrounded by white space unless it is
expanded within another parameter entity. So any time I want to use the
prefix with a tagname or attribute I have to combine the text within
another param entity. Hence, I have to create the doc entity and
substitute that for the element tag name (rather than writing %nsp;:doc
straight into the ELEMENT definition). And the same for 'a' and the
namespace declaration within the doc element.
<!-- Include other DTD -->
<!ENTITY % incdtd SYSTEM 'inc.dtd' > %incdtd;
<!-- This defines the prefix for the namespace -->
<!ENTITY % nsp 'ns' >
<!-- This combines prefix with namespace attribute name -->
<!ENTITY % nspdec 'xmlns:%nsp;' >
<!-- This combines the prefix with the tagname -->
<!ENTITY % doc '%nsp;:doc'>
<!ELEMENT %doc; ( ns:a , inc ) >
<!ATTLIST %doc;
%nspdec; CDATA #REQUIRED >
<!ENTITY % a '%nsp;:a'>
<!ELEMENT %a; ANY >
Specifying my namespace prefix in the entity nsp means that the
namespace prefix for my document can be overridden in another DTD like so:
<!ENTITY % nsp 'ns' >
<!ENTITY % otherdtd SYSTEM 'test.dtd' > %otherdtd;
Does this all look kosher? It works in my test example, but I don't have
enough experience to say that this complexity is worthwhile.
Many thanks for looking,
Dougie
solution to my problem. I now have a solution which works in my test
examples, but before I roll it out through my software, I was hoping
someone might tell me if I've fallen into any traps.
Particularly, I would like to know what type of parser I am restricted
to using - will it work for any fully conforming validating parser? Or
are there certain levels of conformity to the specification?
I want to include another XML file within my own. The other DTD has no
support for namespaces. I want to avoid naming conflicts, so I need
namespaces. However, I also require validation because I'll be using
ID/IDREF references extensively.
Here is an example xml file. inc represents the included structure. It
and it's children are not bound to any namespaces. The rest of the
elements are part of my own structure, and belong to the namespace ns.
<ns:doc xmlns:ns="http://dougie/test/">
<ns:a/>
<inc/>
</ns:doc>
This is the rather complex DTD for the included structure contained in
'inc.dtd':
<!ELEMENT inc ANY >
Below is the DTD for my document, which contains inc. The other DTD is
included, which defines its structure. The parameter entity nsp defines
the prefix for the namespace so that it can be overridden. However, when
this is entity is expanded, it is surrounded by white space unless it is
expanded within another parameter entity. So any time I want to use the
prefix with a tagname or attribute I have to combine the text within
another param entity. Hence, I have to create the doc entity and
substitute that for the element tag name (rather than writing %nsp;:doc
straight into the ELEMENT definition). And the same for 'a' and the
namespace declaration within the doc element.
<!-- Include other DTD -->
<!ENTITY % incdtd SYSTEM 'inc.dtd' > %incdtd;
<!-- This defines the prefix for the namespace -->
<!ENTITY % nsp 'ns' >
<!-- This combines prefix with namespace attribute name -->
<!ENTITY % nspdec 'xmlns:%nsp;' >
<!-- This combines the prefix with the tagname -->
<!ENTITY % doc '%nsp;:doc'>
<!ELEMENT %doc; ( ns:a , inc ) >
<!ATTLIST %doc;
%nspdec; CDATA #REQUIRED >
<!ENTITY % a '%nsp;:a'>
<!ELEMENT %a; ANY >
Specifying my namespace prefix in the entity nsp means that the
namespace prefix for my document can be overridden in another DTD like so:
<!ENTITY % nsp 'ns' >
<!ENTITY % otherdtd SYSTEM 'test.dtd' > %otherdtd;
Does this all look kosher? It works in my test example, but I don't have
enough experience to say that this complexity is worthwhile.
Many thanks for looking,
Dougie