iXML updates and tidyup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7658 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-09-29 17:27:33 +00:00
parent 66a0e94783
commit 8a67887721
5 changed files with 145 additions and 127 deletions

View file

@ -7,6 +7,11 @@
* Source/Makefile.postamble: Add code to install headers in * Source/Makefile.postamble: Add code to install headers in
$(GNUSTEP_SYSTEM_ROOT)/Headers/gnustep/Foundation as well - is this $(GNUSTEP_SYSTEM_ROOT)/Headers/gnustep/Foundation as well - is this
really necessary? really necessary?
* Headers/Foundation/GSXML.h: Removed new methods used for HTML parser
* Source/GSXML.m: Renamed internal methods for xml/html parser
differentiation and declared in private interface. Tidied to conform
to coding standards. Added casts to prevent compiler warnings.
* Documentation/gsdoc/GSXML.gsdoc: added html parser info
2000-09-29 Manuel Guesdon <mguesdon@orange-concept.com> 2000-09-29 Manuel Guesdon <mguesdon@orange-concept.com>
-- You'll need libxml2 v >= 2.2.3 to compile GSXML -- -- You'll need libxml2 v >= 2.2.3 to compile GSXML --

View file

@ -26,6 +26,12 @@
<item><uref url="GSXMLDocument.html">GSXMLDocument</uref></item> <item><uref url="GSXMLDocument.html">GSXMLDocument</uref></item>
<item><uref url="GSXMLParser.html">GSXMLParser</uref></item> <item><uref url="GSXMLParser.html">GSXMLParser</uref></item>
<item><uref url="GSSAXHandler.html">GSSAXHandler</uref></item> <item><uref url="GSSAXHandler.html">GSSAXHandler</uref></item>
<item>GSHTMLParser - HTML specific subclass of GSXMLParser. No
new API intorduced.
</item>
<item>GSHTMLSAXHandler - HTML specific subclass of
GSXMLSAXHandler. No new API intorduced.
</item>
</list> </list>
</section> </section>
</chapter> </chapter>

View file

@ -26,6 +26,12 @@
<li><a href ="GSXMLDocument.html">GSXMLDocument</a> <li><a href ="GSXMLDocument.html">GSXMLDocument</a>
<li><a href ="GSXMLParser.html">GSXMLParser</a> <li><a href ="GSXMLParser.html">GSXMLParser</a>
<li><a href ="GSSAXHandler.html">GSSAXHandler</a> <li><a href ="GSSAXHandler.html">GSSAXHandler</a>
<li>GSHTMLParser - HTML specific subclass of GSXMLParser. No
new API intorduced.
<li>GSHTMLSAXHandler - HTML specific subclass of
GSXMLSAXHandler. No new API intorduced.
</ul> </ul>
</body> </body>

View file

@ -31,9 +31,6 @@
#ifndef __GSXML_H__ #ifndef __GSXML_H__
#define __GSXML_H__ #define __GSXML_H__
#define GSXML_DEBUG 1
//#undef GSXML_DEBUG
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/entities.h> #include <libxml/entities.h>
@ -209,19 +206,11 @@ typedef xmlNsType GSXMLNamespaceType;
- (void) setExternalEntityLoader: (void*)function; - (void) setExternalEntityLoader: (void*)function;
- (BOOL) substituteEntities: (BOOL)yesno; - (BOOL) substituteEntities: (BOOL)yesno;
//libxml base functions
- (BOOL) createCreatePushParserCtxt;
- (void) parseChunk: (NSData*)data;
@end @end
@interface GSHTMLParser : GSXMLParser @interface GSHTMLParser : GSXMLParser
{ {
} }
//libxml base functions
- (BOOL) createCreatePushParserCtxt;
- (void) parseChunk: (NSData*)data;
@end @end
@interface GSSAXHandler : NSObject @interface GSSAXHandler : NSObject
@ -230,7 +219,6 @@ typedef xmlNsType GSXMLNamespaceType;
GSXMLParser *parser; GSXMLParser *parser;
} }
+ (GSSAXHandler*) handler; + (GSSAXHandler*) handler;
- (BOOL) initLib;
- (void*) lib; - (void*) lib;
- (GSXMLParser*) parser; - (GSXMLParser*) parser;
@end @end
@ -303,7 +291,6 @@ typedef xmlNsType GSXMLNamespaceType;
@end @end
@interface GSHTMLSAXHandler : GSSAXHandler @interface GSHTMLSAXHandler : GSSAXHandler
- (BOOL) initLib;
@end @end
#endif __GSXML_H__ #endif __GSXML_H__

View file

@ -67,6 +67,18 @@ setupCache()
} }
/* Internal interfaces */
@interface GSXMLParser (Private)
- (BOOL) _initLibXML;
- (void) _parseChunk: (NSData*)data;
@end
@interface GSSAXHandler (Private)
- (BOOL) _initLibXML;
- (void) _setParser: (GSXMLParser*)value;
@end
@implementation GSXMLDocument : NSObject @implementation GSXMLDocument : NSObject
+ (void) initialize + (void) initialize
@ -799,19 +811,6 @@ static NSMapTable *nodeNames = 0;
@end @end
/* Internal interface for GSSAXHandler */
@interface GSSAXHandler (internal)
- (void) parser: (GSXMLParser*)value;
@end
@implementation GSSAXHandler (Internal)
- (void) parser: (GSXMLParser*)value
{
parser = value;
}
@end
@implementation GSXMLParser : NSObject @implementation GSXMLParser : NSObject
static NSString *endMarker = @"At end of incremental parse"; static NSString *endMarker = @"At end of incremental parse";
@ -941,8 +940,8 @@ static NSString *endMarker = @"At end of incremental parse";
return nil; return nil;
} }
saxHandler = RETAIN(handler); saxHandler = RETAIN(handler);
[saxHandler parser: self]; [saxHandler _setParser: self];
if (![self createCreatePushParserCtxt]) if ([self _initLibXML] == NO)
{ {
RELEASE(self); RELEASE(self);
return nil; return nil;
@ -1049,8 +1048,8 @@ static NSString *endMarker = @"At end of incremental parse";
tmp = RETAIN(src); tmp = RETAIN(src);
ASSIGN(src, endMarker); ASSIGN(src, endMarker);
[self parseChunk:tmp]; [self _parseChunk: tmp];
[self parseChunk:nil]; [self _parseChunk: nil];
RELEASE(tmp); RELEASE(tmp);
if (((xmlParserCtxtPtr)lib)->wellFormed) if (((xmlParserCtxtPtr)lib)->wellFormed)
@ -1094,7 +1093,7 @@ static NSString *endMarker = @"At end of incremental parse";
} }
else else
{ {
[self parseChunk:data]; [self _parseChunk: data];
return YES; return YES;
} }
} }
@ -1156,9 +1155,14 @@ static NSString *endMarker = @"At end of incremental parse";
return ((xmlParserCtxtPtr)lib)->errNo; return ((xmlParserCtxtPtr)lib)->errNo;
} }
- (BOOL) createCreatePushParserCtxt
/*
* Private methods - internal use only.
*/
- (BOOL) _initLibXML
{ {
lib = (void*)xmlCreatePushParserCtxt([saxHandler lib],NULL, 0, 0, ""); lib = (void*)xmlCreatePushParserCtxt([saxHandler lib], NULL, 0, 0, "");
if (lib == NULL) if (lib == NULL)
{ {
NSLog(@"Failed to create libxml parser context"); NSLog(@"Failed to create libxml parser context");
@ -1166,26 +1170,29 @@ static NSString *endMarker = @"At end of incremental parse";
} }
else else
{ {
// Put saxHandler address in _private member, so we can retrieve /*
// the GSXMLHandler to use in our SAX C Functions. * Put saxHandler address in _private member, so we can retrieve
* the GSXMLHandler to use in our SAX C Functions.
*/
((xmlParserCtxtPtr)lib)->_private=saxHandler; ((xmlParserCtxtPtr)lib)->_private=saxHandler;
}; }
return YES; return YES;
}; }
//nil data allowed - (void) _parseChunk: (NSData*)data
- (void) parseChunk: (NSData*)data
{ {
// nil data allowed
xmlParseChunk(lib, [data bytes], [data length], 0); xmlParseChunk(lib, [data bytes], [data length], 0);
}; }
@end @end
@implementation GSHTMLParser @implementation GSHTMLParser
- (BOOL) createCreatePushParserCtxt - (BOOL) _initLibXML
{ {
lib = (void*)htmlCreatePushParserCtxt([saxHandler lib],NULL, 0, 0, "",XML_CHAR_ENCODING_NONE); lib = (void*)htmlCreatePushParserCtxt([saxHandler lib], NULL, 0, 0, "",
XML_CHAR_ENCODING_NONE);
if (lib == NULL) if (lib == NULL)
{ {
NSLog(@"Failed to create libxml parser context"); NSLog(@"Failed to create libxml parser context");
@ -1193,17 +1200,19 @@ static NSString *endMarker = @"At end of incremental parse";
} }
else else
{ {
// Put saxHandler address in _private member, so we can retrieve /*
// the GSXMLHandler to use in our SAX C Functions. * Put saxHandler address in _private member, so we can retrieve
((htmlParserCtxtPtr)lib)->_private=saxHandler; * the GSXMLHandler to use in our SAX C Functions.
}; */
((htmlParserCtxtPtr)lib)->_private = saxHandler;
}
return YES; return YES;
}; }
- (void) parseChunk: (NSData*)data - (void) _parseChunk: (NSData*)data
{ {
htmlParseChunk(lib, [data bytes], [data length], 0); htmlParseChunk(lib, [data bytes], [data length], 0);
}; }
@end @end
@ -1216,10 +1225,10 @@ static NSString *endMarker = @"At end of incremental parse";
} }
/* /*
* The context is a xmlParserCtxtPtr or htmlParserCtxtPtr. Its _private member contain * The context is a xmlParserCtxtPtr or htmlParserCtxtPtr.
* address of our Sax Handler Object. * Its _private member contains the address of our Sax Handler Object.
* We can use a (xmlParserCtxtPtr) cast because xmlParserCtxt and htmlParserCtxt are * We can use a (xmlParserCtxtPtr) cast because xmlParserCtxt and
* the same structure (and will remain, cf libxml author). * htmlParserCtxt are the same structure (and will remain, cf libxml author).
*/ */
#define HANDLER (GSSAXHandler*)(((xmlParserCtxtPtr)ctx)->_private) #define HANDLER (GSSAXHandler*)(((xmlParserCtxtPtr)ctx)->_private)
@ -1478,61 +1487,20 @@ fatalErrorFunction(void *ctx, const char *msg, ...)
- (id) init - (id) init
{ {
NSAssert(lib == 0, @"Already created lib");
self = [super init]; self = [super init];
if (self != nil) if (self != nil)
{ {
if (![self initLib]) if ([self _initLibXML] == NO)
{ {
NSLog(@"GSSAXHandler: out of memory\n"); NSLog(@"GSSAXHandler: out of memory\n");
RELEASE(self); RELEASE(self);
return nil; return nil;
}; }
} }
return self; return self;
} }
- (BOOL) initLib
{
NSAssert(!lib,@"Already created lib");
lib = (xmlSAXHandler*)malloc(sizeof(xmlSAXHandler));
if (lib == NULL)
return NO;
else
{
memset(lib, 0, sizeof(xmlSAXHandler));
#define LIB ((xmlSAXHandlerPtr)lib)
LIB->internalSubset = internalSubsetFunction;
LIB->externalSubset = externalSubsetFunction;
LIB->isStandalone = isStandaloneFunction;
LIB->hasInternalSubset = hasInternalSubsetFunction;
LIB->hasExternalSubset = hasExternalSubsetFunction;
LIB->resolveEntity = resolveEntityFunction;
LIB->getEntity = getEntityFunction;
LIB->entityDecl = entityDeclFunction;
LIB->notationDecl = notationDeclFunction;
LIB->attributeDecl = attributeDeclFunction;
LIB->elementDecl = elementDeclFunction;
LIB->unparsedEntityDecl = unparsedEntityDeclFunction;
LIB->startDocument = startDocumentFunction;
LIB->endDocument = endDocumentFunction;
LIB->startElement = startElementFunction;
LIB->endElement = endElementFunction;
LIB->reference = referenceFunction;
LIB->characters = charactersFunction;
LIB->ignorableWhitespace = ignorableWhitespaceFunction;
LIB->processingInstruction = processInstructionFunction;
LIB->comment = commentFunction;
LIB->warning = warningFunction;
LIB->error = errorFunction;
LIB->fatalError = fatalErrorFunction;
LIB->getParameterEntity = getParameterEntityFunction;
LIB->cdataBlock = cdataBlockFunction;
#undef LIB
return YES;
};
};
- (void*) lib - (void*) lib
{ {
return lib; return lib;
@ -1688,13 +1656,59 @@ fatalErrorFunction(void *ctx, const char *msg, ...)
return 0; return 0;
} }
/*
* Private methods - internal use only.
*/
- (BOOL) _initLibXML
{
lib = (xmlSAXHandler*)malloc(sizeof(xmlSAXHandler));
if (lib == NULL)
return NO;
else
{
memset(lib, 0, sizeof(xmlSAXHandler));
#define LIB ((xmlSAXHandlerPtr)lib)
LIB->internalSubset = (void*) internalSubsetFunction;
LIB->externalSubset = (void*) externalSubsetFunction;
LIB->isStandalone = (void*) isStandaloneFunction;
LIB->hasInternalSubset = (void*) hasInternalSubsetFunction;
LIB->hasExternalSubset = (void*) hasExternalSubsetFunction;
LIB->resolveEntity = (void*) resolveEntityFunction;
LIB->getEntity = (void*) getEntityFunction;
LIB->entityDecl = (void*) entityDeclFunction;
LIB->notationDecl = (void*) notationDeclFunction;
LIB->attributeDecl = (void*) attributeDeclFunction;
LIB->elementDecl = (void*) elementDeclFunction;
LIB->unparsedEntityDecl = (void*) unparsedEntityDeclFunction;
LIB->startDocument = (void*) startDocumentFunction;
LIB->endDocument = (void*) endDocumentFunction;
LIB->startElement = (void*) startElementFunction;
LIB->endElement = (void*) endElementFunction;
LIB->reference = (void*) referenceFunction;
LIB->characters = (void*) charactersFunction;
LIB->ignorableWhitespace = (void*) ignorableWhitespaceFunction;
LIB->processingInstruction = (void*) processInstructionFunction;
LIB->comment = (void*) commentFunction;
LIB->warning = (void*) warningFunction;
LIB->error = (void*) errorFunction;
LIB->fatalError = (void*) fatalErrorFunction;
LIB->getParameterEntity = (void*) getParameterEntityFunction;
LIB->cdataBlock = (void*) cdataBlockFunction;
#undef LIB
return YES;
}
}
- (void) _setParser: (GSXMLParser*)value
{
parser = value;
}
@end @end
@implementation GSHTMLSAXHandler @implementation GSHTMLSAXHandler
- (BOOL) initLib - (BOOL) _initLibXML
{ {
NSAssert(!lib,@"Already created lib");
lib = (xmlSAXHandler*)malloc(sizeof(htmlSAXHandler)); lib = (xmlSAXHandler*)malloc(sizeof(htmlSAXHandler));
if (lib == NULL) if (lib == NULL)
return NO; return NO;
@ -1703,34 +1717,34 @@ fatalErrorFunction(void *ctx, const char *msg, ...)
memset(lib, 0, sizeof(htmlSAXHandler)); memset(lib, 0, sizeof(htmlSAXHandler));
#define LIB ((htmlSAXHandlerPtr)lib) #define LIB ((htmlSAXHandlerPtr)lib)
LIB->internalSubset = internalSubsetFunction; LIB->internalSubset = (void*) internalSubsetFunction;
LIB->externalSubset = externalSubsetFunction; LIB->externalSubset = (void*) externalSubsetFunction;
LIB->isStandalone = isStandaloneFunction; LIB->isStandalone = (void*) isStandaloneFunction;
LIB->hasInternalSubset = hasInternalSubsetFunction; LIB->hasInternalSubset = (void*) hasInternalSubsetFunction;
LIB->hasExternalSubset = hasExternalSubsetFunction; LIB->hasExternalSubset = (void*) hasExternalSubsetFunction;
LIB->resolveEntity = resolveEntityFunction; LIB->resolveEntity = (void*) resolveEntityFunction;
LIB->getEntity = getEntityFunction; LIB->getEntity = (void*) getEntityFunction;
LIB->entityDecl = entityDeclFunction; LIB->entityDecl = (void*) entityDeclFunction;
LIB->notationDecl = notationDeclFunction; LIB->notationDecl = (void*) notationDeclFunction;
LIB->attributeDecl = attributeDeclFunction; LIB->attributeDecl = (void*) attributeDeclFunction;
LIB->elementDecl = elementDeclFunction; LIB->elementDecl = (void*) elementDeclFunction;
LIB->unparsedEntityDecl = unparsedEntityDeclFunction; LIB->unparsedEntityDecl = (void*) unparsedEntityDeclFunction;
LIB->startDocument = startDocumentFunction; LIB->startDocument = (void*) startDocumentFunction;
LIB->endDocument = endDocumentFunction; LIB->endDocument = (void*) endDocumentFunction;
LIB->startElement = startElementFunction; LIB->startElement = (void*) startElementFunction;
LIB->endElement = endElementFunction; LIB->endElement = (void*) endElementFunction;
LIB->reference = referenceFunction; LIB->reference = (void*) referenceFunction;
LIB->characters = charactersFunction; LIB->characters = (void*) charactersFunction;
LIB->ignorableWhitespace = ignorableWhitespaceFunction; LIB->ignorableWhitespace = (void*) ignorableWhitespaceFunction;
LIB->processingInstruction = processInstructionFunction; LIB->processingInstruction = (void*) processInstructionFunction;
LIB->comment = commentFunction; LIB->comment = (void*) commentFunction;
LIB->warning = warningFunction; LIB->warning = (void*) warningFunction;
LIB->error = errorFunction; LIB->error = (void*) errorFunction;
LIB->fatalError = fatalErrorFunction; LIB->fatalError = (void*) fatalErrorFunction;
LIB->getParameterEntity = getParameterEntityFunction; LIB->getParameterEntity = (void*) getParameterEntityFunction;
LIB->cdataBlock = cdataBlockFunction; LIB->cdataBlock = (void*) cdataBlockFunction;
#undef LIB #undef LIB
return YES; return YES;
}; }
}; }
@end @end