3
A
答えて
9
libxml2 HTMLパーサを使用すると、「汚れた」HTMLが正規化されたツリーに正規化されます。 私が原因知識の欠如にそんなにトラブルに直面したhtmlDocPtr htmlParseFile(const char * filename, const char * encoding)
4
を参照してください。ですから、私はlibxml2ライブラリを使ってHTMLを解析するデモプログラム全体を書いています。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/HTMLparser.h>
void traverse_dom_trees(xmlNode * a_node)
{
xmlNode *cur_node = NULL;
if(NULL == a_node)
{
//printf("Invalid argument a_node %p\n", a_node);
return;
}
for (cur_node = a_node; cur_node; cur_node = cur_node->next)
{
if (cur_node->type == XML_ELEMENT_NODE)
{
/* Check for if current node should be exclude or not */
printf("Node type: Text, name: %s\n", cur_node->name);
}
else if(cur_node->type == XML_TEXT_NODE)
{
/* Process here text node, It is available in cpStr :TODO: */
printf("node type: Text, node content: %s, content length %d\n", (char *)cur_node->content, strlen((char *)cur_node->content));
}
traverse_dom_trees(cur_node->children);
}
}
int main(int argc, char **argv)
{
htmlDocPtr doc;
xmlNode *roo_element = NULL;
if (argc != 2)
{
printf("\nInvalid argument\n");
return(1);
}
/* Macro to check API for match with the DLL we are using */
LIBXML_TEST_VERSION
doc = htmlReadFile(argv[1], NULL, HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET);
if (doc == NULL)
{
fprintf(stderr, "Document not parsed successfully.\n");
return 0;
}
roo_element = xmlDocGetRootElement(doc);
if (roo_element == NULL)
{
fprintf(stderr, "empty document\n");
xmlFreeDoc(doc);
return 0;
}
printf("Root Node is %s\n", roo_element->name);
traverse_dom_trees(roo_element);
xmlFreeDoc(doc); // free document
xmlCleanupParser(); // Free globals
return 0;
}
+0
私はlibxml2-2.7.8.win32を使用したことをユーザーに知らせたいと思います。 –
関連する問題
- 1. Qtのプログラミング:どのようにWebKitの
- 2. C++によるLEDAプログラミング:
- 3. FPGAをC言語のようにプログラミングできますか?
- 4. C#のようなイベントがDプログラミング言語にあります
- 5. どのようにC#の
- 6. どのようにC#の
- 7. どのようにC#の
- 8. どのようにC#とC++のdll
- 9. はどのように、C
- 10. どのようにC#
- 11. どのようにC#アプリケーション
- 12. は、どのようにC++
- 13. はどのようにC++
- 14. Cプログラミングのセグメンテーションフォールト
- 15. C/C++でのステガノグラフィアプリケーションのプログラミング
- 16. CGIプログラミングをどのように同期させますか?
- 17. XCODEによる純粋なObjective Cプログラミング?
- 18. VHDLとCによるFPGAプログラミング
- 19. Amazon CloudプログラミングによるJavaのプログラミング
- 20. C/C++ Vistaでのプログラミング
- 21. ゲームボーイC言語のプログラミングC
- 22. Windows GUIのC++プログラミング
- 23. WindowsでのCプログラミング
- 24. C#.netプログラミングのアニメーション
- 25. LinuxでのC++プログラミング
- 26. linux BluetoothプログラミングのC
- 27. MFCプログラミングでのC++
- 28. GNUのMakefile、Cプログラミング
- 29. CでのDirectXプログラミング?
- 30. のxrandrは、Cプログラミング
oh〜それは役に立ちます。ありがとう、^ _^ –
^^^ upvoteボタンがあります;) –