Android XML 解析器
我有一个巨大的 HTML 文件,如下所示:
<html>
<head>
</head>
<body>
<div id="wraper">
<div id="..."> </div>
<div id="..."> </div>
<div id="..."> </div>
<div class="col x8 black">
<div class="sidebar">
<script .../>
<script .../>
<div class="side-box last10">
<h3 .../>
<ul class="sidebarlist">
<li class="fisrt"> Need this Text </li>
<li> Need this Text too (1) </li>
<li> Need this Text too (2) </li>
</ul>
</div>
</div
</div>
</body>
如何在这个 html 文件中“导航”以获取我想要的文本?
html->body->div#wraper->div#col x8 black-> div#side-vox last10-> ul#sidebarlist -> li#first
对于这项工作,DOM 和 SAX 哪个更好? (我的母语不是英语)
I have a huuge HTML File, somthing like this:
<html>
<head>
</head>
<body>
<div id="wraper">
<div id="..."> </div>
<div id="..."> </div>
<div id="..."> </div>
<div class="col x8 black">
<div class="sidebar">
<script .../>
<script .../>
<div class="side-box last10">
<h3 .../>
<ul class="sidebarlist">
<li class="fisrt"> Need this Text </li>
<li> Need this Text too (1) </li>
<li> Need this Text too (2) </li>
</ul>
</div>
</div
</div>
</body>
How can I get "navigate" in this html file to get the text i want?
html->body->div#wraper->div#col x8 black-> div#side-vox last10-> ul#sidebarlist -> li#first
For this job, what is better DOM or SAX ? (I`m not a native English speaker)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您考虑过 XPath 吗?您的伪代码:
...直接转换为以下 XPath 表达式:
或者,更简洁(假设示例中的结构具有代表性):
有关在 Android 上使用 XPath 的信息可以在此处找到:
Have you considered XPath? Your pseudo-code:
...translates directly into the following XPath expression:
Or, more succinctly (assuming the structure in your example is representative):
Information about using XPath on Android can be found here:
您可以使用 XmlPullParser 来执行此操作。请通过以下代码:
you can can XmlPullParser for doing that. Please go through the below code: