1

There is a .xml file that I want to turn into/read as String in order to then parse it as XML.

How can I achieve that in Flutter?

ex. xml file: https://www.cbar.az/currencies/16.03.2020.xml

1
  • Did you try making an http get request to that url? Commented Mar 16, 2020 at 14:32

1 Answer 1

2

This Dart xml library can parse such files. There is an example included that downloads and parses IP address metadata, very similar to your example file. The tutorial contains further examples of how to read files:

final file = new File('bookshelf.xml');
final document = XmlDocument.parse(file.readAsStringSync());

Or download data:

final HttpClient httpClient = HttpClient();
final url = Uri.parse('http://ip-api.com/xml/');
final request = await httpClient.getUrl(url);
final response = await request.close();
final stream = response
    .transform(utf8.decoder)
    .transform(const XmlEventDecoder())
    .transform(const XmlNormalizer())
    .expand((events) => events)
    .forEach((event) => print(event));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.