html_xml_parser 0.1.0

  • Readme
  • Changelog
  • Installing
  • 48

A Dart library for parsing HTML or XML into Dart objects, Map, json string and vice-versa.

Usage #

To use this plugin, add html_xml_parser as a dependency in your pubspec.yaml file.

Library overview #

Checkout the Elements class to understand available elements.

* RootNode -> Start of the markup. It holds children.
* ElementNode -> tag should be specified(ex: div). Supports attributes and children.
* TextNode -> It is the text at appeares inside a HTML/Markup tag.
* CommentNode -> It is a comment that can be place in between elements,
* Attribute -> `Name`, `value` should be given. `valueOriginal` is optional, It is used in creating markup.
Checkout the MarkupUtils class which contains many utils for conversion.

* Node mapToNode(Map<String, dynamic> json)
* Node jsonToNode(String jsonString) 
* Node markup2json(String markupString)
* String jsonToMarkup(String jsonString)
* String mapToMarkup(Map<String, dynamic> jsonMap)

Examples #

Markup to dart object #

Here Markup in string format is converted to dart object.

import 'package:html_xml_parser/html_xml_parser.dart';

main() {
  var markup = """
      <!DOCTYPE html>
          <meta charset="UTF-8">

  Node node = MarkupUtils.markup2json(markup);

      node); //{"type":"root","children":[{"type":"element","tag":"html","children":[{"type":"element","tag":"head","children":[{"type":"element","tag":"meta","attributes":[{"name":"charset","value":"UTF-8","valueOriginal":"\"UTF-8\""}]},{"type":"element","tag":"title","children":[{"type":"text","text":"title"}]}]},{"type":"element","tag":"body"}]}]}

JSON to markup #

Convert JSON to markup. JSON should this type of syntax only.

import 'package:html_xml_parser/html_xml_parser.dart';

main() {
  String jsonString = r"""
    "type": "root",
    "children": [{
        "type": "element",
        "tag": "html",
        "children": [{
            "type": "element",
            "tag": "head",
            "children": [{
                "type": "element",
                "tag": "meta",
                "attributes": [{
                    "name": "charset",
                    "value": "UTF-8",
                    "valueOriginal": "\"UTF-8\""
            }, {
                "type": "element",
                "tag": "title",
                "children": [{
                    "type": "text",
                    "text": "title"
        }, {
            "type": "element",
            "tag": "body"
  String markup = MarkupUtils.jsonToMarkup(jsonString);

  print(markup);//<html><head><meta charset="UTF-8"/><title>title</title></head><body/></html>

Create or edit markup #

Create or edit existing markup Node tree.

import 'package:html_xml_parser/html_xml_parser.dart';

main() {
  Node node = RootNode([
    ElementNode(tag: "message", children: [
      ElementNode(tag: "text", children: [TextNode("Hello!!")]),
      ElementNode(tag: "from", children: [TextNode("Manoj sadhu")]),
      CommentNode("A simple comment")

  String markup = node.toMarKup();
  print(markup); //<message><text>Hello!!</text><from>Manoj sadhu</from><!--A simple comment--></message>

      ElementNode(tag: "time", children: [TextNode("18-06-2019 09:18:00")]));

  String editedMarkup = node.toMarKup();
  print(editedMarkup); //<message><text>Hello!!</text><from>Manoj sadhu</from><!--A simple comment--></message><time>18-06-2019 09:18:00</time>

Features and bugs #

Please file feature requests and bugs.

0.1.0 #

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  html_xml_parser: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:html_xml_parser/html_xml_parser.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and html_xml_parser.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0