fixed some warnings
[TestXSLT.git] / XMLParserLibxml.m
index a76d6f8..7078d04 100644 (file)
                errorMessage = [[NSMutableString alloc] init];
                errorLine = 0;
                errorOccurred = NO;
-               xmlContext = NULL;
+               //xmlContext = malloc(sizeof(xmlParserCtxt));
+               //bzero(xmlContext, sizeof(xmlParserCtxt));
                parsedXmlDoc = NULL;
                baseUri = NULL;
                
        }
-
+       
        return self;
 }
 
 - (void)dealloc {
 
        [errorMessage release];
+       [baseUri release];
 
        if (parsedXmlDoc) {
                xmlFreeDoc(parsedXmlDoc);
+//             free(xmlContext);
        }
 
        
@@ -128,10 +131,13 @@ void makeUnixLineFeeds(char *buffer) {
        
 }
 
+/*
 
-- (BOOL)checkWellFormedString:(NSString *)xmlCode {
+- (BOOL)checkWellFormedData:(NSData *)xmlCode {
 
-       char *xmlString = (char *)[xmlCode cString];
+       // fixme: using nsdata now, not null-terminated. maybe replace with expat.
+       return YES;
+       char *xmlString = (char *)[xmlCode bytes];
        //const char *xmlString = [stringData bytes];
        int error = 0;
 
@@ -148,8 +154,8 @@ void makeUnixLineFeeds(char *buffer) {
         */
                
 
-       xmlContext = xmlCreateDocParserCtxt(xmlString);
-       
+//     xmlContext = xmlCreateDocParserCtxt(xmlString);
+       /*
        if (!xmlContext) {
                return NO;
        }
@@ -174,49 +180,35 @@ void makeUnixLineFeeds(char *buffer) {
                return YES;
        }
 
-
+        
 }
 
+*/
 
 
 
-- (BOOL)parseString:(NSString *)xmlCode {
+- (BOOL)parseData:(NSData *)xmlCode {
 
-       char *xmlString = (char *)[xmlCode cString];
-       int error = 0;
-
-       makeUnixLineFeeds(xmlString);
+//     int error = 0;
 
-       xmlContext = xmlCreateDocParserCtxt(xmlString);
+//     makeUnixLineFeeds(xmlString);
 
     xmlSubstituteEntitiesDefault(1);
        xmlLoadExtDtdDefaultValue = 1;
 
-       if (!xmlContext) {
-               return NO;
-       }
-
-
        [self clearError];
        xmlSetGenericErrorFunc(self, (xmlGenericErrorFunc)XMLParserLibxml_xmlErrorHandler);
 
-       error = xmlParseDocument(xmlContext);
-
-
        if (parsedXmlDoc) {
                xmlFreeDoc(parsedXmlDoc);
        }
-
-       parsedXmlDoc = xmlContext->myDoc;
-
        
-       xmlFreeParserCtxt(xmlContext);
-       xmlContext = NULL;
+       parsedXmlDoc = xmlParseMemory([xmlCode bytes], [xmlCode length]);
 
-       if (error != XML_ERR_OK) {
+       if (!parsedXmlDoc) {
                return NO;
        }
-
+       
        if ([self baseUri] != nil) {
                xmlNodeSetBase((xmlNodePtr)parsedXmlDoc, (xmlChar *)[[self baseUri] cString]);
        }
@@ -230,9 +222,9 @@ void makeUnixLineFeeds(char *buffer) {
 
 - (void)markFirstErrorLine {
 
-       if (errorLine == 0 && xmlContext && xmlContext->input) {
-               errorLine = xmlContext->input->line;
-       }
+//     if (errorLine == 0 && xmlContext && xmlContext->input) {
+//             errorLine = xmlContext->input->line;
+//     }
 
        
 }