[jdom-interest] Namespace Element.addNamespaceDeclaration(String prefix, String uri)

Constantine Plotnikov cap at novosoft.ru
Wed Apr 4 01:15:11 PDT 2001


I want to choose prefix for additional namespace declarartion.

<XMI xmins:UML="....">
    <UML:Class xmi.id=111 name="ddd1"/>
    <UML:Class xmi.id=112 name="ddd2"/>
    <UML:Class xmi.id=113 name="ddd3"/>
    <UML:Class xmi.id=114 name="ddd4"/>
    <UML:Class xmi.id=115 name="ddd5"/>

But currently I could choose prefix for additional
namespace only using depricated API. I think that
this application is critical if it is needed to save
slightly modified copy of xml where namspace prefixes
are used in attibute values (parsing and updating xpath
expresion could be out of scope for such programs).
Possible implementation is following, but that implementation
is incorrect because null could be returned from it. An
implementation should force prefix redefinition for sub
elements and always succeed. This operation could
be good complimentary operation to getNamespace(prefix)
on Element.

class Element
     * <p>
     *  This will add a namespace declarations to this element.
     *    This should <i>not</i> be used to add the declaration for
     *    this element itself; that should be assigned in the construction
     *    of the element. Instead, this is for adding namespace
     *    declarations on the element not relating directly to itself.
     * </p>
     * @param prefix prefix of <code>Namespace</code> to add.
     * @param uri uri of <code>Namespace</code> to add.
     * @return created namespace, this method will never return null
    public Namespace addNamespaceDeclaration(String prefix, String uri) {
        // implementation is incorrect, because next line
        // could return null and this is unacceptable
        Namespace additionalNamespace = Namespace.getNamespace(prefix, uri);
        return additionalNamespace;


More information about the jdom-interest mailing list