GDTyka
GDTyka

Reputation: 530

xml library Flutter error when i use findAllElements on XmlDocument file that be kept in List

I have a few Xml files that i save in assets folder. I need data from them so i made a cycle that add to variable xmlList data from this files. I need to get data from attributes in one of Elements in my xml file so i wrote this code

static List xmlList = [];
    List filePathList = ['assets/data/widow.xml','assets/data/door.xml'];
    // filePathList need to make a cycle, i got files correctly
  Future<void> getXmlData() async{
      for(int i = 0;i<filePathList.length;i++){
        var xmlFile =  XmlDocument.parse(await rootBundle.loadString(filePathList[i]));
        xmlList.add(xmlFile);
        // xmlList has correct data in it
      }
      var data = xmlList[0].findAllElements('CheckList');
      // this line above comment got error
      for(var element in data){
        print(element.attributes[1].value);
        // this is cycle to get data from attributes, it work fine if i will use this code 'data = xmlFile.findAllElements('ChekList');'
      }
  }

but i got this error Unhandled Exception: NoSuchMethodError: Class 'XmlDocument' has no instance method 'findAllElements'.

Upvotes: 0

Views: 260

Answers (1)

GDTyka
GDTyka

Reputation: 530

Need to add XmlDocument to xmlList type

static List<XmlDocument> xmlList = [];

Upvotes: 1

Related Questions