/** * @param start A string of spaces indicating the indentation at which * to start the generation. This constructor will not insert an <?xml * prologue. */ public XMLStringBuffer(String start) { init(Buffer.create(), start); }
public XMLStringBuffer() { init(Buffer.create(), "", "1.0", "UTF-8"); }
/** * @param start A string of spaces indicating the indentation at which to start the generation. * This constructor will not insert an <?xml prologue. */ public XMLStringBuffer(String start) { init(Buffer.create(), start); }
public XMLStringBuffer() { init(Buffer.create(), "", "1.0", "UTF-8"); }
/** * Generate tag. * An opening and closing tag will be generated even if value is null. * @param name name of the tag * @param content content for this tag (or null) * @param attributes tag attributes (or null) */ static public String xml(String indent, String name, @Nullable String content, @Nullable Properties attributes) { IBuffer result = Buffer.create(); xmlOpen(result, indent, name, attributes, true /* no newline */); if (content != null) { result.append(content); } xmlClose(result, "", name, XMLUtils.extractComment(name, attributes)); return result.toString(); }
/** * Generate tag. An opening and closing tag will be generated even if value is null. * * @param name name of the tag * @param content content for this tag (or null) * @param attributes tag attributes (or null) */ public static String xml( String indent, String name, @Nullable String content, @Nullable Properties attributes) { IBuffer result = Buffer.create(); xmlOpen(result, indent, name, attributes, true /* no newline */); if (content != null) { result.append(content); } xmlClose(result, "", name, XMLUtils.extractComment(name, attributes)); return result.toString(); }
@Test public void testMethod() { IBuffer result = Buffer.create(); XMLStringBuffer sb = new XMLStringBuffer(result, ""); sb.push("family"); Properties p = new Properties(); p.setProperty("prop1", "value1"); p.setProperty("prop2", "value2"); sb.addRequired("cedric", "true", p); sb.addRequired("alois", "true"); sb.addOptional("anne-marie", (String) null); sb.pop(); String expected = "<family>" + EOL + " <cedric prop2=\"value2\" prop1=\"value1\">true</cedric>" + EOL + " <alois>true</alois>" + EOL + "</family>"; assertThat(result.toString().trim()).isEqualTo(expected); }