XML 데이터를 JSON 형식으로 변환하는 Flutter/Dart 패키지로, Badgerfish, GData, OpenRally, Parker 등 다양한 변환 표준을 지원합니다. XML을 사용하는 API 및 서비스와 원활하게 통합할 수 있도록 하며, 더 접근하기 쉬운 JSON 구조로 변환합니다. 가볍고 크로스플랫폼 사용을 위해 설계되어 Android, iOS, Web, macOS, Windows, Linux용 앱에 적합합니다. XML 응답을 받는 애플리케이션에서 데이터 파싱을 간소화합니다.
사용 사례
XML API 응답 파싱
레거시 XML 데이터를 JSON으로 변환
XML 기반 웹 서비스와의 통합
크로스 플랫폼 앱에서 데이터 처리 간소화
XML에서 JSON 워크플로로의 마이그레이션
주요 기능
여러 가지 XML에서 JSON로의 변환 스타일을 지원
경량이며 통합이 쉬움
크로스 플랫폼 호환성
중첩된 XML 구조를 처리합니다
사용자 정의 가능한 변환 옵션을 제공합니다
적합한 대상
XML API를 사용하는 개발자
데이터 변환을 필요로 하는 앱
XML에서 JSON으로 마이그레이션하는 프로젝트
풀스택 Dart 개발자
구조화된 데이터를 사용하는 모바일 및 웹 애플리케이션
고려 사항
변환 동작은 스타일(예: Badgerfish, GData 등)에 따라 다릅니다
입력 XML의 검증이 필요할 수 있습니다
사전 처리 없이 복잡한 XML 스키마에는 적합하지 않습니다
출력 구조는 선택한 변환 방법에 따라 달라집니다
XML에서 JSON으로만 제한됨, 역방향 기능 없음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
xml2json
An XML to JSON conversion package.
This package allows the parsing of XML strings and the transformation of the resulting parse
tree into the following XML JSON conventions :-
Parker(optionally with attributes)
Badgerfish
Google Data(GData).
OpenRally
The package uses the xml parser to perform the parsing of XML data into a parse tree.
Exact transforming rules can be found below.
The Parker convention is a lossy but lean conversion from XML into JSON, ideal for lightweight
XML parsing of collections of books, records etc. where attributes and namespace information
is not needed.
Badgerfish and GData both preserve XML information such as attributes and namespaces. These are more
suited to heavyweight XML parsing of say ATOM feeds where this information may be needed.
See the main Xml2Json class for usage.
Xml2Json - details of the JSON output of the transformers
The rules each transformer uses are documented below, following that a global rules section describes
rules all the transformers obey.
Parker
The Parker transformer follows the rules documented here with the following caveats :-
Similar named consecutive elements are grouped under the name of the element, not
anonymously in an array as in the rules above, so :-
This allows grouped elements to be extracted by name in one go, i.e. from above all the
items can be referenced through the 'item' property. This is better for the usage this transform
is suited to, the parsing of simple list like structures of books, records etc that just happen to
be in XML.
There is also an alternative Parker transformer that transforms node elements that have attributes.
The standard Parker transformer should suffice for most use cases.
Badgerfish
The Badgerfish transformer follows the rules documented here, to summarise :-
Element names become object properties
Text content of elements goes in the $ property of an object.
Nested elements become nested properties
Multiple elements at the same level become named array elements.
Attributes go in properties whose names begin with @.
Multiple attributes at the same level become array elements.
Active namespaces for an element go in the element's @xmlns property.
The default namespace URI goes in @xmlns.$.
Other namespaces go in other properties of @xmlns.
Elements with namespace prefixes become object properties, too.
The @xmlns property goes only in the object relative to the element where namespace was declared.
Badgerfish also has the option of using local xml node names by setting the useLocalNameForNodes parameter to true
when transforming.
This has the effect that since the element key("soapenv" in the example below) is implementation dependent (i.e. one manufacturer
will assign "soapenv as the key, while another might assign "ENV"), using the key in the node name makes the
resulting json from xml2json dependent on the implementation as well.
This is the Google Data(GData) format specified here
This is basically the same as Badgerfish except that it drops the @ symbol for attributes and
uses $t instead of just $ for values, also the XML Processing element is included at the top of the
transform.
This is basically the same as Badgerfish except that it drops the @ symbol for attributes and
uses (key/value) format for values, also the XML Processing element is included at the top of the
transform.
Global Rules
Each transformer implements the following rules :-
All JSON output is in the form of strings, numeric literals, true and false become strings.
This allows the output to be 'transmission ready' if needed for RESTful interfaces.
XML Comments are ignored.
CDATA sections are ignored for Parker but translated into '__cdata' properties
for Badgerfish and GData