private void printElementOpen(StringBuffer buffer, MiniElement element) { buffer.append("<"); buffer.append(element.getName()); for (int i = 0, n = element.getAttributeCount(); i < n; i++) { buffer.append(" "); printAttribute(buffer, element.getAttribute(i)); } buffer.append(">"); }
public String getAttribute(String name) { StringTokenizer parser = new StringTokenizer(name, "."); MiniElement element = rootElement; String token = name; while (parser.countTokens() > 1) { token = parser.nextToken(); MiniElement child = element.getElement(token); if (child == null) { return null; } element = child; } token = parser.nextToken(); MiniAttribute attribute = element.getAttribute(token); if (attribute == null) { return null; } else { return attribute.getValue(); } }
public void setAttribute(String name, String value) { StringTokenizer parser = new StringTokenizer(name, "."); MiniElement element = rootElement; String token = name; while (parser.countTokens() > 1) { token = parser.nextToken(); MiniElement child = element.getElement(token); if (child == null) { child = new MiniElement(token); element.addElement(child); } element = child; } token = parser.nextToken(); MiniAttribute attribute = element.getAttribute(token); if (attribute == null) { attribute = new MiniAttribute(token, value); element.addAttribute(attribute); } else { attribute.setValue(value); } }