Index: TXM/trunk/bundles/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.java
===================================================================
--- TXM/trunk/bundles/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.java	(revision 4015)
+++ TXM/trunk/bundles/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.java	(revision 4016)
@@ -26,18 +26,22 @@
 	boolean debug = false;
 	
 	public StaxStackWriter(File file) throws FileNotFoundException, XMLStreamException {
+		
 		this(new BufferedOutputStream(new FileOutputStream(file)));
 	}
 	
 	public StaxStackWriter(File file, String encoding) throws FileNotFoundException, XMLStreamException {
+		
 		this(new BufferedOutputStream(new FileOutputStream(file)), encoding);
 	}
 	
 	public StaxStackWriter(OutputStream output) throws XMLStreamException {
+		
 		this(output, "UTF-8");//create a new file
 	}
 	
 	public StaxStackWriter(OutputStream output, String encoding) throws XMLStreamException {
+		
 		XMLOutputFactory factory = XMLOutputFactory.newInstance();
 		this.output = output;
 		this.writer = factory.createXMLStreamWriter(output, encoding);//create a new file
@@ -45,6 +49,7 @@
 	
 	Charset UTF8 = Charset.forName("UTF-8");
 	public void write(String txt) throws IOException {
+		
 		output.write(txt.getBytes(UTF8));
 	}
 	
@@ -68,6 +73,7 @@
 	 * @throws XMLStreamException 
 	 */
 	public void writeStartElements(List<Object> tagsToWrite) throws XMLStreamException {
+		
 		for (Object tag : tagsToWrite) {
 			if (tag instanceof String) {
 				writeStartElement((String)tag);
@@ -84,11 +90,13 @@
 	}
 	
 	public List<List<List>> getTagStack() {
+		
 		return events;
 	}
 	
 	@Override
 	public void close () throws XMLStreamException {
+		
 		writer.close();
 		try {
 			output.close();
@@ -101,43 +109,51 @@
 	
 	@Override
 	public void flush () throws XMLStreamException {
+		
 		writer.flush();
 	}
 	
 	@Override
 	public NamespaceContext getNamespaceContext() {
+		
 		return writer.getNamespaceContext();
 	}
 	
 	@Override
 	public String getPrefix (String uri) throws XMLStreamException {
+		
 		return writer.getPrefix(uri);
 	}
 	
 	@Override
 	public Object getProperty (String name) throws IllegalArgumentException {
+		
 		return writer.getProperty(name);
 	}
 	
 	@Override
 	public void setDefaultNamespace (String uri) throws XMLStreamException {
+		
 		writer.setDefaultNamespace(uri);
 	}
 	
 	@Override
-	public void setNamespaceContext(NamespaceContext context)
-	throws XMLStreamException {
+	public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
+		
 		writer.setNamespaceContext(context);
 	}
 	
 	@Override
 	public void setPrefix (String prefix, String uri) throws XMLStreamException {
+		
 		writer.setPrefix(prefix, uri);
 	}
 	
 	@Override
 	public void writeAttribute (String localName, String value) throws XMLStreamException {
-		if (value == null) return;
+		
+		if (value == null) return; // skip if value is null
+		if (localName == null) return; // skip if localName is null
 		writer.writeAttribute(localName, value);
 		
 		if (events.size() > 0) events.get(events.size()-1).get(1).add(Arrays.asList(localName, value));
@@ -145,7 +161,9 @@
 	
 	@Override
 	public void writeAttribute (String namespaceURI, String localName, String value) throws XMLStreamException {
-		if (value == null) return;
+		
+		if (value == null) return; // skip if value is null
+		if (localName == null) return; // skip if localName is null
 		writer.writeAttribute(namespaceURI, localName, value);
 		
 		if (events.size() > 0) events.get(events.size()-1).get(1).add(Arrays.asList(localName, value));
@@ -153,7 +171,9 @@
 	
 	@Override
 	public void writeAttribute (String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
-		if (value == null) return;
+		
+		if (value == null) return; // skip if value is null
+		if (localName == null) return; // skip if localName is null
 		writer.writeAttribute(prefix, namespaceURI, localName, value);
 		
 		if (events.size() > 0) events.get(events.size()-1).get(1).add(Arrays.asList(localName, value));
@@ -161,32 +181,42 @@
 	
 	@Override
 	public void writeCData (String data) throws XMLStreamException {
+		
+		if (data == null) return;
 		writer.writeCData(data);
 	}
 	
 	@Override
 	public void writeCharacters (String text) throws XMLStreamException {
+		
+		if (text == null) return;
 		writer.writeCharacters(text);
 	}
 	
 	@Override
 	public void writeCharacters (char[] text, int start, int len) throws XMLStreamException {
+		
+		if (text == null) return;
 		writer.writeCharacters(text, start, len);
 	}
 	
 	@Override
 	public void writeComment (String data) throws XMLStreamException {
+		
+		if (data == null) return;
 		writer.writeComment(data);
 	}
 	
 	@Override
 	public void writeDTD (String dtd) throws XMLStreamException {
+		
+		if (dtd == null) return;
 		writer.writeDTD(dtd);
 	}
 	
 	@Override
-	public void writeDefaultNamespace(String namespaceURI)
-	throws XMLStreamException {
+	public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
+		
 		writer.writeDefaultNamespace(namespaceURI);
 	}
 	
@@ -196,7 +226,8 @@
 	 * @param text
 	 * @throws XMLStreamException
 	 */
-	public void writeElement (String localName, String text) throws XMLStreamException {
+	public void writeElement(String localName, String text) throws XMLStreamException {
+		
 		if (text != null && text.length() > 0) {
 			writer.writeStartElement(localName);
 			writer.writeCharacters(text);
@@ -206,7 +237,8 @@
 		}
 	}
 	
-	public void writeElement (String localName, HashMap map, String text) throws XMLStreamException {
+	public void writeElement(String localName, HashMap map, String text) throws XMLStreamException {
+		
 		if (text != null && text.length() > 0) {
 			writer.writeStartElement(localName);
 			
@@ -217,7 +249,7 @@
 					writeAttribute(key.toString(), map.get(key).toString());
 				}
 			}
-			writer.writeCharacters(text);
+			if (text != null) writer.writeCharacters(text);
 			writer.writeEndElement();
 			
 			events.remove(events.size()-1);
@@ -228,10 +260,12 @@
 	
 	@Override
 	public void writeEmptyElement (String localName) throws XMLStreamException {
+		
 		writer.writeEmptyElement(localName);
 	}
 	
 	public void writeEmptyElement (String localName, HashMap map) throws XMLStreamException {
+		
 		writer.writeEmptyElement(localName);
 		events.add(new ArrayList(Arrays.asList(localName, new ArrayList()))); // must be done or else writeAttribute will insert the attribute in the previous element
 		for (Object key : map.keySet()) {
@@ -243,23 +277,26 @@
 	}
 	
 	@Override
-	public void writeEmptyElement(String namespaceURI, String localName)
-	throws XMLStreamException {
+	public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
+		
 		writer.writeEmptyElement(namespaceURI, localName);
 	}
 	
 	@Override
 	public void writeEmptyElement (String prefix, String localName, String namespaceURI) throws XMLStreamException {
+		
 		writer.writeEmptyElement(prefix, localName, namespaceURI);
 	}
 	
 	@Override
 	public void writeEndDocument () throws XMLStreamException {
+		
 		writer.writeEndDocument();
 	}
 	
 	@Override
 	public void writeEndElement () throws XMLStreamException {
+		
 		writer.writeEndElement();
 		events.remove(events.size()-1);
 		if (debug) System.out.println("END: "+events);
@@ -267,51 +304,56 @@
 	
 	@Override
 	public void writeEntityRef (String name) throws XMLStreamException {
+		
 		writer.writeEntityRef(name);
 	}
 	
 	@Override
-	public void writeNamespace(String prefix, String namespaceURI)
-	throws XMLStreamException {
+	public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
+		
 		writer.writeNamespace(prefix, namespaceURI);
 	}
 	
 	@Override
-	public void writeProcessingInstruction(String target)
-	throws XMLStreamException {
+	public void writeProcessingInstruction(String target) throws XMLStreamException {
+		
 		writer.writeProcessingInstruction(target);
 	}
 	
 	@Override
-	public void writeProcessingInstruction(String target, String data)
-	throws XMLStreamException {
+	public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
+		
 		writer.writeProcessingInstruction(target, data);
 	}
 	
 	@Override
 	public void writeStartDocument () throws XMLStreamException {
+		
 		writer.writeStartDocument();
 	}
 	
 	@Override
 	public void writeStartDocument (String version) throws XMLStreamException {
+		
 		writer.writeStartDocument(version);
 	}
 	
 	@Override
-	public void writeStartDocument(String encoding, String version)
-	throws XMLStreamException {
+	public void writeStartDocument(String encoding, String version) throws XMLStreamException {
+		
 		writer.writeStartDocument(encoding, version);
 	}
 	
 	@Override
 	public void writeStartElement (String localName) throws XMLStreamException {
+		
 		writer.writeStartElement(localName);
 		events.add(new ArrayList(Arrays.asList(localName, new ArrayList())));
 		if (debug) System.out.println("START "+localName+" "+events);
 	}
 
 	public void writeStartElement (String localName, HashMap map) throws XMLStreamException {
+		
 		writeStartElement(localName);
 		
 		for (Object key : map.keySet()) {
@@ -323,8 +365,8 @@
 	}
 	
 	@Override
-	public void writeStartElement(String namespaceURI, String localName)
-	throws XMLStreamException {
+	public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
+		
 		writer.writeStartElement(namespaceURI, localName);
 		events.add(new ArrayList(Arrays.asList(localName, new ArrayList())));
 		
@@ -332,8 +374,8 @@
 	}
 	
 	@Override
-	public void writeStartElement(String prefix, String localName,
-			String namespaceURI) throws XMLStreamException {
+	public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+		
 		writer.writeStartElement(prefix, localName, namespaceURI);
 		events.add(new ArrayList(Arrays.asList(localName, new ArrayList())));
 		if (debug) System.out.println("START "+prefix+" "+localName+" "+events);
