GDTyka
GDTyka

Reputation: 530

How to get data from attribute in xml file Flutter xml library

this is a one of many line from my xml document, and i need to get data from 'requirement' attribute, how i can do this?

<ChekList id="001440142173280" requirement="SOME DATA THERE"/>

and this is code that i got now

Future<String> getXmlData() async{
var document =  XmlDocument.parse(await rootBundle.loadString('assets/data/widow.xml'));
document.toXmlString();
var data = document.findAllElements('ChekList');
}

Upvotes: 0

Views: 952

Answers (1)

Lukas Renggli
Lukas Renggli

Reputation: 8947

The method getAttribute gives you attribute values, i.e.

var data = document.findAllElements('ChekList')
  .map((chekListElement) => chekListElement.getAttribute('requirement'));

For other accessors (and extension methods) have a look at the element class documentation.

Upvotes: 2

Related Questions