comparison src/goodjava/xml/XmlElement.java @ 1791:f8f5c51f5b36

xml work
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 26 Dec 2023 19:16:18 -0700
parents a8c685a894b4
children a55a891a4f67
comparison
equal deleted inserted replaced
1790:a8c685a894b4 1791:f8f5c51f5b36
5 5
6 public final class XmlElement { 6 public final class XmlElement {
7 public final String name; 7 public final String name;
8 public final Map<String,String> attributes; 8 public final Map<String,String> attributes;
9 private Object content = null; 9 private Object content = null;
10 private XmlElement parent = null;
10 11
11 public XmlElement(String name,Map<String,String> attributes) { 12 public XmlElement(String name,Map<String,String> attributes) {
12 this.name = name; 13 this.name = name;
13 this.attributes = attributes; 14 this.attributes = attributes;
14 this.content = null; 15 this.content = null;
16 }
17
18 public XmlElement getParent() {
19 return parent;
15 } 20 }
16 21
17 public Object getContent() { 22 public Object getContent() {
18 return content; 23 return content;
19 } 24 }
32 if( content == null ) 37 if( content == null )
33 throw new IllegalArgumentException("content can't be null"); 38 throw new IllegalArgumentException("content can't be null");
34 if( content.length == 0 ) 39 if( content.length == 0 )
35 throw new IllegalArgumentException("content can't be empty"); 40 throw new IllegalArgumentException("content can't be empty");
36 this.content = content; 41 this.content = content;
42 for( XmlElement el : content ) {
43 el.parent = this;
44 }
37 } 45 }
38 46
39 @Override public String toString() { 47 @Override public String toString() {
40 StringBuilder sb = new StringBuilder(); 48 StringBuilder sb = new StringBuilder();
41 toString(sb,0); 49 toString(sb,0);