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

Constantine Plotnikov cap at novosoft.ru
Tue Apr 3 07:49:33 PDT 2001


Hi!

I want to choose prefix for additional namespace declarartion.

<XMI xmins:UML="....">
  <XMI.constent>
    <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"/>
  </XMI.constent>
</XMI>

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.

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);
        addNamespaceDeclaration(additionalNamespace);
        return additionalNamespace;
    }
}
Constantine




More information about the jdom-interest mailing list