Posts Tagged ‘java’

GWT XML Indenter/Formatter

December 31st, 2008 5 comments

So while I was working on one of my outreach projects as a graduate student, I wanted to write a simple XML indenter to make my GWT generated xml more aesthetically appealing using stock GWT. The xml document is assumed to be as lean as possible (There are no empty #text nodes that are usually in xml because of the indentation.)

I should also mention that I’m posting this because I didn’t really see any stock simple GWT indenters after a quick google. The following is not meant to be a complete indenter, just something quick and simple to organize xml.

Here’s a basic indenter.

	public String formatXML(Node node,String tab_str)
		String formatted="";
		if (node.getNodeType()==Node.ELEMENT_NODE)
			String attributes="";
			for (int k=0;k < node.getAttributes().getLength();k++)
				attributes+=" "+node.getAttributes().item(k).getNodeName()+"=\""+node.getAttributes().item(k).getNodeValue()+"\"";
			for (int i=0;i< node.getChildNodes().getLength();i++)
				formatted=formatted+formatXML(node.getChildNodes().item(i),tab_str+"    ");
			if (node.toString().trim().length()>0)
		return formatted;
Categories: Education Tags: , , , ,


November 3rd, 2008 No comments

A program to find the shortest walking path by road, hills, or shortcut through the Berkeley Campus. Includes cool tracking and zooming picture and GUI interface. CoWritten and planned with Tony Wu. We did this over the winter break in 2004.

Download: Binary and Source