You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by Ch...@swisscom.com on 2007/12/07 20:03:27 UTC

XmlUtils - getAllNamespaces problem

Hi All,

I had discussed this with Dan before, and for the cases I previously
discussed the current code was fine (providing full namespace and prefix
QNames).  However in the case of NotificationMessages and attaching WEF
with extended elements (messages in this case) it proves too
problematic.

While I can solve this for my particular case with overriding the
SimpleNotifciationProducer code and c+p a new notifcation message it is,
I think, a flaw.

Adding the following valid xml to an extended message will cause
serialization problems:

<root xmlns="">....</root>

In fact any fully valid XML node that does not provide both prefix and
namespace will cause this problem.  The problem is due to
SimpleNotificationMessage using getAllNamespaces to provide xpath
functionality.

All that is required is to recognize that if something is not prefixed
(or has the empty namespace) it should not be returned in the list:

    private static Map getAllNamespaces(Element xml, Map
namespacesByPrefix)
    {
        //
        // get the qualifying URI for this element, then recurse through

        // the sub-tree to get those of the child elements
        //
        
        QName qname = getElementQName(xml);
        String prefix = qname.getPrefix();
        String namespace = qname.getNamespaceURI();
// changed lines ...........
	  if (namespace != null && prefix != null) {
        	namespacesByPrefix.put(prefix, namespace);
	  }
        
        Element[] children = getAllElements(xml);
        
        for (int n = 0; n < children.length; ++n)
            getAllNamespaces(children[n], namespacesByPrefix);
        
        return namespacesByPrefix;
    }

This should not affect the rest of the code in any way since it is only
applying normal valid XML.

Please don't reply with "use a prefix always" as, in our case and I'm
sure in many others, I have to deal with empty namespace nodes and those
that don't directly use a prefix.  To quote from getElementQName:


	//
      // prefix is not required, but it CANNOT be null
      //
        
same in the standard for QName.

cheers,
Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org