My favorites
▼
|
Sign in
touchcode
Repository of iPhone and iPod Touch source code.
Project Home
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
12
attachment: htmlparser.patch
(1.9 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Index: CXMLDocument.h
===================================================================
--- CXMLDocument.h (revision 78)
+++ CXMLDocument.h (working copy)
@@ -8,6 +8,10 @@
#import "CXMLNode.h"
+enum {
+ CXMLDocumentTidyHTML = 1 << 9
+};
+
@class CXMLElement;
@interface CXMLDocument : CXMLNode {
Index: CXMLDocument.m
===================================================================
--- CXMLDocument.m (revision 78)
+++ CXMLDocument.m (working copy)
@@ -9,18 +9,59 @@
#import "CXMLDocument.h"
#include <libxml/parser.h>
+#include <libxml/HTMLparser.h>
+#include <libxml/HTMLtree.h>
#import "CXMLNode_PrivateExtensions.h"
#import "CXMLElement.h"
@implementation CXMLDocument
+static void htmlparser_error(void *ctx, const char *msg, ...)
+{
+ va_list args;
+ va_start(args, msg);
+ va_end(args);
+}
+
+static void htmlparser_warning(void *ctx, const char *msg, ...)
+{
+ va_list args;
+ va_start(args, msg);
+ va_end(args);
+}
+
- (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError
{
if ((self = [super init]) != NULL)
{
- xmlDocPtr theDoc = xmlParseDoc((xmlChar *)[inString UTF8String]);
-
+ xmlDocPtr theDoc;
+ if ( inOptions & CXMLDocumentTidyHTML )
+ {
+ const char *htmlString = (const char*) [inString UTF8String];
+ int length = xmlStrlen( (const xmlChar*)htmlString );
+ htmlParserCtxtPtr ctx = htmlCreateMemoryParserCtxt(htmlString, length);
+
+ if (! ctx ) {
+ return 0;
+ }
+
+ ctx->vctxt.error = htmlparser_error;
+ ctx->vctxt.warning = htmlparser_warning;
+ if (ctx->sax != NULL)
+ {
+ ctx->sax->error = htmlparser_error;
+ ctx->sax->warning = htmlparser_warning;
+ }
+ htmlParseDocument(ctx);
+ theDoc = ctx->myDoc;
+ htmlFreeParserCtxt(ctx);
+ }
+ else
+ {
+ theDoc = xmlParseDoc((xmlChar *)[inString UTF8String]);
+ }
+
if (theDoc != NULL)
{
_node = (xmlNodePtr)theDoc;
Powered by
Google Project Hosting