import java.io.FileInputStream; import java.io.IOException; import javax.swing.JTree; import javax.swing.tree.DefaultTreeModel; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; public class StAXCompact { // production of string of spaces with a lazy StringBuffer private static StringBuffer blanks = new StringBuffer(); private static String blanks(int n){ for(int i=blanks.length();i0)System.out.print('\n'+indent); System.out.print("@"+xmlsr.getAttributeLocalName(i)+ '['+xmlsr.getAttributeValue(i)+']'); } boolean first=count==0; while (true){ do {xmlsr.next();} while(xmlsr.isWhiteSpace()); if (xmlsr.isEndElement()) break; if (first) first=false; else System.out.print('\n'+indent); compact(xmlsr,indent); } System.out.print(']'); } else if (xmlsr.isCharacters()){ System.out.print(xmlsr.getText()); } } }