axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksander Slominski <as...@cs.indiana.edu>
Subject [Axis2] namespaces, prefixes, and element context [Re: [Axis2] Proposal for adding a method in OMElement API.
Date Sun, 22 May 2005 18:23:04 GMT
Paul R Brown wrote:

>
>
>>> [Eran] Well, I accept the proposal but not the method signature. 
>>> Uniqueness of a
>>> namespace comes from the URI, but not from the prefix. A URI can 
>>> contain
>>> more than one prefix.
>>
>> [jayachadra[ I think it's the otherway round. A URI can have multiple 
>> prefixes, but
>> a prefix has associated with it just one URI. So supposing the map
>> looks like
>> prefix1 - http://commonurl.org/
>> prefix2 - http://commonurl.org/
>> prefix3 - http://commonurl.org/
>>
>> Uniqueness here comes with prefix.
>
>
> FWIW, there is no uniqueness either way, really. A prefix represents a 
> single URI, if any, in a given context, but the binding in a nested 
> context may shadow one in a larger context.
>
> <foo:bar xmlns:foo="qux:fneh">
> <foo:baz xmlns:foo="baz:snee" att="foo:gazoom" />
> </foo:bar>
>
> The fact that there is another binding hiding behind the foo prefix is 
> not insignificant if the foo on the foo:baz element is deleted. This 
> is why you can't use just a HashMap for namespaces at an element.

i agree - that is why XML parser and OM design must maintain context 
(really a position in a stack) for any element with list of current 
namespaces

here is what worked very well for my OM - i think it is both simple and 
easy to use:

/**
* Return iteraotr for all namespaces in current element only.
* NOTE: if there is no namespaces
* then empty iterator is returned (null is never returned)
*/
public Iterator namespaces();

/**
* Return true if element has namespace declarations.
*/
public boolean hasNamespaceDeclarations();

/**
* Find namespace (will have non empty prefix or empty prefix for default NS)
* corresponding to namespace prefix
* checking first current element and if not found continue in parent (if 
element has parent)
* and so on.
*/
public XmlNamespace lookupNamespaceByPrefix(String namespacePrefix);

/**
* Find namespace (will have non empty prefix) corresponding to namespace 
name
* checking first current elemen and if not found continue in parent (if 
element has parent).
* and so on.
*/
public XmlNamespace lookupNamespaceByName(String namespaceName);


/**
* Create new namespace with prefix and namespace name
* (both MUST NOT be null or exception is throws)
* and add it to current element.
*/
public XmlNamespace declareNamespace(String prefix, String 
namespaceName) throws XmlBuilderException;

/**
* Add namespace to current element (if namespace is null then exception 
is thrown)
*/
public XmlNamespace declareNamespace(XmlNamespace namespace) throws 
XmlBuilderException;

/**
* This is just a hint to OM to allow optimize to storeage for given 
numvber of namespaces.
* OM implemenentation may ignore it...
*/
public void ensureNamespaceDeclarationsCapacity(int minCapacity) throws 
XmlBuilderException;

/**
* Create new namespace with null prefix.
* If namespace name is null then throw exception.
*/
public XmlNamespace newNamespace(String namespaceName) throws 
XmlBuilderException;

/**
* Create new namespace with prefix and namespace name (both MUST NOT be 
null or exception is throws).
*/
public XmlNamespace newNamespace(String prefix, String namespaceName) 
throws XmlBuilderException;

/**
* Remove all namespace declarations from current element.
*/
public void removeAllNamespaceDeclarations() throws XmlBuilderException;


as you can see i have only remove all namespaces method - and even that 
it seems was never used (i would have ti just for completeness - if 
namespace needs to be removed it is very rare and i would expect to 
involve putting whole set of new namespaces - much more efficient and 
simpler is to do it in one sweep IMHO ...)

HTH,

alek

BTW: i have never needed to lookup attributes by namespace name or 
prefix ...

-- 
The best way to predict the future is to invent it - Alan Kay


Mime
View raw message