External DTD & namespaces
james anderson
James.Anderson at mecomnet.de
Wed Dec 23 02:17:19 GMT 1998
David Brownell wrote:
>
> Andy Malakov wrote:
> >
> > I want to use namespace prefixes in element declarations of the
> > external/internal DTDs.
> > ...
> > Where I should put "myns" namespace declaration?
>
> <!ATTLIST myns:point
> xmlns:myns CDATA #FIXED
> "http://www.ptc.com/xml/something/goes/here"
> >
>
> Keep in mind that if you put this in some external parameter
> entity (e.g. the unnamed one in <!DOCTYPE foo SYSTEM "xyz.dtd">
> some nonvalidating parsers will give you a hard time.
within the terms of the proposed recommendation even a conforming validating
parser would be hard pressed to do better. a conforming means is yet to be
specified whereby a parser can establish the identity of identifiers in either
the external or the internal dtd.
> Where namespaces and DTDs really clash is when you might want
> to change the prefix ("myns") associated with some URI.
which clash is the source of the problem.
this is not to say that it is not possible to specify this identity. the
problem is just strictly in terms of the pr: it omits the necessary binding
form and the rules for scoping within the dtd. as previously noted, one can
wait for the "future work on XML schemas" which will be able to take advantage
of attribute-based prefix bindings. a second option is to depend on the parser
of ones choice to
a) expose the name-qualification mechanism (prefix binding and universal name
construction), and
b) report processing instructions.
and implement the binding mechanism onesself.
[a side-point re (a) and a previous response on the related thread: "Re: DOM
Level 1 and namespaces"
i would find an interface of the following form much more useful
interface NamespaceScoped extends Node {
UniversalName Node.getNodeName();
}
interface UniversalName extends *?* { // sorry, i don't know your domains
// it's likely a concrete class,
rather than
// just an interface, but i make no
claims about
// where it fits among your DOM classes
String getLocalName ();
String getNamespace ();
}
]
if these prerequisites are satisfied, then both unambiguous name qualification
and, as a consequence, validation are possible in the presence of otherwise
ambiguous local-name-parts and or prefixes.
to wit:
-----------------------------
? (in-package "XML-PARSER")
#<Package "XML-PARSER">
;; read a document, here with an internal subset only, but that's not significant
;; note the ambiguous local parts and prefixes
? (defParameter *test-document*
(read-xml-stream
(make-string-input-stream
"<?xml version='1.0' standalone='yes'?>
<!DOCTYPE named [
<?namespace xmlns:='ns.1' ?>
<!ELEMENT repeated (a , b) >
<!ELEMENT a EMPTY >
<!ELEMENT b EMPTY >
<?namespace xmlns:='ns.2' ?>
<!ELEMENT repeated (a , b) >
<!ELEMENT a EMPTY >
<!ELEMENT b EMPTY >
<?namespace xmlns:='ns.3' xmlns:one='ns.1' xmlns:two='ns.2' ?>
<!ELEMENT named (one:repeated, two:repeated) >
]>
<named xmlns:='ns.3'>
<repeated xmlns:='ns.1'><a/><b/></repeated>
<repeated xmlns:='ns.2'><a/><b/></repeated>
</named>
")))
*TEST-DOCUMENT*
;; in spite of the "ambiguity" validation is possibly.
? (document.valid? *test-document*)
T
;; now, just to demonstrate the "identity" of the names, we "break" the document.
? (defParameter *test-element* (document.element *test-document*))
*TEST-ELEMENT*
? (first (element.content *test-element*))
#<ELEMENT XMLNS.4::|repeated|>
? (element.content (first (element.content *test-element*)))
(#<ELEMENT XMLNS.4::\a> #<ELEMENT XMLNS.4::\b>)
? (second (element.content *test-element*))
#<ELEMENT XMLNS.5::|repeated|>
? (element.content (second (element.content *test-element*)))
(#<ELEMENT XMLNS.5::\a> #<ELEMENT XMLNS.5::\b>)
? (rotatef (first (element.content (first (element.content *test-element*))))
(first (element.content (second (element.content *test-element*)))))
NIL
;; the root element now looks like this. note the additional (internal) prefix bindings
;; which appear as a consequence of the indefinite extent of the respective URI
? (pprint *test-element*)
<named xmlns='ns.3'>
<repeated xmlns='ns.1'>
<XMLNS.5:a XMLNS.5=ns.2/>
<b/>
</repeated>
<repeated xmlns='ns.2'>
<XMLNS.4:a XMLNS.4=ns.1/>
<b/>
</repeated>
</named>
#<ELEMENT XMLNS.6::|named|>
? (reset-element.valid? *test-element*)
NIL
;; which resulting element is, of course, no longer valid:
;; it fails to conform to the model at the point where a ns.2:a element was
found where
;; a ns.1:a element was expected...
? (document.valid? *test-document*)
NIL
(#<ELEMENT XMLNS.5::\a> #<ELEMENT XMLNS.4::\b>)
#<ELEMENT-MODEL a>
?
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list