@@ -140,8 +140,17 @@ impl XMLElement {
140140 writer : & mut W ,
141141 should_sort : bool ,
142142 should_indent : bool ,
143+ should_break_lines : bool ,
144+ should_expand_empty_tags : bool ,
143145 ) -> Result < ( ) > {
144- self . render_level ( writer, 0 , should_sort, should_indent)
146+ self . render_level (
147+ writer,
148+ 0 ,
149+ should_sort,
150+ should_indent,
151+ should_break_lines,
152+ should_expand_empty_tags,
153+ )
145154 }
146155
147156 /// Internal method rendering and indenting a XMLELement object
@@ -156,30 +165,56 @@ impl XMLElement {
156165 level : usize ,
157166 should_sort : bool ,
158167 should_indent : bool ,
168+ should_break_lines : bool ,
169+ should_expand_empty_tags : bool ,
159170 ) -> Result < ( ) > {
160171 let indent = match should_indent {
161172 true => "\t " . repeat ( level) ,
162173 false => "" . into ( ) ,
163174 } ;
175+ let suffix = match should_break_lines {
176+ true => "\n " ,
177+ false => "" ,
178+ } ;
164179
165180 let attributes = self . attributes_as_string ( should_sort) ;
166181
167182 match & self . content {
168- XMLElementContent :: Empty => {
169- writeln ! ( writer, "{}<{}{} />" , indent, self . name, attributes) ?;
170- }
183+ XMLElementContent :: Empty => match should_expand_empty_tags {
184+ true => {
185+ write ! (
186+ writer,
187+ "{}<{}{}></{}>{}" ,
188+ indent, self . name, attributes, self . name, suffix
189+ ) ?;
190+ }
191+ false => {
192+ write ! (
193+ writer,
194+ "{}<{}{} />{}" ,
195+ indent, self . name, attributes, suffix
196+ ) ?;
197+ }
198+ } ,
171199 XMLElementContent :: Elements ( elements) => {
172- writeln ! ( writer, "{}<{}{}>" , indent, self . name, attributes) ?;
200+ write ! ( writer, "{}<{}{}>{} " , indent, self . name, attributes, suffix ) ?;
173201 for elem in elements {
174- elem. render_level ( writer, level + 1 , should_sort, should_indent) ?;
202+ elem. render_level (
203+ writer,
204+ level + 1 ,
205+ should_sort,
206+ should_indent,
207+ should_break_lines,
208+ should_expand_empty_tags,
209+ ) ?;
175210 }
176- writeln ! ( writer, "{}</{}>" , indent, self . name) ?;
211+ write ! ( writer, "{}</{}>{} " , indent, self . name, suffix ) ?;
177212 }
178213 XMLElementContent :: Text ( text) => {
179- writeln ! (
214+ write ! (
180215 writer,
181- "{}<{}{}>{}</{}>" ,
182- indent, self . name, attributes, text, self . name
216+ "{}<{}{}>{}</{}>{} " ,
217+ indent, self . name, attributes, text, self . name, suffix
183218 ) ?;
184219 }
185220 } ;
0 commit comments