File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed
main/java/com/github/underscore
test/java/com/github/underscore Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,12 @@ public XmlBuilder c(String comment) {
6767 return this ;
6868 }
6969
70+ public XmlBuilder i (String target , String value ) {
71+ U .remove (data , path + "." + SELF_CLOSING );
72+ U .set (data , "?" + target , value );
73+ return this ;
74+ }
75+
7076 public XmlBuilder d (String cdata ) {
7177 U .remove (data , path + "." + SELF_CLOSING );
7278 U .update (data , path + ".#cdata-section" , cdata );
@@ -79,6 +85,11 @@ public XmlBuilder t(String text) {
7985 return this ;
8086 }
8187
88+ public XmlBuilder importXmlBuilder (XmlBuilder xmlBuilder ) {
89+ data .putAll (xmlBuilder .data );
90+ return this ;
91+ }
92+
8293 public XmlBuilder up () {
8394 if (path .equals (savedPath )) {
8495 path = path .substring (0 , path .lastIndexOf ("." ));
Original file line number Diff line number Diff line change @@ -52,6 +52,28 @@ void comment() {
5252 xmlBuilder .asString ());
5353 }
5454
55+ @ Test
56+ void inst () {
57+ XmlBuilder xmlBuilder = XmlBuilder .create ("Projects" ).i ("target" , "text" );
58+ assertEquals (
59+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
60+ + "<Projects></Projects>\n "
61+ + "<?target text?>" ,
62+ xmlBuilder .asString ());
63+ }
64+
65+ @ Test
66+ void importXmlBuilder () {
67+ XmlBuilder xmlBuilder = XmlBuilder .create ("a" );
68+ assertEquals (
69+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
70+ + "<root>\n "
71+ + " <b/>\n "
72+ + " <a/>\n "
73+ + "</root>" ,
74+ XmlBuilder .create ("b" ).importXmlBuilder (xmlBuilder ).asString ());
75+ }
76+
5577 @ Test
5678 void cdata () {
5779 XmlBuilder xmlBuilder = XmlBuilder .create ("Projects" ).d ("text" );
@@ -107,17 +129,15 @@ void remove() {
107129 XmlBuilder xmlBuilder = new XmlBuilder ("root" ).e ("123" );
108130 xmlBuilder .remove ("root.123" );
109131 assertEquals (
110- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n <root></root>" ,
111- xmlBuilder .asString ());
132+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n <root></root>" , xmlBuilder .asString ());
112133 }
113134
114135 @ Test
115136 void clear () {
116137 XmlBuilder xmlBuilder = new XmlBuilder ("xml" ).e ("123" );
117138 xmlBuilder .clear ();
118139 assertEquals (
119- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n <root></root>" ,
120- xmlBuilder .asString ());
140+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n <root></root>" , xmlBuilder .asString ());
121141 }
122142
123143 @ Test
You can’t perform that action at this time.
0 commit comments