You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by James Bates <ja...@amplexor.com> on 2002/10/23 14:35:51 UTC

The return of SAX namespaces...

After yesterday's discussion, I have gone ahead with my second proposition.

Here is a recap:

* when using XMLResource.setContentAsSAX(), you can submit SAX produced
according any of the three valid combinations of features, as documented on 
http://sax.sourceforge.net/?selected=namespaces.

* when using XMLResource.getContentAsSAX(), you can set the two ns-related
features as you like (see how below) to determine what kind of SAX you would 
like. By default (i.e. if you don't set any features yourself), both options 
are on, meaning your SAX will be reported as indicated in the second line of 
the table on the SAX namespaces page. (both prefixMappings, and namespace 
"attributes").

mini-HOWTO:
===========
To set features, you need to run methods on XMLResource. As XMLResource itself
comes from XML:DB, and the XML:DB folks seem all to be sleeping, I have had to 
add the methods to Xindice's implementation. This means you must set features 
as follows:

import org.xmldb.api.base.Collection;
import org.xmldb.api.modules.XMLResource;
import org.xml.sax.ContentHandler;

/* Xindice client-side implementation of XMLResource */
import org.apache.xindice.client.xmldb.resources.XMLResourceImpl;

Collection col = ...;

XMLResource r = (XMLResource) col.getResource("mynsfile.xml");

((XMLResourceImpl) r).setSaxFeature(
			"http://xml.org/sax/features/namespaces",true);
((XMLResourceImpl) r).setSaxFeature(
			"http://xml.org/sax/features/namespaces-features",false);

ContentHandler myHandler = ...;

/*
 * Now myHandler will receive SAX according to the two features specified
 * above.
 */
r.getContentAsSAX(myHandler);