pub repository
mirror.p-hatan.irxml
7.1.0Full-featured XML for Dart — DOM parsing, SAX streaming, XPath 3 querying, and a fluent builder API.
Readme
Dart XML
Pub Package Build Status Code Coverage GitHub Issues GitHub Forks GitHub Stars GitHub License
Dart XML is a lightweight, full-featured XML and XPath library for Dart and Flutter.
- DOM Model: In-memory document tree with navigation, querying, mutation, standard W3C position comparison, and customizable serialization.
- XPath 3.1 & XDM: W3C-compliant query engine supporting expressions, standard functions and operators, serialization (
fn:serialize), XML Schema regular expressions, JSON integration, and native maps and arrays. - Event-Driven Streaming (SAX): Push- and pull-based event streaming via Dart
IterableandStreamAPIs for memory-efficient processing of arbitrary large documents. - Fluent Builder: Declarative, type-safe builder API for constructing XML documents and fragments.
- Zero Overhead: Fast and portable across Dart VM, Flutter, and Web (Wasm & JavaScript), built on PetitParser.
Installation
Add xml as a dependency to your pubspec.yaml or run:
dart pub add xml
Import the primary XML library:
import 'package:xml/xml.dart';
[!TIP] This library makes extensive use of static extension methods. Avoid using import prefixes or selective
showclauses that hide extension members. For collision avoidance, public DOM classes carry anXmlprefix.
Reading and Writing
Parse XML into an XmlDocument tree using XmlDocument.parse():
final bookshelfXml = '''<?xml version="1.0"?>
<bookshelf>
<book>
<title lang="en">Growing a Language</title>
<price>29.99</price>
</book>
<book>
<title lang="en">Learning XML</title>
<price>39.95</price>
</book>
<price>132.00</price>
</bookshelf>''';
final document = XmlDocument.parse(bookshelfXml);
If the document is malformed, an XmlParserException (subclass of XmlException) is thrown with exact line and column coordinates.
Serialization and Pretty Printing
Serialize any node back to XML using toString() or toXmlString():
// Compact serialization:
print(document.toString());
// Formatted pretty printing with custom indentation:
print(document.toXmlString(pretty: true, indent: ' '));
File I/O
Read files using dart:io:
import 'dart:io';
final file = File('bookshelf.xml');
final document = XmlDocument.parse(file.readAsStringSync());
For large files that should not be fully buffered into memory, use the streaming event-driven API.
Traversing and Querying
Accessors and Mutation
Nodes provide mutable lists for structural manipulation:
attributes: Attributes declared on this node.elementAttributes: Attributes excluding namespace declarations (xmlnsorxmlns:*).children: Direct child nodes of this node.
Lists support standard List methods (add, addAll, insert, remove). Inserting nodes automatically detaches them from any existing parent and moves them into position. Fragments (XmlDocumentFragment) are expanded in-place.
Traversal Axes
Navigate the DOM along document order axes:
descendants: All descendants in document order (attributes, child elements, text, etc.).ancestors: Preceding ancestor chain up to the root (reverse document order).siblings: Sibling nodes at the same tree level.preceding: Nodes preceding the opening tag of the current node in document order.following: Nodes following the closing tag of the current node in document order.
Convenience getters filter these axes for element nodes only: childElements, descendantElements, ancestorElements, siblingElements, precedingElements, and followingElements.
// Extract all text content from the document:
final text = document.descendants
.whereType<XmlText>()
.map((node) => node.value.trim())
.where((str) => str.isNotEmpty)
.join('\n');
Element Searching
Find elements by tag name:
getElement(String name): First direct child element with matching name, ornull.findElements(String name): Direct child elements matching name.findAllElements(String name): Recursive descendants matching name.
// Find all titles:
final titles = document.findAllElements('title')
.map((element) => element.innerText);
// ['Growing a Language', 'Learning XML']
// Calculate the total book prices:
final total = document.findAllElements('book')
.map((book) => double.parse(book.findElements('price').single.innerText))
.reduce((a, b) => a + b);
print(total); // 69.94
Node Comparison & Document Position
Compare nodes using standard DOM Level 3 / DOM 4 semantics:
// Structural equality comparison:
final isSame = nodeA.isEqualNode(nodeB);
// Bitmask position comparison:
final position = nodeA.compareDocumentPosition(nodeB);
if (position.isPreceding) {
print('nodeA precedes nodeB in document order');
}
XPath 3.1 & XDM
PetitXml includes a comprehensive, high-performance W3C XPath 3.1 implementation.
To enable XPath on DOM nodes, import:
import 'package:xml/xpath.dart';
Node Selection (xpath)
XmlNode.xpath(String expression) evaluates an expression and returns a lazy Iterable<XmlNode>:
// Find all books:
final books = document.xpath('/bookshelf/book');
// Find the second book (1-based index):
final secondBook = document.xpath('/bookshelf/book[2]');
// Find elements by attribute value:
final englishTitles = document.xpath('//title[@lang="en"]');
// Predicate with relative path:
final englishBooks = document.xpath('//book[title/@lang="en"]');
Full XDM Evaluation (xpathEvaluate)
XmlNode.xpathEvaluate(String expression) evaluates expressions returning an XPathSequence containing nodes, atomic values, functions, maps, or arrays:
// Evaluate XPath functions directly:
final totalPrice = document.xpathEvaluate('sum(//book/price)').single;
print(totalPrice.toValue()); // 69.94
// Count matching nodes:
final bookCount = document.xpathEvaluate('count(//book)').single;
print(bookCount.toValue()); // 2
// String and regex operations:
final joined = document.xpathEvaluate('string-join(//title, ", ")').single;
print(joined.toValue()); // 'Growing a Language, Learning XML'
Reverse XPath Generation
Generate a canonical XPath expression leading to any node in the document:
final title = document.findAllElements('title').first;
print(title.xpathGenerate()); // /bookshelf/book[1]/title
Configuration and Extensibility
Pass an XPathConfiguration to customize variables, extension functions, namespaces, and document loaders:
final config = XPathConfiguration.standard(
variables: {'taxRate': 0.08},
namespaces: {'bk': 'https://example.com/books'},
);
final result = document.xpathEvaluate(
'//book/price * (1 + \$taxRate)',
configuration: config,
);
Building XML
The XmlBuilder class provides a declarative, fluent API to construct XML structures programmatically:
final builder = XmlBuilder();
builder.processing('xml', 'version="1.0"');
builder.element('bookshelf', nest: () {
builder.element('book', nest: () {
builder.element('title', nest: () {
builder.attribute('lang', 'en');
builder.text('Growing a Language');
});
builder.element('price', nest: 29.99);
});
builder.element('book', nest: () {
builder.element('title', nest: () {
builder.attribute('lang', 'en');
builder.text('Learning XML');
});
builder.element('price', nest: 39.95);
});
builder.element('price', nest: 132.00);
});
final document = builder.buildDocument();
Modular builder methods can be composed to assemble nested document fragments:
void buildBook(XmlBuilder builder, String title, String lang, num price) {
builder.element('book', nest: () {
builder.element('title', nest: () {
builder.attribute('lang', lang);
builder.text(title);
});
builder.element('price', nest: price);
});
}
final builder = XmlBuilder();
buildBook(builder, 'The War of the Worlds', 'en', 12.50);
buildBook(builder, 'Voyages extraordinaires', 'fr', 18.20);
// Attach the generated fragment into an existing tree:
document.rootElement.children.add(builder.buildFragment());
Event-Driven Streaming
For large files or streaming network sources where buffering an entire DOM tree in memory is impractical, use the event-driven SAX parser:
import 'package:xml/xml_events.dart';
Lazy Iterables
Parse an XML string incrementally on-demand:
parseEvents(bookshelfXml)
.whereType<XmlTextEvent>()
.map((event) => event.value.trim())
.where((text) => text.isNotEmpty)
.forEach(print);
Asynchronous Streams
Process asynchronous streams from files or HTTP connections using stream transformers:
final file = File('large_sitemap.xml');
await file.openRead()
.transform(utf8.decoder)
.toXmlEvents()
.normalizeEvents()
.selectSubtreeEvents((event) => event.name == 'loc')
.toXmlNodes()
.expand((nodes) => nodes)
.forEach((node) => print(node.innerText));
Hierarchical Context & Namespaces
Enable withParent: true and withNamespace: true to annotate events with parent linkages and resolved namespace URIs:
const shiporderXsd = '''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>''';
await Stream.fromIterable([shiporderXsd])
.toXmlEvents(withNamespace: true, withParent: true)
.normalizeEvents()
.selectSubtreeEvents((event) =>
event.localName == 'element' &&
event.namespaceUri == 'http://www.w3.org/2001/XMLSchema')
.toXmlNodes()
.expand((nodes) => nodes)
.forEach((node) => print(node.toXmlString(pretty: true)));
Command-Line Tools & Examples
The repository includes runnable command-line applications in the example/ directory:
-
XPath Query Tool: Evaluate XPath 3.1 expressions against files or inline computations:
dart run example/xml_xpath.dart -x "//book/title" example/books.xml dart run example/xml_xpath.dart "1 + 2 * 3" -
Pretty Printer & Highlighter: Format and colorize XML files in the terminal:
dart run example/xml_pp.dart example/books.xml -
Source Position Locator: Determine character positions and line numbers for DOM nodes:
dart run example/xml_pos.dart example/books.xml -
Online Demo: Try the interactive parser in your browser at the PetitParser Web Demo.
Standards Compliance
PetitXml conforms to the following official W3C specifications:
- Extensible Markup Language (XML) 1.0 (Fifth Edition)
- Namespaces in XML 1.0 (Third Edition)
- XML Path Language (XPath) 3.1
- XPath and XQuery Functions and Operators 3.1
- W3C DOM4 / DOM Level 3 Core
Scope and Limitations
- Schema Validation: Does not validate against XML Schema (XSD) definitions.
- DTD Enforcement: Basic DTD parsing is supported (
XmlDoctype), but external DTD entity resolution and validation are not enforced. - XSLT / XQuery: XSLT transformations and full XQuery modules are outside the scope of this package.
History & License
Dart XML originated as an example parser for the PetitParser framework and replaced the original dart-xml package in April 2014.
Released under the MIT License.
Changelog
Changelog
7.1.0
- Dart 3.13 and PetitParser 7.1.0 requirement.
- Standard-compliant DOM position comparison:
- Introduced
XmlNode.compareDocumentPositionreturningXmlDocumentPositionbitmask flags (isSame,isDisconnected,isPreceding,isFollowing,isContains,isContainedBy,isImplementationSpecific), matching W3C DOM Level 3 / DOM 4. - Deprecated
XmlNode.compareNodePositionin favor ofcompareDocumentPosition.
- Introduced
- XML attribute and namespace separation:
- Added
XmlAttribute.isNamespaceDeclarationto distinguish namespace declarations (xmlnsorxmlns:*) from regular attributes. - Added
elementAttributesgetter onXmlAttributesBaseandXmlHasAttributesto iterate over attributes excluding namespace declarations.
- Added
- XPath 3.1 enhancements and W3C compliance:
- Excluded namespace declarations from the attribute axis (
@*), aligning with XPath 3.1 specification. - Restored document order for reverse-indexed axes with predicates.
- Implemented canonical EQName path generation in
fn:path(/Q{uri}name[idx],@Q{uri}name,text()[idx]). - Improved ID and IDREF resolution in
fn:id,fn:idref, andfn:element-with-idwithxml:idand DTD<!ATTLIST ... ID/IDREF>attribute declarations. - Introduced
XPathConfigurationto configure evaluation contexts (custom variables, functions, namespaces, documents, environment variables, base URI, unparsed text loader, and trace callback). Deprecated passingvariablesandfunctionsdirectly toxpathandxpathEvaluate. - Added XML serialization (
fn:serialize) supporting XML, HTML, XHTML, text, JSON, and adaptive output methods with serialization parameters. - Added PetitParser-based regular expression transformer for XML Schema regex syntax supporting
fn:matches,fn:replace,fn:tokenize, andfn:analyze-string. - Added
fn:parse-ietf-date. - Standardized error handling with
XPathErrorCodeand W3C error codes. - Redesigned date, time, and duration types (
xs:duration,xs:dayTimeDuration,xs:yearMonthDuration,xs:dateTime,xs:date,xs:time, and Gregorian date types) for strict W3C compliance. - Added support for
xs:anyAtomicType,xs:error, and string-derived XML Schema constructors. - Added support for unparsed text and JSON document retrieval (
fn:unparsed-text,fn:unparsed-text-lines,fn:unparsed-text-available,fn:json-doc) viaunparsedTextLoader. - Added context-aware document lookup (
fn:doc,fn:doc-available) and cross-platform environment variable resolution (fn:environment-variable,fn:available-environment-variables). - Added support for key sequences and native Dart
MapandListstructures in lookup expressions (?). - Integrated maps and arrays into dynamic function calls.
- Added duration support in aggregation functions (
fn:avg,fn:sum). - Protected arithmetic and math functions (
fn:ceiling,fn:floor, duration operations) againstInfinityandNaN. - Significant XPath evaluation performance optimizations:
- Preserved document order on absolute paths (
/,//), avoiding redundant sorting and deduplication fallbacks. Yields up to 775x speedup on large documents (e.g., at $N=10,000$,//*is ~775x faster dropping from 3.75s to 4.8ms;/root/item/nameis ~609x faster dropping from 840ms to 1.38ms;//itemis ~307x faster dropping from 870ms to 2.84ms). - Introduced two-tier node sorting with direct sibling indexing in DOM position comparisons for queries requiring deduplication.
- Collapsed
DescendantOrSelfAxis+ChildAxisintoDescendantAxisfor steps with non-positional predicates (e.g.,//item[@id=100]is ~5.75x faster). - Cached small
XPathIntegerinstances (0..128) and unboxed integer comparisons for zero-allocation positional predicate matching with early-exit loop termination. - Optimized sequence atomization with zero-allocation fast paths for empty and single-item sequences, along with primitive 1-vs-1 comparison fast paths.
- Preserved document order on absolute paths (
- Fix short-circuit evaluation for
!=general comparisons (#207). - Removed
@experimentalannotation from XPath API.
- Excluded namespace declarations from the attribute axis (
- Add command-line XPath evaluation example tool (
example/xml_xpath.dart).
7.0.1
- Better namespace support across all parts of the library:
- Namespaces of
XmlDocument.parseandXmlDocumentFragment.parseare now resolved at parse-time and constant when manipulating the DOM (this aligns with other XML libraries and removes surprising behavior when moving nodes around). - Deprecate all
namespacearguments and replace them with the more intention revealingnamespaceUriandnamespacePrefix. - Lower-level parser and event APIs can now enable and disable the validation and resolution of namespaces with
validateNamespacesandwithNamespaces. This is a BREAKING CHANGE to existing code using these lower-level APIs, as namespaces are no longer available by default. - Introduced
XmlNamespaceExceptionfor error reporting of invalid namespaces. XmlNameis now immutable and the complexity with different states is gone.- Added
XmlNamespacenode type andXmlHasNamespacesmixin to support reading in-scope namespaces on nodes.
- Namespaces of
- Correctly move nodes from their previous parent when inserting them into a new location, rather than throwing an
XmlParentException. This aligns with standard DOM behavior and improves usability and performance.XmlDocumentFragmentnodes are automatically expanded and their children are moved as well. - Improved performance and usability of
XmlBuilder:- Significantly improve the performance of
XmlBuilderas all namespace lookups are now in constant time. - Deprecated
namespace(String uri, String? prefix)andnamespaces(Map<String, String?> uriToPrefix)accessors that have an unusually awkward API. Replaced withnamespaceUri(String? prefix, String? uri)andnamespaceUris(Map<String, String> prefixToUri)with a clear prefix-uri order. - Deprecated
String? namespacearguments when definition elements and attributes. Replaced with more flexibleString namespacePrefixandString namespaceUri.
- Significantly improve the performance of
- Comprehensive XPath 3.1 support:
- Complete execution model supporting sequences of items (nodes, atomic values, functions, maps, and arrays).
- New expressions and operators: String concatenation (
||), range (to), quantified (some/every), loops (for), simple map (!), lookup (?), and node comparison (is,<<,>>). - Support for Higher-Order Functions: Inline, named, and arrow functions, inclusive of partial function application and dynamic binding with
fn:function-lookup. - Native support for XPath Data Model (XDM) maps and arrays, including associated JSON and sequence functions.
- Added support for EQName parsing (
Q{uri}name). - Add missing XPath name tests (namespace prefix, namespace URI, local name, and wildcards) and node tests (
attribute(),document-node()andelement()). - Significantly improve XPath evaluation performance for large documents (thanks to laishere).
- Fix issues with XPath axis parsing, reverse axis access, and predicate expressions (thanks to laishere).
- Update to PetitParser 7.0.2.
6.6.1
- Dart and Flutter 3.9 compatibility.
- Minor optimization to eliminate unused namespaces.
6.6.0
- Dart 3.8 and PetitParser 7.0 requirement.
- Correct decoding of names with surrogate characters.
6.5.0
- Add support for most XPath 1.0 functions, including set-operations and ensuring document order for node-sets.
- Add support for XPath expression evaluation, user-defined variables, and user-defined functions.
- Add
XmlNode.xpathGenerateto create a readable XPath for all nodes. - Add support for node comparison:
XmlNode.isEqualNodeandXmlNode.compareNodePosition.
6.4.0
- Dart 3.0 and PetitParser 6.0 requirement.
- Add RSS feed reader example.
6.3.0
- Upgrade to Dart 2.19 and PetitParser 5.4.
- Add
XmlElement.tagconstructor that greatly simplifies the creation of elements, i.e.XmlElement(XmlName('br'), [], [], true)becomesXmlElement.tag('br', isSelfClosing: true). - Deprecate the ambiguous
XmlNode.text: Replace withXmlNode.valueto access the textual contents of the node, orXmlNode.innerTextto access the textual contents of its descendants. - Fix
XmlNode.siblingsand various related methods to also work correctly onXmlAttributenodes, make the method return a mutable list. - Improve
XmlNode.replace(XmlNode)and addXmlNode.remove()for easy removal of a node. - Improve error position propagation when building the XML DOM.
- Make the parser more forgiving when reading attributes.
- Experimental support of a subset of XPath.
- Add new-line normalization support.
6.2.0
- Upgrade to PetitParser 5.1 brings a 10% speed improvement (typed sequences).
- Add the ability to tap into a stream of
XmlEventwithtapEachEvent(similar toforEachEvent). - Remove
XmlNameequality operator==andhashCode. This is inconsistent with the other DOM nodes, and the provided implementation might not have the desired behavior. - Improved error reporting when accessing
innerTextorinnerXmlon DOM nodes that cannot have children.
6.1.0
- Dart 2.17 requirement.
- Validate the presence and order of root nodes when parsing; this got lost in 6.0.0 and can now also optionally be enabled for streaming and iterable parsers.
- Add support for basic document type parsing. The contents of the
XmlDoctypecan now be accessed throughname,externalIdandinternalSubset.
6.0.0
- Significantly improve parsing performance by up to 30%.
- Improved error handling to include more information, such as tag names and location in the parsed source.
- Use the pull-based parser for all underlying parsing operations:
- Reduce size of library by removing duplicated parsing and validation functionality.
- Fix entity decoding if the entity spawns multiple chunks.
- Cleanup dynamic calls and type declarations:
- Avoid all dynamic calls across the library (thanks to srawlins).
- Remove deprecated
XmlTransformeras it requires dynamic calls in theXmlVisitor. - Cleanup the dynamic typing of
XmlVisitor.
XmlBuilderkeeps keeps correct nesting, even in case of exceptions.- Remove deprecated code:
parse(String input): useXmlDocument.parse(String input)orXmlDocumentFragment.parse(String input)instead.XmlBuilder.build(): useXmlBuilder.buildDocument()orXmlBuilder.buildFragment()instead.XmlNormalizer.defaultInstance: useconst XmlNormalizer()instead.XmlProductionDefinition,XmlGrammarDefinition, andXmlParserDefinition.
5.4.0
- Dart 2.16 requirement.
- Update to PetitParser 5.0.
- Escape control characters (thanks to rspilker).
- Add a predicate to pretty printer to insert a space character before self-closing elements (thanks to rspilker).
- Add predicates to normalizer to trim leading and trailing whitespaces, as well as collapse consecutive whitespaces.
- Expose
qualifiedName,localName,namespacePrefixandnamespaceUrifor convenience on the named nodes.
5.3.0
- Dart 2.15 requirement.
- Upgrade to PetitParser 4.3.
5.2.0
- A series of read-only accessors that simplify navigating the XML DOM with
XmlElements:- Add
XmlNode.childElements. - Add
XmlNode.siblingsandXmlNode.siblingElements. - Add
XmlNode.previousElementSiblingandXmlNode.nextElementSibling. - Add
XmlNode.ancestorElements,XmlNode.precedingElements,XmlNode.descendantElements, andXmlNode.followingElements.
- Add
5.1.1
- Fix printing of Exceptions.
- Fix parsing of DOCTYPE tags.
5.1.0
- Upgrade to PetitParser 4.1.0.
5.0.0
- Dart 2.12 requirement and null-safety.
- Add the possibility to
XmlBuilderto add raw strings. - Improve error reporting (particularly for fragment parsing).
- Default entity mapping is now a global setting.
- Improve tutorials and documentation.
4.5.0
- Fixed a bug in the XML name parsing where certain unicode planes were not correctly recognized.
- Removed const constructor from
XmlEventto be able to add a lazy initializedparentEventfield. - Add
XmlWithParentEventsthat provides validation of event nesting and efficient access to the parent events. Usestream.withParentEvents()to annotate the stream accordingly. - Add namespace resolution to events through
event.namespaceUri. Note that the data is only available when the parent information is present (see above). - Fix namespace resolutions for events in selected sub-tree nodes, even if the namespace declaration is not part of the visible DOM.
- Add
stream.forEachEvent(onText: ...)for easier callback based stream processing.
4.4.0
- Add a
XmlSubtreeSelectorthat allows efficient filtering of events in specific sub-trees. Usestream.selectSubtreeEvents(...)to filter the stream accordingly. - Add more options to XML pretty printer, namely the possibility to sort and indent attributes.
- Add typed extension methods for all stream converters, for simpler and more fluent API.
- Improvements to documentation and examples.
4.3.0
- Improve error reporting of
XmlBuilderand add possibility to buildXmlDocumentFragments. - Improvements to documentation and examples.
4.2.0
- Deprecate standalone
XmlDocument parse(String input)method, and introduce factory methods in the respective nodesXmlDocument.parse(String input)andXmlDocumentFragment.parse(String input). - Introduce getters and setters for
XmlNode.innerText(in most cases an alias toXmlNode.text),XmlNode.innerXmlandXmlNode.outerXml. - Improved support for
XmlDocumentFragmentacross the library. - Remove the
XmlDocument.textoverride, which returnednull. - Add
XmlNode.replace(XmlNode other)to make it easier to replace nodes in an existing tree. - Add
XmlNode.getElement(String name)as a shortcut to find the first child element with a given name. - Add
XmlNode.firstElementChildandXmlNode.lastElementChildto easy access the first/last child element. - Add support to selectively disable whitespace normalization while pretty-printing, for example
document.toXmlString(pretty: true, preserveWhitespace: (node) => node is XmlElement && node.name.local == 'pre')would keep everything within<pre>tags as-is.
4.1.0
- Improve the pretty printing and the customization of the pretty printing:
XmlWriterandXmlPrettyWriterare now initialized with optional arguments.- Pretty printing now also supports to customize the newline support.
- Example is updated to also syntax highlight / colorize the output.
- Add full namespace support to attribute accessors
setAttributeandremoveAttribute. - Improved the documentation, particularly started a section on
xml_eventspackage.
4.0.0
- Cleanup the node hierarchy. Specifically removed
XmlOwnedandXmlParentthat added a lot of complexity and confusion. Instead, introduced dedicated mixins for nodes with attributes (XmlHasAttributes), children (XmlHasChildren), names (XmlHasName) or parents (XmlHasParent). - Introduce
XmlDeclarationnodes, events and builder to make accessing XML version and encoding simpler.
3.7.0
- Update to PetitParser 3.0.0.
- Dart 2.7 compatibility and requirement.
3.6.0
- Entity decoding and encoding is now configurable with an
XmlEntityMapping. All operations that read or write XML can now (optionally) be configured with an entity mapper. - The default entity mapping used only maps XML entities, as opposed to all HTML entities as in
previous versions. To get the old behavior use
XmlDefaultEntityMapping.html5. - Made
XmlParserErroraFormatExceptionto follow typical Dart exception style. - Add an example demonstrating the interaction with HTTP APIs.
3.5.0
- Dart 2.3 compatibility and requirement.
- Turn various abstract classes into proper mixins.
- Numerous documentation improvements and code optimizations.
- Add an event parser example.
3.4.0
- Dart 2.2 compatibility and requirement.
- Take advantage of PetitParser fast-parse mode:
- 15-30% faster DOM parsing, and
- 15-50% faster event parsing.
- Improve error messages and reporting.
3.3.0
- New events based parsing in
xml_events:- Lazy event parsing from an XML string into an
IterableofXmlEvent. - Async converters between streams of XML,
XmlEventandXmlNode.
- Lazy event parsing from an XML string into an
- Clean up package structure by moving internal packages into the
src/subtree. - Remove the experimental SAX parser, the event parser allows more flexible streaming XML consumption.
3.2.4
- Remove unnecessary whitespace when printing self-closing tags.
- Remember if an element is self-closing for stable printing.
3.2.0
- Migrated to PetitParser 2.0
3.1.0
- Drop Dart 1.0 compatibility
- Cleanup, optimization and improved documentation
- Add experimental support for SAX parsing
3.0.0
- Mutable DOM
- Cleaned up documentation
- Dart 2.0 strong mode compatibility
- Reformatted using dartfmt
2.6.0
- Fix CDATA encoding
- Migrate to micro libraries
- Fixed linter issues
2.5.0
- Generic Method syntax with Dart 1.21
2.4.5
- Do no longer use
ArgumentError, but instead use proper exceptions.
2.4.4
- Fixed attribute escaping
- Preserve single and double quotes
2.4.3
- Improved documentation
2.4.2
- Use enum as the node type
2.4.1
- Fixed attribute escaping
2.4.0
- Fixed linter issues
- Cleanup node hierarchy
2.3.2
- Improved documentation
2.3.1
- Improved test coverage
2.3.0
- Improved comments
- Optimize namespaces
2.2.2
- Formatted source
2.2.1
- Cleanup pretty printing
2.2.0
- Improved comments
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add xmlpubspec.yaml
name: xml
version: 7.1.0
description: Full-featured XML for Dart — DOM parsing, SAX streaming, XPath 3 querying, and a fluent builder API.
repository: https://github.com/renggli/dart-xml
screenshots:
- description: 'XML for Dart'
path: xml.png
topics:
- xml
- dom
- sax
- xpath
- builder
environment:
sdk: ^3.13.0
dependencies:
args: ^2.7.0
collection: ^1.19.1
meta: ^1.19.0
petitparser: ^7.1.0
dev_dependencies:
lints: ^6.1.0
test: ^1.31.2Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2012-09-25T01:24:58.330770Z | Download | 7b26c71a383b87d4ebf08294e23e1713b8fd0ed366fd0362d19f564a98b48009 |
| 0.1.0 | 2012-10-29T19:51:55.780960Z | Download | e228f5c2c7af7cc065242ec4337c2ab17fbced57d904e912cb5271d10f344bbe |
| 0.1.3 | 2012-11-30T01:25:57.297180Z | Download | 29d18c7f72c44611eb7daa03d3ef80028899ce08ca8886818055193c17f1061c |
| 0.1.5 | 2012-12-10T23:00:58.796990Z | Download | 575f96f80ef650cb8d552e2695e0c8028726cf01d9112da96994120386715072 |
| 0.1.6 | 2012-12-17T20:47:22.456410Z | Download | 30dc633c7415fc271dd9d2ffd935dcfdaa63ce3486f7bf25d9194c50539d3fdd |
| 0.9.0 | 2013-02-18T21:12:37.621220Z | Download | 7ff3db2d2dd9e9242ea62207d0e6b5a777b4b2b44244acec810a348b1767878d |
| 0.9.2 | 2013-03-07T20:25:24.844700Z | Download | 87b5351de1f60018a5d23632eaf919165a5e083bd55245545a6eadc8a46861e7 |
| 0.9.3 | 2013-03-20T21:13:34.367480Z | Download | 2b2ad085f4a61c66ee8803aa74303bd362bce9390d235b1b79ea33ed101a5a22 |
| 0.9.3+1 | 2013-04-27T19:35:42.290130Z | Download | 86c5a92170691886b8e5edd75812abb42f3c6906d124ba72a40f0180bba865be |
| 0.9.3+2 | 2013-05-07T20:24:33.481260Z | Download | ba2264540756d8fb761c8e113968104fe817cbc265381f02c5bb7c086cab59e1 |
| 0.9.3+3 | 2013-08-30T22:23:44.997900Z | Download | 705e078d53609076d24e234eee10f7179d55bd636b67e26c156c44a6772910e8 |
| 0.9.3+4 | 2013-08-31T16:24:53.353270Z | Download | bf9d6c2de30832a39a909dc5fa65b521a4fb34bd0062207f5210ecda5245b0fb |
| 0.9.3+5 | 2013-08-31T17:19:01.368040Z | Download | 0b3b072ecaf3431326f6de2ab83bad20b454b8b3a854740d7937e56cbfd0c252 |
| 0.9.3+6 | 2013-09-10T20:22:24.286110Z | Download | bd4331158827996c36f37523d5404cd55bfb1fa79d3529ae16b1539b03986851 |
| 0.9.4 | 2013-09-28T17:40:21.278480Z | Download | 37502b0f766ea750f95d7d46e749a44fed26a616a6b6ed90113e22a4e9da5dd2 |
| 0.9.5 | 2013-10-26T20:59:39.984890Z | Download | 6face9cb0dfda6df11faf29368ee1d5cab8ddd6e6ac0511fc2a6cece74296e72 |
| 1.0.0 | 2014-03-03T02:08:50.577240Z | Download | d70c11b248591a6fd4bd619f7a65ebb9d48322b25f46caeee9386812e398bdf6 |
| 2.0.0 | 2014-04-21T13:39:50.574320Z | Download | 4d876b185a041bf73312aa847d50eaf6ef0e73a6b27c583cfbf302805e12a763 |
| 2.1.0 | 2014-05-18T14:19:59.070930Z | Download | 65f3b8b8e8a85c6e81cc99ef50947246d52448f1c2e894ea3b7009c4ef8d126d |
| 2.1.1 | 2014-05-22T16:53:51.676430Z | Download | 9a457ad2584bb781ad6105da85eb174eb41c415053c435c50e02d3adcf843ddb |
| 2.1.3 | 2014-07-06T08:36:08.215320Z | Download | e2c8a0ec819b1300f8eb6d968bfdf6791d5c1006063e501d83ba02abc11da4d4 |
| 2.1.4 | 2014-08-16T10:38:49.175370Z | Download | bbf37b8538e4ef0331dc209bd953b683b42e767846719e31ff5e26bfce15d05f |
| 2.1.5 | 2014-09-06T21:03:10.664670Z | Download | 25fd7f6b2502a5ac3d578ac676e148e9595a8f6c95d83d067d24351433e5d5f2 |
| 2.1.6 | 2014-11-14T19:27:39.558730Z | Download | 8092f729a74e0b780b7642ceaa9d42b9f92c29951205b14526de1d6bd9fe2dd7 |
| 2.1.7 | 2014-11-15T14:05:57.259510Z | Download | 12058d13b1ee3d2b2ef3adc69d7070b2e4a091204416c421750c6b80d5335adb |
| 2.2.0 | 2014-11-29T08:29:11.267750Z | Download | 88f4cec54f992cc3025140f0a91baddec1aa688207cc22e443f7c75906ceb18d |
| 2.2.1 | 2014-12-14T10:55:24.935730Z | Download | 82ca7e28158b991a1ab9bd35b59226d92ecc806b04bfb21d2fcd9abd19a4b59f |
| 2.2.2 | 2015-01-23T20:54:07.639310Z | Download | d159e6d7cc856596f6ec18d747beff9aefd570e806f64dff1a1fef70fd398222 |
| 2.2.3 | 2015-02-02T23:10:34.560720Z | Download | 3d05764a76767cb039c8400a09db0aa6cf981da127f8a38c075f40cc677ac184 |
| 2.3.0 | 2015-05-15T15:54:31.194Z | Download | b9509111a43f071037b0bbf7d1efd9bb0a1341bfbf27661b3b5da75834c611d1 |
| 2.3.1 | 2015-05-15T16:07:10.900Z | Download | 372cd7044a5387e5651e1140c4ceee243dbdf613348d6771ca54a67c4e0209cc |
| 2.3.2 | 2015-05-15T17:38:33.135Z | Download | dde4c15db95114f59444cf0c4e1e94a1c12e111f6f97177f0417c77e85a4f700 |
| 2.4.0 | 2015-10-06T18:18:29.207Z | Download | fe3d69548a898a2de31327ff6c3bbb6148b2bdc2b301473b6aeef1bbfd1c1ea8 |
| 2.4.1 | 2016-01-17T10:10:10.246Z | Download | 5eee59bbe5b9fb4c375a803239f062633eba0bcbf5d747bba5b067f37c2c29e0 |
| 2.4.2 | 2016-03-07T15:50:26.122Z | Download | ae7c382c270dc8986d0df5433f3c433f63109e817d42523a820d9576b380a3c2 |
| 2.4.3 | 2016-04-05T09:23:39.861Z | Download | 21021658c125784f4c9d1ad7379aa73020808875ca409153ff618a41960d4f38 |
| 2.4.4 | 2016-11-24T10:32:35.380Z | Download | 91da53df032406dccf88c691c2fff944638be4b60d5884d666f8497acb5e6b5e |
| 2.5.0 | 2016-12-19T17:09:50.949Z | Download | 2032b1e16e93a4370e40334475ada1550f6070939e1855716cdf848130e9bc83 |
| 2.6.0 | 2017-08-04T18:36:20.536009Z | Download | 19049ef7e4c329e6be5b32d69886f35e9b7c74050c368e9b9210d40c72b85a01 |
| 3.0.0-alpha | 2017-12-19T19:29:12.235405Z | Download | cfaec34af17c2b72d937781fd358963c01349893237b01114b6ebec94a4a6ffd |
| 3.0.0 | 2018-03-10T11:08:24.098405Z | Download | 27b1b3905d9de4026b0abc11d6b8f1d342cd319a855899b14dd58b06d091b073 |
| 3.0.1 | 2018-07-21T14:16:22.882374Z | Download | 382c0094263113d6e124d80a597e0aa62d8b86ac398b558499bf116e31cf0cfc |
| 3.2.0 | 2018-08-01T19:00:28.058334Z | Download | 3f7fac285ff44c8222a403d72214e8b93bd3f5ded4d23c2765e17aaac32d127e |
| 3.2.1 | 2018-09-15T16:31:32.366801Z | Download | 2e8dd8d05be1779f4b821aeddd399b4ed615a2e172055921f91b017ed1d19e36 |
| 3.2.2 | 2018-09-27T10:43:32.190543Z | Download | c82b2784de7f2bda08442db6c160fe57b0bb0068d11e73f459a04faa748f30f7 |
| 3.2.3 | 2018-09-27T11:16:04.113973Z | Download | 65ced2d31b3b014ccce3e86b66a48f67524d819029663ce333bb4dca47500234 |
| 3.2.4 | 2019-01-07T21:41:18.603156Z | Download | 5b14486552a1f2bcbc4d9d8236425e8454ddec0d6df3a355b868f9e324373de7 |
| 3.2.5 | 2019-01-08T17:19:09.720548Z | Download | 875ea607302f08409350ca41f2629c108b15a9754fd1188a0b46bc88b8d55421 |
| 3.3.0 | 2019-01-24T15:38:10.339555Z | Download | e2b0670f340410ad55da514b3d1cd5f08f2fa9529bd1cd9d106074e25dba8eed |
| 3.3.1 | 2019-01-28T16:52:46.941578Z | Download | c48d9d7a430a64ceb87c09c298e0c7010f69c511648e53c1dab3de6230e0566d |
| 3.4.0 | 2019-02-27T22:27:11.249561Z | Download | 6a97d6ea454dd48ce669477b3ac00fa98e2ab6f77c57689e6e2223696730dfbd |
| 3.4.1 | 2019-03-07T06:21:39.957976Z | Download | 61f0538f19867cff9aebf885bd74fe7eaf531a69885c64b0a87b4148fb6782f3 |
| 3.5.0 | 2019-05-10T13:37:16.405676Z | Download | 3a42822cbfa529f8294e6aa1bb941a264161afa469f5dfa54c6f2ea8f2703f4d |
| 3.6.0 | 2019-11-30T23:14:53.027563Z | Download | d9e33a640ada4197a9ddc71da51fbd307e37cf15f9d25ed5ef9970aaaaa6ad93 |
| 3.6.1 | 2019-12-10T06:52:06.429234Z | Download | 8501c1516b03e10ea0adb38531188e0d2817a58f734b1c1f579f4db5465e1b6b |
| 3.7.0 | 2020-01-01T10:06:05.079336Z | Download | a11fbb305f75dd200c96d3fd13f9fdb4bc8d8dcdb5331f6ba15c57acb950ef09 |
| 4.1.0 | 2020-03-30T17:36:13.184636Z | Download | 77ac18e95b9b58fff42b5feec8fa1cc21f9c46f1394f244de5452ff314696a4f |
| 4.2.0 | 2020-05-29T17:29:56.218350Z | Download | 2b3cb58e5a6b93b99b8d3591539a3ed8192f0e52c050ba92b6e472c916ce3d85 |
| 4.3.0 | 2020-07-18T10:18:03.398262Z | Download | 92dffba70672b1a69f5dabb9b81b7a6e507737102cd1e365b8d1b1089f6f34b7 |
| 4.4.0 | 2020-08-16T19:43:00.741845Z | Download | ba9c1a18a909a7f283408d2a80f8fb63f809c8a9cc164b599203b396dec6c7dc |
| 4.4.1 | 2020-08-18T20:28:30.733315Z | Download | ff2f3b882851cc23e4c32b7cc3193b33fbe988aa0a2b7d2fc9ede6f545894170 |
| 4.5.0 | 2020-09-04T09:58:33.884988Z | Download | 1238316e1f90eacb56208e1c788bbb24d2801ca7773a9b6d7ed38ea9a1de43b4 |
| 4.5.1 | 2020-09-17T21:39:15.234755Z | Download | 4c4262c7dcf7b66fa8743cdfd37ccac03d6d50d3de4084b1a528de3107540752 |
| 5.0.0-nullsafety.1 | 2020-11-21T08:05:05.403331Z | Download | 8a7cc6f9ee52310f9b2759ae7818860108b66c78d2c501561a1cdc3a5de3e961 |
| 5.0.0 | 2021-02-17T22:22:20.369535Z | Download | 583426a617c5423a6863a23b6e6cc676f0a0174c38f4fd36de9c6895237ab77f |
| 5.0.1 | 2021-02-19T11:00:02.768855Z | Download | 77139ce98484bfaf6a7bb58a7094541c12f0b06ab962ca31f1c156b4e53ba3c1 |
| 5.0.2 | 2021-02-19T13:37:44.340685Z | Download | d212eabbd5066ceba6b5187a2ae89a86c609fbba160876b493f2f5db684f0190 |
| 5.1.0 | 2021-04-05T15:53:58.773619Z | Download | 88d26fad429944d29b7c418177d156d04bbef049f295cf48130eccc84f0b8b4b |
| 5.1.1 | 2021-05-20T16:47:06.537252Z | Download | 9d2cf96b38e3f523fb78f0102d1d4483f817f3c3a6d81f46bf1b7a430ae8d561 |
| 5.1.2 | 2021-06-05T12:40:05.210038Z | Download | 30498604ab00fc50286f8aaf7e077c496550b16ed2f325c14152244882314f03 |
| 5.2.0 | 2021-08-14T08:30:53.456770Z | Download | 925e1d7923773fef2f90c5c9ad0f496630f63e03f974a0aaa5fb50c60640c570 |
| 5.3.0 | 2021-09-10T18:46:38.993940Z | Download | 78bc0a9ed038e65944b95f4c5d3a72a607d63e1a9f1e8281fa0cfe9d2811c279 |
| 5.3.1 | 2021-10-16T08:30:07.743586Z | Download | baa23bcba1ba4ce4b22c0c7a1d9c861e7015cb5169512676da0b85138e72840c |
| 5.4.0 | 2022-03-18T18:54:08.313962Z | Download | abc002d0490fc4a74bca4356fca2629323a2595964cfd403f6aa4d120ea07502 |
| 5.4.1 | 2022-03-19T10:37:30.678247Z | Download | 80d494c09849dc3f899d227a78c30c5b949b985ededf884cb3f3bcd39f4b447a |
| 6.0.0 | 2022-03-28T08:50:07.302357Z | Download | db7540c353cbf172e6532cae806f0ed31b938fc0cace3f01ac5707418b7553b4 |
| 6.0.1 | 2022-03-28T08:56:08.620876Z | Download | 6d1e8d8641b1b4675a2f6ec0d0c6b519a472f0a4f0a2aa8a63d08b64383ee87a |
| 6.1.0 | 2022-05-25T08:26:26.056977Z | Download | ac0e3f4bf00ba2708c33fbabbbe766300e509f8c82dbd4ab6525039813f7e2fb |
| 6.2.0 | 2022-10-23T15:28:24.514859Z | Download | 1a235945f0831980f690291fe7744e440d73acb20fc18b923cea373f391a2837 |
| 6.2.1 | 2022-11-08T21:25:50.213162Z | Download | 0be2cc68212206ab22f700a706782f79a303fb7d4b51279ac394bcc5545f273f |
| 6.2.2 | 2022-11-10T08:00:56.961262Z | Download | 979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5 |
| 6.3.0 | 2023-04-24T11:46:02.421859Z | Download | 5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84 |
| 6.4.0 | 2023-08-17T19:32:01.088703Z | Download | b477e76184eaf1ea0a11ebf4b3d937631693b8ea143c759146c4cd512438442d |
| 6.4.1 | 2023-08-20T09:46:03.292341Z | Download | 6a8c45d77aa090cff0380283d4d552761a3f3f6f69b4cbd950cbfcefbeb003a2 |
| 6.4.2 | 2023-08-20T10:03:58.369917Z | Download | af5e77e9b83f2f4adc5d3f0a4ece1c7f45a2467b695c2540381bac793e34e556 |
| 6.5.0 | 2023-12-02T17:36:14.361226Z | Download | b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 |
| 6.6.0 | 2025-06-15T15:17:35.334041Z | Download | 3202a47961c1a0af6097c9f8c1b492d705248ba309e6f7a72410422c05046851 |
| 6.6.1 | 2025-08-16T12:56:36.310706Z | Download | 971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025 |
| 7.0.0 | 2026-04-25T09:10:48.036664Z | Download | 2d19c24548c25ea11ed02bfe6d9e0dffe8460aac66231f5174ca970f14b5cc62 |
| 7.0.1 | 2026-04-25T17:34:36.413972Z | Download | 67f0aff7be013d107995e9b75bf4e7f2c3ef2dfdb2c8e68024bba0a7fd5756a4 |
| 7.1.0 | 2026-09-27T14:39:32.170674Z | Download | 0fe8cc98946def31cbcbc8734aa4067031e6f65ea3a78a508060bfed2200bfeb |
Dependencies
args "^2.7.0"
collection "^1.19.1"
meta "^1.19.0"
petitparser "^7.1.0"