开发者

Should I use DomDocument for parsing html code

I have tried my best to answer this question myself through research but I am still a little bit worried about whether I am using the right thing. Basically I am using the 开发者_Go百科DomDocument Library to build a jQuery like theme parser for my framework. Now with the web as it is today HTML is coming in different shapes and sizes e.g HTML 4, HTML 5, XHTML, XHTML 5 etc ... The issue that I am finding with DomDocument is that if you give it HTML code it will only work with it if it is standards compliant XHTML. I know it can convert it into XHTML and I can use the tidy library to make the code acceptable but my main worry is: what if a developer using my framework has a theme that uses all the cool(debatable) new HTML 5 features, as soon as he passes it to my framework it will either throw a tantrum or convert it down to XHTML which would suck.

So my question is: Is DomDocument the most convenient library for what I need?

or

Is there a way of getting it to work with all the different variants of HTML?


DOMDocument can parse non-XHTML files. Just set the proper switches:

    libxml_use_internal_errors ( true );

    $dom = new DOMDocument;
    $dom -> formatOutput = true;
    $dom -> substituteEntities = false;
    $dom -> recover = true;
    $dom -> strictErrorChecking = false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜