import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import java.io.*;
public class Foo {
    public Document createDocument() {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement( "root" );
        Element author1 = root.addElement( "author" )
            .addAttribute( "name", "James" )
            .addAttribute( "location", "UK" )
            .addText( "James Strachan" );
       
        Element author2 = root.addElement( "author" )
            .addAttribute( "name", "Bob" )
            .addAttribute( "location", "US" )
            .addText( "Bob McWhirter" );
        return document;
    }
 
 public static void main(String[] args)
 {
  try
  {
  Foo foo=new Foo();
  Document dok= foo.createDocument();
  FileWriter out = new FileWriter( "c:\\foo3.xml" );
  dok.write( out );
  String XML = dok.asXML();
  System.out.print(XML);
  }
  catch(Exception e)
  {
   System.out.println(e);
  }
  
 }
}
 
Why output foo3.xml is empty? Please help me!!!!!


Discover Yahoo!
Stay in touch with email, IM, photo sharing & more. Check it out!

Reply via email to