Bernd Fondermann wrote:
> Niklas Gustavsson wrote:
>> Hi
>>
>> I'm looking into how to work with namespaces with XMLElement, and is
>> getting confused :-)
> 
> Yes, I'm too.
> In the beginning, I thought this is like XML. But it isn't quite like
> it.

Clarification: XMPP of course doesn't bend the XML spec. But I've never
seen prefixes actually used except for <stream:stream>. I think some
clients don't go that far in terms of parsing XML, so I don't know where
we should be heading here.

> Prefixes only are important when starting streams (and maybe later
> when you have conflicting XML payload in a stanza.
> 
> Here an excerpt from 12.2.3. Extended Namespaces in
>   http://tools.ietf.org/html/draft-saintandre-rfc3920bis-09
> 
>    An implementation SHOULD NOT generate namespace prefixes for elements
>    qualified by content (as opposed to stream) namespaces other than the
>    default namespace.  However, if included, the namespace declarations
>    for those prefixes MUST be included on the stanza root or a child
>    thereof, not at the level of the stream element (this helps to ensure
>    that any such namespace declaration is routed and delivered with the
>    stanza, instead of assumed from the stream).
> <<<<
> 
> This confused me a lot.
> 
> Also, admittedly, the namespace implementation is half-baked.
> 
>> * XMLElement.getNamespace() seems to return the namespace prefix, if
>> any. Should probably be renamed to getNamespacePrefix()?
> 
> +1
> 
>> Also, the
>> following test case breaks badly:
>>         List<XMLParticle> particles = new ArrayList<XMLParticle>();
>>         particles.add(new XMLParticle("<p:balanced xmlns:p=\"urn:foo\"/>"));
>>         XMLElement xmlElement = (XMLElement)
>> xmlRawToFragmentConverter.convert(particles);
>>         assertEquals("p", xmlElement.getNamespace());
>>
>> Will fail since getNamespace() will return "balanced".

I agree, this is bad.

>> * Getting the real namespace (the URI) for an element seems to be done
>> by calling XMLElementVerifier.getUniqueXMLNSValue() which looks it up
>> from the attribute collection. First, wouldn't make more sense to have
>> this as a getNamespaceURI() on XMLElement? Second, this method seems a
>> bit buggy, for example, the following test case:
>>         List<XMLParticle> particles = new ArrayList<XMLParticle>();
>>         particles.add(new XMLParticle("<p:balanced xmlns=\"urn:bar\"
>> xmlns:p=\"urn:foo\"/>"));
>>         XMLElement xmlElement = (XMLElement)
>> xmlRawToFragmentConverter.convert(particles);
>>
>>         assertEquals("urn:foo", 
>> xmlElement.getVerifier().getUniqueXMLNSValue());
>>
>> Will fail since it returns null.

Uhh, this is bad, too. Why the heck did you bring this up? ;-)
I remember now that this is not the nicest corner of Vysper.

Bernd

Reply via email to