Skip to content

Commit

Permalink
Issue67 (#68)
Browse files Browse the repository at this point in the history
* Issue 67

* Issue 67

* Issue 67
  • Loading branch information
shamblett authored Oct 13, 2024
1 parent cae3709 commit dbff585
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/src/xml2json_open_rally.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class _Xml2JsonOpenRally {
} else if (children.isNotEmpty) {
ret.addAll({_toJsonString(node.name.local): children});
} else {
ret.addAll(
{_toJsonString(node.name.local): _toJsonString(true.toString())});
ret.addAll({_toJsonString(node.name.local): null});
}
return ret;
} else if (node is XmlText) {
Expand All @@ -91,7 +90,7 @@ class _Xml2JsonOpenRally {
json = _recursiveParse(xmlNode, attributePrefix: attributePrefix);
} on Exception catch (e) {
throw Xml2JsonException(
'Parker internal transform error => ${e.toString()}');
'OpenRally internal transform error => ${e.toString()}');
}
return json.toString();
}
Expand Down
24 changes: 24 additions & 0 deletions test/issue67_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@TestOn('vm')
library;

import 'package:test/test.dart';
import 'package:xml2json/xml2json.dart';

void main() {
const input = "<root><item></item><name>john</name></root>";

test('OpenRally', () {
final xmlParser = Xml2Json();
xmlParser.parse(input);
var jsonResponse = xmlParser.toOpenRally();
expect(jsonResponse, '{"root": {"item": null, "name": "john"}}');
});

test('Parker', () {
final xmlParser = Xml2Json();
xmlParser.parse(input);
var jsonResponse = xmlParser.toParker();
print(jsonResponse);
expect(jsonResponse, '{"root": {"item": null, "name": "john"}}');
});
}
4 changes: 2 additions & 2 deletions test/xml2json_test_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,10 @@ String openRallyStringJson = """
"extensions":{
"distance":"0",
"cap":"328",
"show_coordinates":"true",
"show_coordinates":null,
"tulip":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY4AAA...",
"notes":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY4AAA...",
"timecontrol":"true"
"timecontrol": null
}
},
{
Expand Down

0 comments on commit dbff585

Please sign in to comment.