libxml2 get inner (X)HTML
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 x开发者_开发技巧mlNode *
, 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.
The content of the div node is not a single text string. It probably consists of:
- A text node containing
This is sample content
(with the preceding new line). - an element node with a tag name of
b
- A text node containing the trailing new line and the indentation up to the
div
's closing tag.
The element node for the <b>...</b>
will have the text content that 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.
精彩评论