public void saveIntoXMLFile( String filename ) {
		try {
			// set up xml doc factory
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = factory.newDocumentBuilder();
			Document xmlDoc = db.newDocument();

			// set up xml builder
			TransformerFactory tf = TransformerFactory.newInstance();
			Transformer t = tf.newTransformer();
			t.setOutputProperty( "indent", "yes" );
			DOMSource source = new DOMSource();
			source.setNode( xmlDoc );
			
			// Transform the word list into a ordered set. Then the output list is ordered.
			TreeSet< Word > ts = new TreeSet< Word >( wordLib );
			
			for( Word w : ts ) {
				Element word = xmlDoc.createElement( "word" );
				Element english = xmlDoc.createElement( "english" );
				english.setTextContent( w.getEnglishContent() );
				word.appendChild( english );
				Element type = xmlDoc.createElement( "type" );
				if( w.getType() == Word.WordType.NORMAL ) {
					type.setTextContent( "normal" );
				}
				else if( w.getType() == Word.WordType.PERSON_NAME ) {
					type.setTextContent( "person name" );
				}
				else if( w.getType() == Word.WordType.SPOT_NAME ) {
					type.setTextContent( "spot name" );
				}
				else {
					System.out.println( "Unknown word type:" + w.getType().toString() );
					System.exit( 0 );
				}
				word.appendChild( type );
				Element sentences = xmlDoc.createElement( "sentences" );
				for( int i = 0; i < w.getSentences().size(); i++ ) {
					Element s = xmlDoc.createElement( "sentence" );
					s.setTextContent( w.getSentences().get( i ) );
					sentences.appendChild( s );
				}
				word.appendChild( sentences );
				Element in_time = xmlDoc.createElement( "in_time" );
				in_time.setTextContent( w.getIn_time() );
				word.appendChild( in_time );
				Element last_time = xmlDoc.createElement( "last_time" );
				last_time.setTextContent( w.getLast_time() );
				word.appendChild( last_time );
				Element total_times = xmlDoc.createElement( "total_times" );
				total_times.setTextContent( w.getTotal_times() + "" );
				word.appendChild( total_times );
				Element peak_times = xmlDoc.createElement( "peak_times" );
				peak_times.setTextContent( w.getPeak_times() + "" );
				word.appendChild( peak_times );
				Element article_frequency = xmlDoc.createElement( "article_frequency" );
				article_frequency.setTextContent( w.getArticle_frequency() + "" );
				word.appendChild( article_frequency );
				
				xmlDoc.appendChild( word );
			}
			
			StreamResult result = new StreamResult();
			result.setOutputStream( new FileOutputStream( filename ) );
			t.transform( source, result );
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}