Hi All, Seems like the trick with the sample code that Chinthaka and I posted is in the DocumentBuilderFactory of the default DOM impl. If we make the DocumentBuilderFactory instance namespace aware we have a behaviour similar to OM default behaviour.
DocumentBuilderFactory.setNamespaceAware(true); And if the DocumentBuilderFactory instance is not namspace aware one then getLocalName() will return null all the time... Please note that this is the behaviour of the default DOM impl... :-) Ok... now since we can safely assume OM is namespace aware ... we can chage the getLocalName() in DOOM ElementImpl to comply with it. Problem solved :-) Thanks, Ruchith On 12/23/05, Eran Chinthaka <[EMAIL PROTECTED]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hmm, interesting discussion. > > Let me add something too. > I wrote a sample code using DOM and it seems the current DomImpl is > returning null for any element.getLocalName() call, irrespective of > whether it is qualified or not. This is bit of strange to me. > > I created a SOAPEnvelope and and called > documentElement.getLocalName(), its returning null. But when I call > getTagName(), it returns "soapenv:Envelope". So there is a problem in > the current DOM impl too. > > BTW, looking at Ruchith's proposals, I don't like the options #1 as > there he has tried to make the impl neutral code independant code, > non-neutral by putting instance of checking. (Please see [1] for the > code.) > > Anyway, I don't think those options are needed if Sanjiva's points are > accepted :-) > > - -- Chinthaka > > > [1] : http://www.rafb.net/paste/results/IGuT5M12.html > > > > > Sanjiva Weerawarana wrote: > > > On Thu, 2005-12-22 at 16:50 +0600, Ruchith Fernando wrote: > > > >> Hi Azeez, > >> > >> This is a known issue in serializing *unqualified* xml elements. > > > > > > First of all, IIRC the test envelope is wrong: children of > > <soap:Body> *must* be qualified. > > > > However, that does not excuse the NPE behavior :). > > > >> org.apache.axis2.om.impl.llom.OMSerializerUtil was > originally > >> written to only work with LLOM OM implementation. And it uses > >> getLocalName() of OMElement to get the local part of a qualified > >> element OR the 'tag name' of a qualified element. > > > > > > OK. (You meant "unqualified" in the last bit there I believe.) > > > >> And now DOOM uses it to serialize DOOM elements. But according to > >> the DOM APIs[1] (Proof: [2]) the when getLocalName() is called > >> on an unqualified element it will be null. And DOOM does this > >> properly to comply with DOM interfaces. > > > > > > I just looked thru the DOM L2 spec [1] and AFAICT the behavior is > > not clearly defined. In particular, it says: > > > > "localName of type DOMString, readonly, introduced in DOM Level 2 > > Returns the local part of the qualified name of this node. For > > nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and > > nodes created with a DOM Level 1 method, such as createElement from > > the Document interface, this is always null". > > > > Note that it does not say what happens if the name was not > > qualified at all. There's further discussion of namespace issues in > > [2] but that does not clarify it either. So, at least to me, it > > appears that you're noticing the behavior of the default DOM impl > > rather than spec compliance. > > > >> Therefore we have two options to solve this problem: 1.) Modify > >> OMSerializerUtil to check for whether the element being > >> serialized is a DOM element by checking instanceof > >> org.w3c.Element and calling getTagName if the element is not > >> namespace qualified. > >> > >> 2.) Add another method to OMElement interface : public String > >> getTagName() where we can use it in the case when we serialize an > >> unqualified element (either LLOM or DOOM). > >> > >> What do you think? > > > > > > If the spec indeed does not specify a given behavior, my preference > > would be to change getLocalName() to return the name if the > > OMElement is unqualified. > > > > Sanjiva. [1] > > > http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html > > [2] > > > http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#Namespaces-Considerations > > > > > > > > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2 (MingW32) > > iD8DBQFDq1zIjON2uBzUhh8RAuvTAKCWR0nV2GcrS7x/tnuojAS3J293HQCfScSZ > cMrz4uXHGPS+gGM8xXA2NK8= > =MyEi > -----END PGP SIGNATURE----- > > -- Ruchith
