All pastes #366436 Raw Edit

Miscellany

public text v1 · immutable
#366436 ·published 2007-02-21 17:56 UTC
rendered paste body
public class Test {
  public static void main(String[] args) {
    XmlBuffer buf = new XmlBuffer();

    try {
      buf
        .openTag("ItemDiscountAddRq")
          .openTag("ItemDiscountAdd").addAttribute("foo", "b&ar").addAttribute("biz", "bam")
            .textTag("Name", "Foobar")
          .closeTag()
          .openTag("ItemDiscountDel")
            .textTag("Foo", "barfoo")
          .closeTag()
        .closeTag();
      System.out.print(buf.toString());
    } catch (XmlBuffer.InvalidOpException e) {
      System.out.println("Error: " + e.getMessage());
    }
  }
}

Output:
<?xml version="1.0"?>
<ItemDiscountAddRq>
  <ItemDiscountAdd foo="b&amp;ar" biz="bam">
    <Name>Foobar</Name>
  </ItemDiscountAdd>
  <ItemDiscountDel>
    <Foo>barfoo</Foo>
  </ItemDiscountDel>
</ItemDiscountAddRq>