2011-12-11 72 views

回答

2

nu.xom.Serializer正是你所需要的。下面是一个使用example

public static void main(String[] args) { 
    Element root = new Element("root"); 
    Element fraction = new Element("Fraction"); 
    fraction.addAttribute(new Attribute("hash", "108e898f")); 
    root.appendChild(fraction); 
    Element integer = new Element("Integer"); 
    integer.addAttribute(new Attribute("hash", "19498483")); 
    root.appendChild(integer); 
    Document doc = new Document(root); 
    try { 
     Serializer serializer = new Serializer(System.out, "ISO-8859-1"); 
     serializer.setIndent(4); 
     serializer.setMaxLength(64); 
     serializer.write(doc); 
    } catch (IOException ex) { 
     System.err.println(ex); 
    } 
} 
1

好像你想要一个漂亮的打印输出。用Xom做这件事应该很容易,试试this previous answer,这可能会有所帮助。

相关问题