File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
main/java/com/github/underscore
test/java/com/github/underscore Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -1935,6 +1935,6 @@ public static String changeXmlEncoding(
19351935 }
19361936
19371937 public static String changeXmlEncoding (String xml , String encoding ) {
1938- return changeXmlEncoding (xml , XmlStringBuilder .Step .THREE_SPACES , encoding );
1938+ return changeXmlEncoding (xml , XmlStringBuilder .Step .TWO_SPACES , encoding );
19391939 }
19401940}
Original file line number Diff line number Diff line change @@ -144,10 +144,18 @@ public String asString() {
144144 return U .toXml (data );
145145 }
146146
147+ public String toXml (Xml .XmlStringBuilder .Step identStep ) {
148+ return Xml .toXml (data , identStep );
149+ }
150+
147151 public String toXml () {
148152 return U .toXml (data );
149153 }
150154
155+ public String toJson (Json .JsonStringBuilder .Step identStep ) {
156+ return Json .toJson (data , identStep );
157+ }
158+
151159 public String toJson () {
152160 return U .toJson (data );
153161 }
Original file line number Diff line number Diff line change @@ -214,12 +214,28 @@ void xmlBuilderArray() {
214214 xmlBuilder .asString ());
215215 }
216216
217+ @ Test
218+ void toXmlFormat () {
219+ XmlBuilder xmlBuilder = new XmlBuilder ("xml" ).e ("a" ).e ("b" );
220+ assertEquals (
221+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?><xml><a><b/></a></xml>" ,
222+ xmlBuilder .toXml (Xml .XmlStringBuilder .Step .COMPACT ));
223+ }
224+
217225 @ Test
218226 void toXml () {
219227 XmlBuilder xmlBuilder = XmlBuilder .parse (XML );
220228 assertEquals (XML , xmlBuilder .toXml ());
221229 }
222230
231+ @ Test
232+ void toJsonFormat () {
233+ XmlBuilder xmlBuilder = new XmlBuilder ("json" ).e ("a" ).e ("b" );
234+ assertEquals (
235+ "{\" json\" :{\" a\" :{\" b\" :{\" -self-closing\" :\" true\" }}}}" ,
236+ xmlBuilder .toJson (Json .JsonStringBuilder .Step .COMPACT ));
237+ }
238+
223239 @ Test
224240 void toJson () {
225241 XmlBuilder xmlBuilder = XmlBuilder .parse (XML );
You can’t perform that action at this time.
0 commit comments