I have an XML file with the following structure:
<?xml version='1.0' encoding='UTF8'?>
<root>
<row filter="FILTER STRING"> // THIS IS THE FIRST "ROW"
<id>100</id>
<name>Some nome here</name>
<text>TEXT CONTENT HERE</text>
</row>
<row filter="FILTER STRING"> // THIS IS THE SECOND "ROW"
<id>101</id>
<name>Some nome here</name>
<text>TEXT CONTENT HERE</text>
</row>
</root>
I'll have lots of rows nodes in just one XML file and I cannot change this structure.
So, with XML package, how should I proceed in order to be able to get the text content from specific nodes?
For example, I would like to get the text from the node called "name" from the SECOND ROW.
EDIT:
So far:
void main() {
_readFile("test_UTF8.xml").then((xmlContent) {
var parsedXml = parse(xmlContent);
parsedXml.findAllElements("row").forEach((row) {
// EACH "ROW" NODE WILL BE ITERATED HERE.
// READ "ROW" CHILDREN NODES HERE.
// FOR EXAMPLE: GET "NAME"'S TEXT CONTENT.
});
});
}
Future _readFile(String filename) {
var completer = new Completer();
new File(filename).readAsString().then((String xmlContent) {
completer.complete(xmlContent);
});
return completer.future;
}
You probably don't need a
Completer
hereI haven't actually tried this code but according to the
README.md
of the package it should work like this: