mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
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:
parent
ce4f27de56
commit
401298ab15
5 changed files with 145 additions and 127 deletions
|
@ -7,6 +7,11 @@
|
|||
* Source/Makefile.postamble: Add code to install headers in
|
||||
$(GNUSTEP_SYSTEM_ROOT)/Headers/gnustep/Foundation as well - is this
|
||||
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>
|
||||
-- You'll need libxml2 v >= 2.2.3 to compile GSXML --
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
<item><uref url="GSXMLDocument.html">GSXMLDocument</uref></item>
|
||||
<item><uref url="GSXMLParser.html">GSXMLParser</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>
|
||||
</section>
|
||||
</chapter>
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
<li><a href ="GSXMLDocument.html">GSXMLDocument</a>
|
||||
<li><a href ="GSXMLParser.html">GSXMLParser</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>
|
||||
</body>
|
||||
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
#ifndef __GSXML_H__
|
||||
#define __GSXML_H__
|
||||
|
||||
#define GSXML_DEBUG 1
|
||||
//#undef GSXML_DEBUG
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/entities.h>
|
||||
|
||||
|
@ -209,19 +206,11 @@ typedef xmlNsType GSXMLNamespaceType;
|
|||
- (void) setExternalEntityLoader: (void*)function;
|
||||
- (BOOL) substituteEntities: (BOOL)yesno;
|
||||
|
||||
//libxml base functions
|
||||
- (BOOL) createCreatePushParserCtxt;
|
||||
- (void) parseChunk: (NSData*)data;
|
||||
|
||||
@end
|
||||
|
||||
@interface GSHTMLParser : GSXMLParser
|
||||
{
|
||||
}
|
||||
|
||||
//libxml base functions
|
||||
- (BOOL) createCreatePushParserCtxt;
|
||||
- (void) parseChunk: (NSData*)data;
|
||||
@end
|
||||
|
||||
@interface GSSAXHandler : NSObject
|
||||
|
@ -230,7 +219,6 @@ typedef xmlNsType GSXMLNamespaceType;
|
|||
GSXMLParser *parser;
|
||||
}
|
||||
+ (GSSAXHandler*) handler;
|
||||
- (BOOL) initLib;
|
||||
- (void*) lib;
|
||||
- (GSXMLParser*) parser;
|
||||
@end
|
||||
|
@ -303,7 +291,6 @@ typedef xmlNsType GSXMLNamespaceType;
|
|||
@end
|
||||
|
||||
@interface GSHTMLSAXHandler : GSSAXHandler
|
||||
- (BOOL) initLib;
|
||||
@end
|
||||
|
||||
#endif __GSXML_H__
|
||||
|
|
242
Source/GSXML.m
242
Source/GSXML.m
|
@ -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
|
||||
|
||||
+ (void) initialize
|
||||
|
@ -799,19 +811,6 @@ static NSMapTable *nodeNames = 0;
|
|||
@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
|
||||
|
||||
static NSString *endMarker = @"At end of incremental parse";
|
||||
|
@ -941,8 +940,8 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
return nil;
|
||||
}
|
||||
saxHandler = RETAIN(handler);
|
||||
[saxHandler parser: self];
|
||||
if (![self createCreatePushParserCtxt])
|
||||
[saxHandler _setParser: self];
|
||||
if ([self _initLibXML] == NO)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
|
@ -1049,8 +1048,8 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
|
||||
tmp = RETAIN(src);
|
||||
ASSIGN(src, endMarker);
|
||||
[self parseChunk:tmp];
|
||||
[self parseChunk:nil];
|
||||
[self _parseChunk: tmp];
|
||||
[self _parseChunk: nil];
|
||||
RELEASE(tmp);
|
||||
|
||||
if (((xmlParserCtxtPtr)lib)->wellFormed)
|
||||
|
@ -1094,7 +1093,7 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
}
|
||||
else
|
||||
{
|
||||
[self parseChunk:data];
|
||||
[self _parseChunk: data];
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
@ -1156,9 +1155,14 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
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)
|
||||
{
|
||||
NSLog(@"Failed to create libxml parser context");
|
||||
|
@ -1166,26 +1170,29 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
}
|
||||
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;
|
||||
};
|
||||
}
|
||||
return YES;
|
||||
};
|
||||
}
|
||||
|
||||
//nil data allowed
|
||||
- (void) parseChunk: (NSData*)data
|
||||
- (void) _parseChunk: (NSData*)data
|
||||
{
|
||||
// nil data allowed
|
||||
xmlParseChunk(lib, [data bytes], [data length], 0);
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@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)
|
||||
{
|
||||
NSLog(@"Failed to create libxml parser context");
|
||||
|
@ -1193,17 +1200,19 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
}
|
||||
else
|
||||
{
|
||||
// Put saxHandler address in _private member, so we can retrieve
|
||||
// the GSXMLHandler to use in our SAX C Functions.
|
||||
((htmlParserCtxtPtr)lib)->_private=saxHandler;
|
||||
};
|
||||
/*
|
||||
* Put saxHandler address in _private member, so we can retrieve
|
||||
* the GSXMLHandler to use in our SAX C Functions.
|
||||
*/
|
||||
((htmlParserCtxtPtr)lib)->_private = saxHandler;
|
||||
}
|
||||
return YES;
|
||||
};
|
||||
}
|
||||
|
||||
- (void) parseChunk: (NSData*)data
|
||||
- (void) _parseChunk: (NSData*)data
|
||||
{
|
||||
htmlParseChunk(lib, [data bytes], [data length], 0);
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
@ -1216,10 +1225,10 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
}
|
||||
|
||||
/*
|
||||
* The context is a xmlParserCtxtPtr or htmlParserCtxtPtr. Its _private member contain
|
||||
* address of our Sax Handler Object.
|
||||
* We can use a (xmlParserCtxtPtr) cast because xmlParserCtxt and htmlParserCtxt are
|
||||
* the same structure (and will remain, cf libxml author).
|
||||
* The context is a xmlParserCtxtPtr or htmlParserCtxtPtr.
|
||||
* Its _private member contains the address of our Sax Handler Object.
|
||||
* We can use a (xmlParserCtxtPtr) cast because xmlParserCtxt and
|
||||
* htmlParserCtxt are the same structure (and will remain, cf libxml author).
|
||||
*/
|
||||
#define HANDLER (GSSAXHandler*)(((xmlParserCtxtPtr)ctx)->_private)
|
||||
|
||||
|
@ -1478,61 +1487,20 @@ fatalErrorFunction(void *ctx, const char *msg, ...)
|
|||
|
||||
- (id) init
|
||||
{
|
||||
NSAssert(lib == 0, @"Already created lib");
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
if (![self initLib])
|
||||
if ([self _initLibXML] == NO)
|
||||
{
|
||||
NSLog(@"GSSAXHandler: out of memory\n");
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
};
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
return lib;
|
||||
|
@ -1688,13 +1656,59 @@ fatalErrorFunction(void *ctx, const char *msg, ...)
|
|||
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
|
||||
|
||||
@implementation GSHTMLSAXHandler
|
||||
- (BOOL) initLib
|
||||
- (BOOL) _initLibXML
|
||||
{
|
||||
NSAssert(!lib,@"Already created lib");
|
||||
lib = (xmlSAXHandler*)malloc(sizeof(htmlSAXHandler));
|
||||
if (lib == NULL)
|
||||
return NO;
|
||||
|
@ -1703,34 +1717,34 @@ fatalErrorFunction(void *ctx, const char *msg, ...)
|
|||
memset(lib, 0, sizeof(htmlSAXHandler));
|
||||
|
||||
#define LIB ((htmlSAXHandlerPtr)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;
|
||||
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;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue