private void buildXMLNode(JSONObject from, Element parent) { if (from == null) { return; } Element node = parent.addElement(from.optString("type")) .addAttribute("name", from.optString("name")) .addAttribute("label", from.optString("label")) .addAttribute("value", from.optString("value")) .addAttribute("ref", from.optString("ref")); JSONArray array = from.optJSONArray("children"); if (array != null) { for (int i = 0; i < array.length(); i++) { JSONObject n = array.optJSONObject(i); buildXMLNode(n, node); } } } }