Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 42 additions & 29 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,95 @@
## 6.2.6
Issue 71
- [Issue 71](https://github.com/shamblett/xml2json/issues/71)

## 6.2.5
Issue 67
- [Issue 67](https://github.com/shamblett/xml2json/issues/67)

## 6.2.4
Update to issue 23
Update to Issue 23
- [Issue 23](https://github.com/shamblett/xml2json/issues/23)

## 6.2.3
Added topics and screenshot

## 6.2.2
Issue 64
- [Issue 64](https://github.com/shamblett/xml2json/issues/64)

## 6.2.1
Issue 62
- [Issue 62](https://github.com/shamblett/xml2json/issues/62)

## 6.2.0
Issue 23 - OpenRally update
- [Issue 23](https://github.com/shamblett/xml2json/issues/23) - OpenRally update

## 6.1.0
Issue 58
- [Issue 58](https://github.com/shamblett/xml2json/issues/58)

## 6.0.0
Issue 60 - Dart 3
- [Issue 60](https://github.com/shamblett/xml2json/issues/60) - Dart 3

## 5.3.6
Issue 52
- [Issue 52](https://github.com/shamblett/xml2json/issues/52)

## 5.3.5
Issue 51
- [Issue 51](https://github.com/shamblett/xml2json/issues/51)

## 5.3.4
Issue 48
- [Issue 48](https://github.com/shamblett/xml2json/issues/48)

## 5.3.3
PR 46 and issue 47, remove Travis
- [PR 46](https://github.com/shamblett/xml2json/pull/46)
- [Issue 47](https://github.com/shamblett/xml2json/issues/47)

## 5.3.2
PR's 44 and 45, add SBOM
- [PR 44](https://github.com/shamblett/xml2json/pull/44)
- [PR 45](https://github.com/shamblett/xml2json/pull/45)

## 5.3.1
Issue 41
- [Issue 41](https://github.com/shamblett/xml2json/issues/41)

## 5.3.0
Issue 36
- [Issue 36](https://github.com/shamblett/xml2json/issues/36)

## 5.2.0
Issue 33, addition of Parker with attributes transformer.
- [Issue 33](https://github.com/shamblett/xml2json/issues/33), addition of Parker with attributes transformer.

## 5.1.0
Merge pull request #32 from faithoflifedev/master
- [PR 32](https://github.com/shamblett/xml2json/pull/32)

Badgerfish transform now supports the option to use local name for nodes.

## 5.0.0
Issues 27(NNBD), 28, 29 and 30
- [Issue 27](https://github.com/shamblett/xml2json/issues/27)
- [Issue 28](https://github.com/shamblett/xml2json/issues/28)
- [Issue 29](https://github.com/shamblett/xml2json/issues/29)
- [Issue 30](https://github.com/shamblett/xml2json/issues/30)

## 5.0.0-nullsafety.0
Null safety first update

## 4.4.0
Issue 23
- [Issue 23](https://github.com/shamblett/xml2json/issues/23)

## 4.3.0
Issue 21
- [Issue 21](https://github.com/shamblett/xml2json/issues/21)

## 4.2.1
Issue 20
- [Issue 20](https://github.com/shamblett/xml2json/issues/20)

## 4.2.0
Issue 16
- [Issue 16](https://github.com/shamblett/xml2json/issues/16)

## 4.1.1
Linter updates

## 4.1.0
Pull request 18, add CDATA node parsing for Parker
- [Pull request 18](https://github.com/shamblett/xml2json/pull/18), add CDATA node parsing for Parker

## 4.0.0
Issue 17, License is now MIT, small tidy ups
- [Issue 17](https://github.com/shamblett/xml2json/issues/17), License is now MIT, small tidy ups

## 3.0.3
Update testing, new linter rules
Expand All @@ -87,16 +98,16 @@ Update testing, new linter rules
Update testing, run browser tests on Travis

## 3.0.1
Issue 15, relax sdk constraints for flutter
- [Issue 15](https://github.com/shamblett/xml2json/issues/15), relax sdk constraints for flutter

## 3.0.0
Issue 14, update to Dart 2
- [Issue 14](https://github.com/shamblett/xml2json/issues/14), update to Dart 2

## 2.0.14
Issue 12, update to latest XML package
- [Issue 12](https://github.com/shamblett/xml2json/issues/12), update to latest XML package

## 2.0.13
Issue 11, exception message bug
- [Issue 11](https://github.com/shamblett/xml2json/issues/11), exception message bug

## 2.0.12
Remove dev infinity constraint on the Dart SDK for Flutter
Expand All @@ -109,23 +120,25 @@ Rename the analysis options file

## 2.0.9

Issue 9, SDK version constraint update, general
- [Issue 9](https://github.com/shamblett/xml2json/issues/9), SDK version constraint update, general
pre Dart 2.0 spruce up

## 2.0.8

Issue 8, correctly escape CDATA strings for JSON
- [Issue 8](https://github.com/shamblett/xml2json/issues/8), correctly escape CDATA strings for JSON

## 2.0.7

Issue 7, CDATA nodes now translated for Badgerfish
- [Issue 7](https://github.com/shamblett/xml2json/issues/7), CDATA nodes now translated for Badgerfish
and GData.

## 2.0.6

Use the new XML Package, update to latest Petit Parser
see issue 5 in github.

- [Issue 5](https://github.com/shamblett/xml2json/issues/5)

Remove Drone IO integration, now done by pub.

## 2.0.5
Expand All @@ -134,7 +147,7 @@ Integrate with Dart's Drone IO testing

## 2.0.4

Browser is now a dev dependancy
Browser is now a dev dependency

## 2.0.3

Expand All @@ -154,6 +167,6 @@ Updates for Dart 1.0 release

## 1.1.0

* Fix the runtime type name change intoroduced in Dart r28101
* Fix the runtime type name change introduced in Dart r28101
* Generate API documents
* Package formatting updates
16 changes: 16 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,19 @@ analyzer:
exclude:
- test/issues/**
- test/xml2json_test_strings.dart
-
dart_code_metrics:
exclude:
metrics:
- test/**
- example/**
rules:
- test/**
- example/**
extends:
- package:dart_code_metrics_presets/dart_all.yaml
rules:
- avoid-dynamic : false
- avoid-non-null-assertion : false
- newline-before-return : false
- avoid-late-keyword : false
39 changes: 27 additions & 12 deletions lib/src/xml2json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Xml2Json {
final xmlStringPrep = _Xml2JsonUtils.prepareXmlString(xmlString);
try {
_result = XmlDocument.parse(xmlStringPrep);
} on Object {
} on Object catch (_, stack) {
const errorString = 'parse error - invalid XML';
throw Xml2JsonException(errorString);
Error.throwWithStackTrace(Xml2JsonException(errorString), stack);
}
}

Expand All @@ -70,8 +70,11 @@ class Xml2Json {
final badgerfishTransformer = _Xml2JsonBadgerfish(useLocalNameForNodes);
try {
json = badgerfishTransformer.transform(_result);
} on Exception catch (e) {
throw Xml2JsonException('toBadgerfish error => ${e.toString()}');
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException('toBadgerfish error => ${e.toString()}'),
stack,
);
}

return json;
Expand All @@ -87,8 +90,11 @@ class Xml2Json {
final openRallyTransformer = _Xml2JsonOpenRally();
try {
json = openRallyTransformer.transform(_result);
} on Exception catch (e) {
throw Xml2JsonException('toOpenRally error => ${e.toString()}');
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException('toOpenRally error => ${e.toString()}'),
stack,
);
}

return json;
Expand All @@ -104,8 +110,11 @@ class Xml2Json {
final parkerTransformer = _Xml2JsonParker();
try {
json = parkerTransformer.transform(_result);
} on Exception catch (e) {
throw Xml2JsonException('toParker error => ${e.toString()}');
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException('toParker error => ${e.toString()}'),
stack,
);
}

return json;
Expand All @@ -121,8 +130,11 @@ class Xml2Json {
final parkerTransformer = _Xml2JsonParkerWithAttrs();
try {
json = parkerTransformer.transform(_result, array: array);
} on Exception catch (e) {
throw Xml2JsonException('toParkerWithAttrs error => ${e.toString()}');
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException('toParkerWithAttrs error => ${e.toString()}'),
stack,
);
}

return json;
Expand All @@ -138,8 +150,11 @@ class Xml2Json {
final gDataTransformer = _Xml2JsonGData();
try {
json = gDataTransformer.transform(_result);
} on Exception catch (e) {
throw Xml2JsonException('toGData error => ${e.toString()}');
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException('toGData error => ${e.toString()}'),
stack,
);
}

return json;
Expand Down
30 changes: 17 additions & 13 deletions lib/src/xml2json_badgerfish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ part of '../xml2json.dart';
class _Xml2JsonBadgerfish {
/// Badgerfish transformer function.

final bool useLocalNameForNodes;
final String _marker = '"\$"';
final String _xmlnsPrefix = '"@xmlns"';
final String _cdata = '"__cdata"';
final bool useLocalNameForNodes;

_Xml2JsonBadgerfish(this.useLocalNameForNodes);

/// Transformer function
String transform(XmlDocument? xmlNode) {
Map<dynamic, dynamic> json;
try {
json = _transform(xmlNode);
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException(
'Badgerfish internal transform error => ${e.toString()}',
),
stack,
);
}
return json.toString();
}

Map<dynamic, dynamic> _transform(XmlDocument? node) {
final json = <dynamic, dynamic>{};

Expand Down Expand Up @@ -98,16 +114,4 @@ class _Xml2JsonBadgerfish {
process(node, json, <dynamic, dynamic>{});
return json;
}

/// Transformer function
String transform(XmlDocument? xmlNode) {
Map<dynamic, dynamic> json;
try {
json = _transform(xmlNode);
} on Exception catch (e) {
throw Xml2JsonException(
'Badgerfish internal transform error => ${e.toString()}');
}
return json.toString();
}
}
4 changes: 2 additions & 2 deletions lib/src/xml2json_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ part of '../xml2json.dart';
/// This exception is thrown when Xml2Json has an internal error,
/// such as an invalid parameter being passed to a function.
class Xml2JsonException implements Exception {
final String _message;

/// Xml2Json exception
Xml2JsonException([this._message = 'No Message Supplied']);

final String _message;

@override
String toString() => 'Xml2JsonException: message = $_message';
}
32 changes: 17 additions & 15 deletions lib/src/xml2json_gdata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,21 @@ class _Xml2JsonGData {
final String _xmlnsPrefix = '"xmlns"';
final String _cdata = '"__cdata"';

/// GData transformer function.
/// Transformer function
String transform(XmlDocument? xmlNode) {
Map<dynamic, dynamic> json;
try {
json = _transform(xmlNode);
} on Exception catch (e, stack) {
Error.throwWithStackTrace(
Xml2JsonException('GData internal transform error => ${e.toString()}'),
stack,
);
}
return json.toString();
}

// GData transformer function.
Map<dynamic, dynamic> _transform(XmlDocument? node) {
final json = <dynamic, dynamic>{};

Expand Down Expand Up @@ -105,8 +118,9 @@ class _Xml2JsonGData {
final nodeMap = _Xml2JsonUtils.mapProcessingNode(processingString);
for (final i in nodeMap.keys) {
final index = '"$i"';
final sanitisedNodeData =
_Xml2JsonUtils.escapeTextForJson(nodeMap[i]!);
final sanitisedNodeData = _Xml2JsonUtils.escapeTextForJson(
nodeMap[i]!,
);
final nodeData = '"$sanitisedNodeData"';
obj[index] = nodeData;
}
Expand All @@ -116,16 +130,4 @@ class _Xml2JsonGData {
process(node, json, <dynamic, dynamic>{});
return json;
}

/// Transformer function
String transform(XmlDocument? xmlNode) {
Map<dynamic, dynamic> json;
try {
json = _transform(xmlNode);
} on Exception catch (e) {
throw Xml2JsonException(
'GData internal transform error => ${e.toString()}');
}
return json.toString();
}
}
Loading