Dart Language and XML package: reading nodes (text contents) -
i have xml file next structure:
<?xml version='1.0' encoding='utf8'?> <root> <row filter="filter string"> // first "row" <id>100</id> <name>some nome here</name> <text>text content here</text> </row> <row filter="filter string"> // sec "row" <id>101</id> <name>some nome here</name> <text>text content here</text> </row> </root>
i'll have lots of rows nodes in 1 xml file , cannot alter structure.
so, xml package, how should proceed in order able text content specific nodes?
for example, text node called "name" sec row.
edit:
so far:
class="lang-dart prettyprint-override">void main() { _readfile("test_utf8.xml").then((xmlcontent) { var parsedxml = parse(xmlcontent); parsedxml.findallelements("row").foreach((row) { // each "row" node iterated here. // read "row" children nodes here. // example: "name"'s text content. }); }); } future _readfile(string filename) { var completer = new completer(); new file(filename).readasstring().then((string xmlcontent) { completer.complete(xmlcontent); }); homecoming completer.future; }
you don't need completer
here
future _readfile(string filename) { // homecoming here achieves same in cases homecoming new file(filename).readasstring(); // because makes method short doen't create much sense // create method }
i haven't tried code according readme.md
of bundle should work this:
void main() { new file("test_utf8.xml").readasstring() .then((xmlcontent) { var parsedxml = parse(xmlcontent); homecoming parsedxml.findelements("root") .first.findelements("row").tolist()[1] .findelements('name').first.text; // <= modified }) .then((text) { print(text); }); }
xml dart dart-async
No comments:
Post a Comment