...." in the ...">

In dart parse HTML string in DOM

In the dart

I want to parse the string " <!DOCTYPE HTMT><html><head></head><body>....</body></html>" in the DOM so that I can manipulate the element in the generated DOM. I know that in jQuery there is $ .parseHTML to handle this. But I can't find anything like this in a dart. Thanks.

(I tried html2lib, but the output cannot use query(".classname")for selection.)

+4
source share
2 answers

Try html5lib . This is a 100% clean dart, so you must be installed.

You can also consider an XML parser for Dart, such as dart-xml , depending on the nature of your HTML.

+2

, HTML:

new Element.html("YOUR HTML STRING HERE");

. Dart: CH03


NodeValidator, , :

NodeValidator nodeValidator = new NodeValidatorBuilder()
    ..allowTextElements();
    // ..allowHtml5()
    // ..allowElement('Button', attributes: ['ng-disabled']);

new Element.html("YOUR HTML STRING HERE", validator: nodeValidator);

, , "element/attribute xxx removed from...", - NodeValidator.

+3

All Articles