libxml2 获取内部 (X)HTML
我有一些示例 XHTML 数据,如下所示:
<html>
<head>
<style type="text/css">
..snip
</style>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.js"></script>
</head>
<body>
<div id="contentA">
This is sample content <b> that is bolded as well </b>
</div>
</body>
</html>
现在,我需要做的是使用 xmlNode *
,获取 div contentA
的内部 HTML。我有它的 xmlNode *
,但是我怎样才能获得它的innerXML?我查看了内容,但只返回 This is example content
而不是粗体标签中的 xml。为此,我研究了 jQuery,但由于 Apple 和 JavaScript 的限制,我无法使用 jQuery 获取该节点的innerXML。
另一方面,我是否应该使用另一个库来获取内部 XML?我查看了 TBXML,但也有同样的问题。
I have some sample XHTML data, like this:
<html>
<head>
<style type="text/css">
..snip
</style>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.js"></script>
</head>
<body>
<div id="contentA">
This is sample content <b> that is bolded as well </b>
</div>
</body>
</html>
Now, what I need to do, is using an xmlNode *
, get the inner HTML of the div contentA
. I have the xmlNode *
for it, but how can I get the innerXML of that? I looked at content, but that only returns This is sample content
and not the xml in the bold tags. I looked into jQuery
for this, but due to limitations on Apple and JavaScript, I cannot use jQuery to get the innerXML of that node.
On another note, Is there another library I should be using to get the inner XML? I looked into TBXML, but that had the same problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
div 节点的内容不是单个文本字符串。它可能包括:
This is example content
的文本节点(带有前面的新行)。b
的元素节点div
结束标签的缩进的文本节点。...
的元素节点将具有粗体文本内容。
要将 div 中的所有文本作为一个字符串获取,您需要递归地向下遍历整个子节点树来查找文本内容。
The content of the div node is not a single text string. It probably consists of:
This is sample content
(with the preceding new line).b
div
's closing tag.The element node for the
<b>...</b>
will have the text contentthat is bolded as well
.To get all the text in the div as one string, you'll need to recursively descend through the entire tree of child nodes looking for text content.