annotate src/goodjava/xml/Xml.java @ 1790:a8c685a894b4

start xml work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Dec 2023 23:07:59 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1790
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.xml;
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 public final class Xml {
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 public String declaration;
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 private XmlElement element;
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 public XmlElement getElement() {
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 return element;
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 }
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 public void setElement(XmlElement element) {
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 if( element == null )
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 throw new IllegalArgumentException("element can't be null");
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 this.element = element;
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 }
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 @Override public String toString() {
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 StringBuilder sb = new StringBuilder();
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 if( declaration != null ) {
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 sb.append( declaration );
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 sb.append( '\n' );
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 }
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 element.toString(sb,0);
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return sb.toString();
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 }
a8c685a894b4 start xml work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 }