パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.1.1

xmlstream

イベント駆動型のXMLパーサーとして、XMLドキュメントをSAX形式でストリーミング解析するための軽量なライブラリです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
16.8万
いいね数
7
Pub ポイント
120

パッケージをインストール

flutter pub add xmlstream

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

xmlstream は、Dart および Flutter 向けの軽量でイベント駆動型の XML パーサーであり、SAX(XML のためのシンプルな API)アプローチを使用して XML ドキュメントを処理します。要素、属性、テキストが検出されるたびに、XML データを段階的にストリーム処理し、イベントを発行します。これにより、ドキュメント全体をメモリに読み込むよりもメモリ使用量を削減でき、大規模なファイル処理において効率的です。リアルタイムでの構造化データの解析やストリーミング XML ソースの処理に最適です。

用途

  • 大規模なXMLファイルを効率的に解析する
  • リアルタイムXMLデータ処理
  • ネットワークリクエストからのXMLのストリーミング
  • 低メモリ環境でのXML処理
  • XML を返す API との統合
  • XMLベースのプロトコルの構築

主な機能

  • イベントベースのパースモデル
  • メモリ使用量が小さい
  • ストリーミング入力をサポートしています
  • SAXスタイルのイベントコールバック
  • クロスプラットフォーム互換性
  • シンプルで直感的な API

適している対象

  • 大規模なXMLデータセットを扱う開発者
  • リアルタイムXML処理を必要とするアプリ
  • メモリ制約のあるプロジェクト
  • XMLフィードを消費するネットワークアプリケーション
  • XML形式の構成ファイルまたはデータファイルを解析するツール

注意事項

  • XML ノードへのランダムアクセスには適していません
  • イベントの処理を手動で行う必要があります
  • 順次解析に限定
  • XML スキーマの組み込みサポートなし
  • 構造よりも順序と流れが重要である場合に最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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);
...

These are the xml states:

  • Top
  • Open
  • Closed
  • Attribute
  • Characters

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

You can add an option to XmlStream to trim space or not, standard he will do this.

var xmlStreamer = new XmlStreamer(rawText, trimSpaces: false);
xmlStreamer.read().listen((e) => print("listen: $e"));
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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。