我正在使用libxml2解析HTML,使用XPath查找元素。一旦我找到了需要的元素,如何从该元素中获取HTML字符串(需要注意该元素将有许多子元素)?给定一个文档:
<html>
<header>
<title>Some document</title>
</header
<body>
<p id="faq">
Some kind of text <a href="http://www.nowhere.com/">here</a>.
</p>
</body>
</html>
假设我使用XPath检索到了
body
元素,然后获取该元素的HTML内容,我希望最终得到一个包含以下字符串的字符串:<body>
<p id="faq">
Some kind of text <a href="http://www.nowhere.com/">here</a>.
</p>
</body>
我该怎么做?