rdftemplate

Library for generating XML documents from RDF data using templates
git clone https://code.djc.id.au/git/rdftemplate/
commit bfc2f6cf953dfa980579b15c1199effdac866254
parent dcd5d96bb2d6c88b3a7636f5a2a3eab9fa1693b7
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sun,  2 May 2010 13:35:57 +1000

useful utility method

Diffstat:
Msrc/main/java/au/com/miskinhill/rdftemplate/XMLStream.java | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/src/main/java/au/com/miskinhill/rdftemplate/XMLStream.java b/src/main/java/au/com/miskinhill/rdftemplate/XMLStream.java
@@ -1,13 +1,30 @@
 package au.com.miskinhill.rdftemplate;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.events.XMLEvent;
 
 public class XMLStream implements Iterable<XMLEvent> {
     
+    public static XMLStream collect(Iterator<XMLEvent> it) {
+        List<XMLEvent> events = new ArrayList<XMLEvent>();
+        while (it.hasNext()) {
+            XMLEvent event = it.next();
+            switch (event.getEventType()) {
+                case XMLStreamConstants.START_DOCUMENT:
+                case XMLStreamConstants.END_DOCUMENT:
+                    break; // discard
+                default:
+                    events.add(event);
+            }
+        }
+        return new XMLStream(events);
+    }
+    
     private final List<XMLEvent> events;
     
     public XMLStream(XMLEvent... events) {