File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
main/java/org/metafacture/xml
test/java/org/metafacture/xml Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe<ObjectReceiver<Str
55
55
56
56
public static final String DEFAULT_ROOT_TAG = "records" ;
57
57
public static final String DEFAULT_RECORD_TAG = "record" ;
58
- public static final String DEFAULT_VALUE_TAG = null ;
58
+ public static final String DEFAULT_VALUE_TAG = "" ;
59
59
60
60
private static final String NEW_LINE = "\n " ;
61
61
private static final String INDENT = "\t " ;
@@ -211,7 +211,7 @@ public void endEntity() {
211
211
212
212
@ Override
213
213
public void literal (final String name , final String value ) {
214
- if (name .isEmpty () || name . equals (valueTag )) {
214
+ if (name .equals (valueTag )) {
215
215
element .setText (value );
216
216
}
217
217
else if (name .startsWith (attributeMarker )) {
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ public void shouldAddNamespaceWithEmptyKeyFromPropertiesFileAsDefaultNamespaceTo
180
180
}
181
181
182
182
@ Test
183
- public void testShouldEncodeEmptyLiteralsAsText () {
183
+ public void testShouldEncodeUnnamedLiteralsAsText () {
184
184
simpleXmlEncoder .startRecord ("" );
185
185
simpleXmlEncoder .literal ("" , VALUE );
186
186
simpleXmlEncoder .endRecord ();
@@ -195,6 +195,25 @@ public void testShouldEncodeEmptyLiteralsAsText() {
195
195
getResultXml ());
196
196
}
197
197
198
+ @ Test
199
+ public void testShouldStillEncodeUnnamedLiteralsAsTextWithConfiguredValueTagName () {
200
+ simpleXmlEncoder .setValueTag ("data" );
201
+
202
+ simpleXmlEncoder .startRecord ("" );
203
+ simpleXmlEncoder .literal ("" , VALUE );
204
+ simpleXmlEncoder .endRecord ();
205
+ simpleXmlEncoder .closeStream ();
206
+
207
+ // SimpleXmlEncoder.Element.writeElement() does not write child elements with empty name
208
+ assertEquals ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
209
+ "<records>" +
210
+ "<record>" +
211
+ "value" +
212
+ "</record>" +
213
+ "</records>" ,
214
+ getResultXml ());
215
+ }
216
+
198
217
@ Test
199
218
public void testShouldNotEncodeLiteralsWithDifferentValueTagNameAsText () {
200
219
simpleXmlEncoder .setValueTag ("data" );
You can’t perform that action at this time.
0 commit comments