xmlstream 0.11.1

  • readme.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 76

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<Item>.

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

example/example.dart

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:


dependencies:
  xmlstream: ^0.11.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.11.1 Dec 18, 2018 Go to the documentation of xmlstream 0.11.1 Download xmlstream 0.11.1 archive
0.11.0 Dec 18, 2018 Go to the documentation of xmlstream 0.11.0 Download xmlstream 0.11.0 archive
0.10.0 Apr 2, 2015 Go to the documentation of xmlstream 0.10.0 Download xmlstream 0.10.0 archive
0.9.1 Nov 26, 2014 Go to the documentation of xmlstream 0.9.1 Download xmlstream 0.9.1 archive
0.9.0+1 Jun 25, 2014 Go to the documentation of xmlstream 0.9.0+1 Download xmlstream 0.9.0+1 archive
0.9.0 Jun 25, 2014 Go to the documentation of xmlstream 0.9.0 Download xmlstream 0.9.0 archive
0.8.15 Feb 25, 2014 Go to the documentation of xmlstream 0.8.15 Download xmlstream 0.8.15 archive
0.8.14 Feb 19, 2014 Go to the documentation of xmlstream 0.8.14 Download xmlstream 0.8.14 archive
0.8.13 Feb 18, 2014 Go to the documentation of xmlstream 0.8.13 Download xmlstream 0.8.13 archive
0.8.12 Feb 17, 2014 Go to the documentation of xmlstream 0.8.12 Download xmlstream 0.8.12 archive

All 41 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:xmlstream/xmlstream.dart.

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/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 lib/xml/xml_streamer.dart. (-0.50 points)

Analysis of lib/xml/xml_streamer.dart reported 1 hint:

line 87 col 20: Use isNotEmpty instead of length

Format lib/src/xml_char.dart.

Run dartfmt to format lib/src/xml_char.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/xml/event_stream.dart (Run dartfmt to format lib/xml/event_stream.dart.)
  • lib/xml/xml_base_event.dart (Run dartfmt to format lib/xml/xml_base_event.dart.)
  • lib/xml/xml_object_builder.dart (Run dartfmt to format lib/xml/xml_object_builder.dart.)
  • lib/xml/xml_parent_processor.dart (Run dartfmt to format lib/xml/xml_parent_processor.dart.)
  • lib/xml/xml_processor.dart (Run dartfmt to format lib/xml/xml_processor.dart.)
  • lib/xml/xml_state.dart (Run dartfmt to format lib/xml/xml_state.dart.)

Dependencies

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