Flutter - How to fetch data from remote XML file in Flutter

1.5k views Asked by At

Flutter : I'm trying to fetch data from a remote XML file on a webserver in Flutter.

I already wrote a PHP code to generate xml file from my database rows.

I'd like to fetch and display data from the Xml in the Application Please i need some help!

2

There are 2 answers

1
Ali Yazdi On

Have you seen this dart package.

It helps you to work with xml files. It is a lightweight library for parsing, traversing, querying, transforming and building XML documents.

I hope it will be useful.

0
Z_Z On

I found something. You can try this code. With using xml2json converter Goole data

import 'dart:convert';

import 'package:xml2json/xml2json.dart';
import 'package:http/http.dart' as http;

Future<List> rssToJson(String category, {String baseUrl = 'https://www.hindustantimes.com/rss/'}) async {
  var client = http.Client();
  final myTranformer = Xml2Json();
  return await client.get(baseUrl + category + '/rssfeed.xml').then((response) {
    return response.body;
  }).then((bodyString) {
    myTranformer.parse(bodyString);
    var json = myTranformer.toGData();
    return jsonDecode(json)['rss']['channel']['item'];
  });
}