In dart,
I want to parse a string "<!DOCTYPE HTMT><html><head></head><body>....</body></html>
" to a DOM so that I can manipulate element in the generated DOM. I know in JQuery, there is $.parseHTML to deal with it. But I can not find anything similar in dart.
Thank you.
(I have tried html2lib, but the output Document cannot use query(".classname")
to select.)
You can create an element by parsing HTML text:
see Dart: Up and Running CH03
EDIT
You may need to pass a NodeValidator to get the entire text rendered like:
If you run the application you get log messages like "element/attribute xxx removed from ..." if some of the text was not accepted by the NodeValidator.
Try html5lib. It's 100% pure Dart, so you should be set.
You could also consider an XML parser for Dart like dart-xml depending on the nature of your HTML.
Check out this article in dart documentation
You can use this for dart
and carryout parsing like this
In case of flutter, you have to add the "html" package in the pubspec.yaml below the cupertino_icons dependency like this for example
and then the dart file you have to import it like
and then carry out parsing as before but remember to add the alias name before each method!