dingodart 1.0.0
dingodart: ^1.0.0 copied to clipboard
Parser and DOM for the Dingo markup language in Dart
example/main.dart
import 'dart:io';
import '../lib/dingodart.dart';
void main(List<String> arguments) async {
// parse ./test.dml
var doc = parseDocument(await File("./test.dml").readAsString());
// create new tag called <blegh>
var node = TagNode("blegh");
node["attribute"] = "value";
// create two text nodes (one cdata, to demonstrate the different text spacing rules)
node.appendChild(TextNode("weirdly\nspaced\nstring"));
node.appendChild(CdataNode("weirdly\nspaced\nstring"));
// add to document
doc.appendChild(node);
// note that if there is no <embryo/> this section will fail silently
// find <egg> containing <embryo> -- this is an example of the 'query' system
var egg = doc.findTag((e) => e.nameIs("egg").hasChildWhere((e) => e.nameIs("embryo")));
// rename embryo to chick
var chick = egg?.findByName("embryo");
chick?.name = "chick";
// create and add brain
var brain = TagNode("brain");
brain["size"] = "small";
chick?.appendChild(brain);
// print updated source
print(doc.outerSource());
}