lubi lubi - 4 months ago 27
Dart Question

dart xml with external files

I've been able to follow all the examples of dart-xml but that is only for a dart file containing xml in a variable. How to i parse and create external xml files?

If I try and import an xml file directly dart usually gets stuck on the first character of the xml file '<'.

How would I write the given example from dart-xml https://github.com/renggli/dart-xml? I can print it to the shell using

print(bookshelfXml.toString());


but how to i save || pipe it to an external file? I've tried to use dart:io a little but not having any success at the moment.

Answer

This should do what you want:

import 'dart:io';

...

var file = new File('path/to/file.xml');
file.writeAsString(bookshelfXml.toString());

See also: