搜尋套件、儲存庫與 APP 分類

套件詳情v1.1.1

xmlstream

一個輕量級庫,用於以事件為基礎的XML解析器,以SAX方式解析XML文件。

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-style 事件回調
  • 跨平台相容性
  • 簡單、直覺的 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。