Glen Daniels wrote:
Is there a utility function to map string->qname in the context of an Element?


If there isn't yet, we should add one (Axis 1's MessageElement has this, and it's generally hugely useful).


I've done it, just dont know


Thanks Steve!

1. where to put it


Shouldn't it be OMElement.resolve (String)? Eran?


OMElement.getQNameFromString(String) or
OMElement.resolveQName(String)

either works for me.

2. what the failure policy should be. Return null vs throw exception?


Exception seems more right to me.


Really? I was thinking null would be better to avoid a ton of try/catch blocks.

QName foo = element.resolveQName("foo:bar");
if (foo != null) {
  // do something useful
}

here you go.

    /**
* Turn a name:value qname string into a propert QName, evaluating it in the OMElement context
     *
     * @param text
     * @return null for no such namespace
     */
    public QName resolveQName(String text) {
        int colon = text.indexOf(':');
        if (colon < 0) {
            //things in the local space are local.
//TODO: is this right? Should they be in the namespace of the current element?
            return new QName(text);
        }
        String prefix = text.substring(0, colon);
        String local = text.substring(colon + 1);
        //TODO: what if local=="" ?

        OMNamespace namespace = findNamespace(null, prefix);
        if (namespace == null) {
            return null;
        }
        return new QName(namespace.getName(), local, prefix);
    }

What we have to do is the policy for the following qnames.

":localonly"          //error?
"prefixonly:"         //error?
":"                           //should be caught by previous logic
"nocolon"             //assume ns="" or ns=element.getNamespace()

Someone who understands xmlns needs to tell me thr right answers there

Reply via email to