xmlstream 0.11.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

xmlstream #

A lightweight api for parsing xml

You can listen to xml encounters and states by parsing the xml char by char.

Simple usage #

The xmlStreamer will send an XmlEvent that will contain the state and value of a specific part of the xml.

See here a simple example how to use it in your application.

var xmlStreamer = new XmlStreamer(rawText);
xmlStreamer.read().listen((e) => print("listen: $e"));

These are the xml states:

  • Top
  • Open
  • Closed
  • Attribute
  • Characters

Namespace and cdate are still on the todo list to support!

Object builder usage #

In this package we provide also the opportunity to build and stream Objects.

If we have the following xml:

<?xml version="1.0" encoding="UTF-8"?>
<item name="flow">world</item>
<item name="text">say what</item>

You see an item object in it. So we want to pump the data in the following object.

class Item {
  String name;
  String value;

  String toString() => "$name - $value";

You can do that by creating a class that extends from XmlProcessor

class ItemProcessor extends XmlProcessor<Item> {
	ItemProcessor() {
		tagName = "item";
	void onOpenTag(String tag) {
 		element = new Item();
  	void onAttribute(String key, String value) {
		if (key == "name") {
  			element.name = value;
	void onCharacters(String text) {
		element.value = text;

Now bootstrap the processing and you are ready to build a list of Items.

var xmlStreamer = new XmlStreamer(rawText);
var xmlObjectBuilder = new XmlObjectBuilder<Item>(xmlStreamer, new ItemProcessor());
xmlObjectBuilder.onProcess().listen((e) => print("listen: $e"));

The listen method will produce Item objects and you can listen to the production of it. If you want to parse an hierachical object structure then you can take a look at XmlParentProcessor class.

In my project on github you will find some examples how to use it. Any suggestions for improvements are welcome.

Ideas #

It is based upon the SAX's and StAX's principles from Java.

Contributing #

If you found a bug, just create a new issue or even better fork and issue a pull request with you fix.

Changelog #

This file contains highlights of what changes on each version of the xmlstream package.

Pub version 0.11.1

  • update description of this package

Pub version 0.11.0

  • update for Dart 2

Pub version 0.10.0

  • update for Dart 1.9

Pub version 0.9.1

  • fix CDATA in xmlprocessor, route it to onText ...

Pub version 0.9.0

  • Add better parsing for comments
  • Adding tests and implementation for CDATA

Pub version 0.8.15

Adding functionality to read a file


import 'package:xmlstream/xmlstream.dart';

void main() {
  print("Hello, World!");
  var rawText = '<?xml version="1.0" encoding="UTF-8"?><hello attr="flow" url="http://static2.demorgen.be/static/photo/2013/5/14/9/20131127210358/media_s_6291969.jpg">world</hello><hello attr="link">http://www.demorgen.be/dm/nl/1005/Meer-Sport/article/detail/1748285/2013/11/27/Scheenbeenbreuk-voor-wereldkampioen-hink-stap-springen.dhtml/</hello><end attr="flow" />';
  var xmlStreamer = new XmlStreamer(rawText);
  xmlStreamer.read().listen((e) => print("listen: $e"));

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  xmlstream: ^0.11.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:xmlstream/xmlstream.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-1 points)

107 out of 107 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/xml/event_stream.dart. (-1.99 points)

Analysis of lib/xml/event_stream.dart reported 4 hints:

line 8 col 37: Unnecessary new keyword.

line 21 col 34: Unnecessary new keyword.

line 26 col 28: Don't type annotate initializing formals.

line 26 col 54: Don't type annotate initializing formals.

Fix lib/xml/xml_streamer.dart. (-1.99 points)

Analysis of lib/xml/xml_streamer.dart reported 4 hints:

line 23 col 19: Unnecessary new keyword.

line 39 col 25: Unnecessary new keyword.

line 87 col 20: Use isNotEmpty instead of length

line 231 col 22: Unnecessary new keyword.

Fix lib/xml/xml_event.dart. (-1 points)

Analysis of lib/xml/xml_event.dart reported 2 hints:

line 8 col 34: Use = to separate a named parameter from its default value.

line 8 col 51: Use = to separate a named parameter from its default value.

Fix additional 6 files with analysis or formatting issues. (-1.50 points)

Additional issues in the following files:

  • lib/xml/xml_object_builder.dart (1 hint)
  • lib/xml/xml_parent_processor.dart (1 hint)
  • lib/xml/xml_processor.dart (1 hint)
  • lib/src/xml_char.dart (Run dartfmt to format lib/src/xml_char.dart.)
  • lib/xml/xml_base_event.dart (Run dartfmt to format lib/xml/xml_base_event.dart.)
  • lib/xml/xml_state.dart (Run dartfmt to format lib/xml/xml_state.dart.)

Maintenance suggestions

Package is getting outdated. (-29.32 points)

The package was last published 67 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.9.0 <3.0.0
Dev dependencies
path ^1.6.2
test >=1.5.1+1 <1.5.2