Hi Mukul, I was going to make a comment to that effect. Xerces itself doesn't have any APIs which consume a NamespaceContext from a user, so isn't clear why it should expose an implementation of this interface to users.
In my opinion this kind of utility really should be part of the JAXP API. There was talk of adding it to JAXP 1.5 [1] at some point though I'm not sure where that's at these days. May also make more sense as part of a commons library of XML utilities if you'd like to explore that. There was some talk about creating one [2] last year. Thanks. [1] http://norman.walsh.name/2006/03/28/jaxpNamespaceContext [2] http://markmail.org/thread/i4mzckmqzy2gdwsc Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [email protected] E-mail: [email protected] Mukul Gandhi <[email protected]> wrote on 01/14/2010 10:55:28 PM: > Please pardon me. > > But I am really not sure, if this implementation should belong to Xerces. > > Implementation of JAXP XPath API is typically implemented by a > XSLT/XPath engine like Xalan. > > Xalan-J already provides guidance for this at, > http://xml.apache.org/xalan-j/xpath_apis.html#namespacecontext. > > Please ignore this proposal, if it's incorrect. > > On Thu, Jan 14, 2010 at 6:47 PM, Mukul Gandhi <[email protected]> wrote: > > Hi all, > > Currently I cannot see in Xerces-J codebase, a Xerces > > implementation of the JAXP XPath interface, > > javax.xml.namespace.NamespaceContext. > > > > It seems user's have to write their own implementation of this > > interface, when they need this functionality. > > > > I propose an implementation of this interface in Xerces-J, along the > > following lines: > > > > import javax.xml.namespace.NamespaceContext; > > import java.util.Iterator; > > import java.util.Map; > > import java.util.HashMap; > > import java.util.Set; > > import java.util.ArrayList; > > import java.util.List; > > > > public class NamespaceContextImpl implements NamespaceContext { > > private Map namespaceStore; > > > > public NamespaceContextImpl() { > > namespaceStore = new HashMap(); > > } > > > > public void setNamespace(String prefix, String namespaceURI) { > > namespaceStore.put(prefix, namespaceURI); > > } > > > > public String getNamespaceURI(String prefix) { > > return (String) namespaceStore.get(prefix); > > } > > > > public String getPrefix(java.lang.String namespaceURI) { > > Set keys = namespaceStore.keySet(); > > > > for (Iterator iterator = keys.iterator(); iterator.hasNext();) { > > String prefix = (String) iterator.next(); > > String uri = (String) namespaceStore.get(prefix); > > if (uri.equals(namespaceURI)) { > > return prefix; > > } > > } > > > > return null; > > } > > > > public Iterator getPrefixes(String namespaceURI) { > > List prefixes = new ArrayList(); > > Set keys = namespaceStore.keySet(); > > > > for (Iterator iterator = keys.iterator(); iterator.hasNext();) { > > String prefix = (String) iterator.next(); > > String uri = (String) namespaceStore.get(prefix); > > if (uri.equals(namespaceURI)) { > > prefixes.add(prefix); > > } > > } > > > > return prefixes.iterator(); > > } > > > > } > > > > An implementation like above is needed, when we have to do > > namespace-aware XPath evaluations with JAXP XPath API. for e.g, > > something like following needs to be done by the user: > > > > XPathFactory xFactory = XPathFactory.newInstance(); > > XPath xPath = xFactory.newXPath(); > > NamespaceContextImpl namespaceContext = new NamespaceContextImpl(); > > namespaceContext.setNamespace(prefix,uri); > > xPath.setNamespaceContext(namespaceContext); > > XPathExpression xpression = xPath.compile("xpath-string using namespaces"); > > > > The class, NamespaceContextImpl might be stored in Xerces-J package, > > org.apache.xerces.jaxp > > > > Any thoughts about this, please? > > > > I have an implementation for this ready with me (which is just only > > the above Java code). This could be committed to Xerces-J code-base, > > if we agree on this. > > > > -- > Regards, > Mukul Gandhi > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected]
