패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.1.1

xmlstream

이벤트 기반의 XML 파서를 스트리밍하여 XML 문서를 SAX 방식으로 파싱하는 가벼운 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
16.8만
좋아요
7
Pub 점수
120

패키지 설치

flutter pub add xmlstream

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

xmlstream은 Dart와 Flutter용 가벼운 이벤트 기반 XML 파서로, SAX(Simple API for XML) 방식을 사용하여 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.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.