how do i read xml file value

Issue

this is my XML data file:

<?xml version = "1.0"?>
<contact-info>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</contact-info>

and this is my flutter code:

  Future _xml() async {

              http.Response response = await http.get(Uri.parse(url));
              XmlData = XmlDocument.parse(response.body);
              final wantData = XmlData!.findAllElements('contact-info');

  }

please how i can get the value TutorialsPoint from my xml file

Solution

Use the xml package

import 'package:xml/xml.dart' as xml;
var xmldata='<?xml version = "1.0"?>
<contact-info>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</contact-info>';







void main() {
 
  var contact = xml.parse(xmldata);
  print(contact.findAllElements('phone'));
}

Answered By – Ashutosh singh

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *