Hi, i am doing the following in java.
I am searching through a lucene index and getting a Collection of Documents. Below is the code that i have written. Collection<org.apache.lucene.document.Document> docCollection= new ArrayList<org.apache.lucene.document.Document>(); try { Query query = new TermQuery(new Term(nameType, queryStr)); ScoreDoc[] hits = searcher.search(query, 1).scoreDocs; org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document(); for (int i = 0; i < hits.length; i++) { int docId = hits[i].doc; doc = searcher.doc(docId); docCollection.add(doc); } } catch (IOException e) { e.printStackTrace(); } return docCollection; The above method snippet is returning a collection of Documents. The next step for me is to iterate through the collection of lucene documents that i got and convert the same into XML using javax.xml.stream. The issue is that i cannot figure out how to iterate through the Collection of documents.... *Below is the code where i am facing the problem* public void write(XMLStreamWriter writer, Collection<Document> docCollection) throws XMLStreamException { writer.writeStartDocument(); writer.writeStartElement("documents"); *Iterator<Document> document = docCollection.iterator();* while (document.hasNext()) { writer.writeStartElement("document"); * for (Field field : (List<Field>) document.getFields()) {* writer.writeStartElement("field"); writer.writeAttribute("name", field.name()); writer.writeAttribute("value", field.stringValue()); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); Request you to correct the above code snippet..... How do i iterate through the Collection of Lucene docs? Please help !!!! Thanks, Altaf