You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Nuno Miguel Ferreira <Nu...@siemens.com> on 2005/02/24 16:25:58 UTC

[ECS] Format a XML Document

 I there ... I started using the ECS API today and this is really what I
need ... I only whish to know only little thing. Is it possible to
insert line breaks to format the XML document in a more readable way?

 Im using this example code ...

public class JakartaECSExample {

    public static void main(String[] args){
        XML root = new XML("root");
        root.addXMLAttribute("attr", "root");

        
        XML innerElement = new XML("element");
        root.addElement(innerElement);
        
        XMLDocument doc = new XMLDocument();
        doc.addElement(root);
        System.out.println(doc.toString());
        
        try{
            File file = new File ("d:/TMP/xmldoc.xml");
            OutputStream out = new FileOutputStream(file);
            
            doc.output(out);
            
            out.flush();
            out.close();
            
            
        }catch(FileNotFoundException e){
            e.printStackTrace();
            
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}

 The generated output is like this:
 <?xml version="1.0" standalone="yes"?><root
attr='raiz'><element></element></root>

 Is there any possibility to include linebreaks after each xml tag? I
searched the API documentation and I've found a getNeedLineBreak() but
no set method ... 

 Help ... :)

 Thks in advance ...

 Nuno Belo
-------------------------------------------- 
 Siemens, S.A. 
 COM RD1 WON NM P3 
 Software Development - TMN Porto 
 Estrada Nacional 107, 3570
 4456-901 Perafita
-------------------------------------------- 
 Tel.: + 351 22 999 2073
 Fax: + 351 22 999 2080
 Email: nuno.mferreira@siemens.com
--------------------------------------------