ios,android不用内置浏览器如何解析html数据并布局
伊谢尔伦
伊谢尔伦 2017-04-17 17:50:10
0
3
369

现在做的这个项目有一个文章详情的页面要显示,文章内容是html代码,有图文,就跟微信公众号的文章一样的。以前都是直接用内置浏览器打开,但现在要求不能用webview打开网页,要使用原生解析html数据并布局?请问苹果和安卓端各有相应的插件可以用吗?或者说有什么好的实现思路?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all (3)
Peter_Zhu

That’s great for you. It probably requires the server to cooperate in parsing the dom structure (if you don’t do it on the front end, the performance may not be good, and the server can still cache it)

I also tried to put simple html in react native (knowing the general structure, there may be nested styles, and all the tags, attributes, and even the order of attributes that will appear are given)

But when I was doing the mixing of p, img, b/blockquote, and a, there was only one layer of nesting. I gave up after an hour of doing it, and I honestly made a WebView to put it in

So the key to the problem is that considering that Java does not have a balanced group, it is painful to use regular expressions to display the elements. It is too tiring to analyze the dom structure without using regular expressions, so if you want to do it, you need a dom parsing library. Get the DOM tree, and then use the DOM tree to convert each element into a native element. . .

Let me just talk about something I encountered. For example, in p, if p has a width set, then if the elements inside are not enough for one line, should they be squeezed below? Or if there are two p without float, will it automatically wrap? , but there is no such thing as
for you to identify when parsing. .

    巴扎黑

    I don’t know personally. If you are not going to display it through webview, why should you use html format? Will it be more efficient through other formats?
    If you need to manually parse the html format, TextView can set the html style, but generally speaking, it is a bit too troublesome to display the corresponding elements one by one, and also set the corresponding attributes for the corresponding style.

      Ty80

      If it’s a mix of images and text, there’s nothing better than webview. If images and texts can be separated, it also depends on your design needs. Generally speaking, Android uses TextView+ImageView, plus combinations such as gridview. Those so-called plug-ins are basically based on these combinations

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!