String encoding = collection.properties.getProperty(OutputKeys.ENCODING, "UTF-8"); OutputFormat format = new OutputFormat("xml", encoding, false);
SAXSerializer handler = SAXSerializerPool.getInstance().borrowSAXSerializer(); handler.setOutputProperties(outputProperties);
	public Resource getMembersAsResource() throws XMLDBException {		String encoding = collection.properties.getProperty(OutputKeys.ENCODING, "UTF-8");		OutputFormat format = new OutputFormat("xml", encoding, false);		StringWriter writer = new StringWriter();		XMLSerializer handler = new XMLSerializer(writer, format);		DBBroker broker = null;		try {			broker = brokerPool.get(user);			// configure the serializer			Serializer serializer = broker.getSerializer();			serializer.reset();			collection.properties.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");			serializer.setProperties(collection.properties);			serializer.setUser(user);			serializer.setContentHandler(handler);			//	serialize results			handler.startDocument();			handler.startPrefixMapping("exist", Serializer.EXIST_NS);			AttributesImpl attribs = new AttributesImpl();			attribs.addAttribute(				"",				"hitCount",				"hitCount",				"CDATA",				Integer.toString(resources.size()));			handler.startElement(						Serializer.EXIST_NS,						"result",						"exist:result",						attribs);			Object current;			char[] value;			for(Iterator i = resources.iterator(); i.hasNext(); ) {				current = (Object)i.next();				if(current instanceof NodeProxy)					serializer.toSAX((NodeProxy)current);				else {					value = current.toString().toCharArray();					handler.characters(value, 0, value.length);				}			}			handler.endElement(Serializer.EXIST_NS, "result", "exist:result");			handler.endPrefixMapping("exist");			handler.endDocument();		} catch (EXistException e) {			throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, "serialization error", e);		} catch (SAXException e) {			throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, "serialization error", e);		} finally {			brokerPool.release(broker);		}		Resource res = new LocalXMLResource(user, brokerPool, collection, "", -1);		res.setContent(writer.toString());		return res;	}