1998-08-13 03:39:55 +00:00
/*
* SAX . c : Default SAX handler to build a tree .
1998-10-20 06:14:16 +00:00
*
* Daniel Veillard < Daniel . Veillard @ w3 . org >
1998-08-13 03:39:55 +00:00
*/
# include <stdio.h>
1998-10-01 20:51:15 +00:00
# include <stdlib.h>
1998-08-13 03:39:55 +00:00
# include "tree.h"
# include "parser.h"
1998-10-27 06:21:04 +00:00
# include "entities.h"
1998-08-13 03:39:55 +00:00
# include "error.h"
/* #define DEBUG_SAX */
1998-10-20 06:14:16 +00:00
/**
* getPublicId :
* @ ctxt : An XML parser context
*
1998-08-13 03:39:55 +00:00
* Return the public ID e . g . " -//SGMLSOURCE//DTD DEMO//EN "
1998-10-20 06:14:16 +00:00
*
* return values : a CHAR *
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
const CHAR *
getPublicId ( xmlParserCtxtPtr ctxt )
{
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
1998-10-20 06:14:16 +00:00
/**
* getSystemId :
* @ ctxt : An XML parser context
*
1998-08-13 03:39:55 +00:00
* Return the system ID , basically URI or filename e . g .
1998-10-20 06:14:16 +00:00
* http : //www.sgmlsource.com/dtds/memo.dtd
*
* return values : a CHAR *
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
const CHAR *
getSystemId ( xmlParserCtxtPtr ctxt )
{
1998-08-13 03:39:55 +00:00
return ( ctxt - > input - > filename ) ;
}
1998-10-20 06:14:16 +00:00
/**
* getLineNumber :
* @ ctxt : An XML parser context
*
1998-08-13 03:39:55 +00:00
* Return the line number of the current parsing point .
1998-10-20 06:14:16 +00:00
*
* return values : an int
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
int
getLineNumber ( xmlParserCtxtPtr ctxt )
{
1998-08-13 03:39:55 +00:00
return ( ctxt - > input - > line ) ;
}
1998-10-20 06:14:16 +00:00
/**
* getColumnNumber :
* @ ctxt : An XML parser context
*
1998-08-13 03:39:55 +00:00
* Return the column number of the current parsing point .
1998-10-20 06:14:16 +00:00
*
* return values : an int
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
int
getColumnNumber ( xmlParserCtxtPtr ctxt )
{
1998-08-13 03:39:55 +00:00
return ( ctxt - > input - > col ) ;
}
/*
* The default SAX Locator .
*/
xmlSAXLocator xmlDefaultSAXLocator = {
getPublicId , getSystemId , getLineNumber , getColumnNumber
} ;
1998-10-20 06:14:16 +00:00
/**
* resolveEntity :
* @ ctxt : An XML parser context
* @ publicId : The public ID of the entity
* @ systemId : The system ID of the entity
*
1998-08-13 03:39:55 +00:00
* Special entity resolver , better left to the parser , it has
* more context than the application layer .
1998-10-27 06:21:04 +00:00
* The default behaviour is to NOT resolve the entities , in that case
* the ENTITY_REF nodes are built in the structure ( and the parameter
* values ) .
1998-10-20 06:14:16 +00:00
*
1998-10-27 06:21:04 +00:00
* return values : the xmlParserInputPtr if inlined or NULL for DOM behaviour .
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
xmlParserInputPtr
resolveEntity ( xmlParserCtxtPtr ctxt , const CHAR * publicId , const CHAR * systemId )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.resolveEntity(%s, %s) \n " , publicId , systemId ) ;
# endif
1998-10-27 06:21:04 +00:00
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
1998-10-20 06:14:16 +00:00
/**
* notationDecl :
* @ ctxt : An XML parser context
* @ name : The name of the notation
* @ publicId : The public ID of the entity
* @ systemId : The system ID of the entity
*
1998-08-13 03:39:55 +00:00
* What to do when a notation declaration has been parsed .
* TODO Not handled currently .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
notationDecl ( xmlParserCtxtPtr ctxt , const CHAR * name ,
const CHAR * publicId , const CHAR * systemId )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.notationDecl(%s, %s, %s) \n " , name , publicId , systemId ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* unparsedEntityDecl :
* @ ctxt : An XML parser context
* @ name : The name of the entity
* @ publicId : The public ID of the entity
* @ systemId : The system ID of the entity
* @ notationName : the name of the notation
*
1998-08-13 03:39:55 +00:00
* What to do when an unparsed entity declaration is parsed
* TODO Create an Entity node .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
unparsedEntityDecl ( xmlParserCtxtPtr ctxt , const CHAR * name ,
const CHAR * publicId , const CHAR * systemId ,
const CHAR * notationName )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.unparsedEntityDecl(%s, %s, %s, %s) \n " ,
name , publicId , systemId , notationName ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* setDocumentLocator :
* @ ctxt : An XML parser context
* @ loc : A SAX Locator
*
1998-08-13 03:39:55 +00:00
* Receive the document locator at startup , actually xmlDefaultSAXLocator
* Everything is available on the context , so this is useless in our case .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
setDocumentLocator ( xmlParserCtxtPtr ctxt , xmlSAXLocatorPtr loc )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.setDocumentLocator() \n " ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* startDocument :
* @ ctxt : An XML parser context
*
1998-08-13 03:39:55 +00:00
* called when the document start being processed .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
startDocument ( xmlParserCtxtPtr ctxt )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.startDocument() \n " ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* endDocument :
* @ ctxt : An XML parser context
*
1998-08-13 03:39:55 +00:00
* called when the document end has been detected .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
endDocument ( xmlParserCtxtPtr ctxt )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.endDocument() \n " ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* startElement :
* @ ctxt : An XML parser context
* @ name : The element name
*
1998-08-13 03:39:55 +00:00
* called when an opening tag has been processed .
* TODO We currently have a small pblm with the arguments . . .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
startElement ( xmlParserCtxtPtr ctxt , const CHAR * name )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.startElement(%s) \n " , name ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* endElement :
* @ ctxt : An XML parser context
* @ name : The element name
*
1998-08-13 03:39:55 +00:00
* called when the end of an element has been detected .
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
endElement ( xmlParserCtxtPtr ctxt , const CHAR * name )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.endElement(%s) \n " , name ) ;
# endif
}
1998-10-24 18:27:49 +00:00
/**
* attribute :
* @ ctxt : An XML parser context
* @ name : The attribute name
* @ value : The attribute value
*
* called when an attribute has been read by the parser .
* The default handling is to convert the attribute into an
* DOM subtree and past it in a new xmlAttr element added to
* the element .
*
* return values :
*/
void
attribute ( xmlParserCtxtPtr ctxt , const CHAR * name , const CHAR * value )
{
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.attribute(%s, %s) \n " , name , value ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* characters :
* @ ctxt : An XML parser context
* @ ch : a CHAR string
* @ start : the first char in the string
* @ len : the number of CHAR
*
1998-08-13 03:39:55 +00:00
* receiving some chars from the parser .
* Question : how much at a time ? ? ?
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
characters ( xmlParserCtxtPtr ctxt , const CHAR * ch , int start , int len )
{
1998-08-13 03:39:55 +00:00
xmlNodePtr lastChild ;
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.characters(%.30s, %d, %d) \n " , ch , start , len ) ;
# endif
/*
* Handle the data if any . If there is no child
* add it as content , otherwise if the last child is text ,
* concatenate it , else create a new node of type text .
*/
lastChild = xmlGetLastChild ( ctxt - > node ) ;
if ( lastChild = = NULL )
xmlNodeAddContentLen ( ctxt - > node , & ch [ start ] , len ) ;
else {
if ( xmlNodeIsText ( lastChild ) )
xmlTextConcat ( lastChild , & ch [ start ] , len ) ;
else {
lastChild = xmlNewTextLen ( & ch [ start ] , len ) ;
xmlAddChild ( ctxt - > node , lastChild ) ;
}
}
}
1998-10-20 06:14:16 +00:00
/**
* ignorableWhitespace :
* @ ctxt : An XML parser context
* @ ch : a CHAR string
* @ start : the first char in the string
* @ len : the number of CHAR
*
1998-08-13 03:39:55 +00:00
* receiving some ignorable whitespaces from the parser .
* Question : how much at a time ? ? ?
1998-10-20 06:14:16 +00:00
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
ignorableWhitespace ( xmlParserCtxtPtr ctxt , const CHAR * ch , int start , int len )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.ignorableWhitespace(%.30s, %d, %d) \n " , ch , start , len ) ;
# endif
}
1998-10-20 06:14:16 +00:00
/**
* processingInstruction :
* @ ctxt : An XML parser context
* @ target : the target name
* @ data : the PI data ' s
* @ len : the number of CHAR
*
* A processing instruction has been parsed .
*
* return values :
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
void
processingInstruction ( xmlParserCtxtPtr ctxt , const CHAR * target ,
const CHAR * data )
{
1998-08-13 03:39:55 +00:00
# ifdef DEBUG_SAX
fprintf ( stderr , " SAX.processingInstruction(%s, %s) \n " , target , data ) ;
# endif
}
xmlSAXHandler xmlDefaultSAXHandler = {
resolveEntity ,
notationDecl ,
unparsedEntityDecl ,
setDocumentLocator ,
startDocument ,
endDocument ,
startElement ,
endElement ,
1998-10-24 18:27:49 +00:00
attribute ,
1998-08-13 03:39:55 +00:00
characters ,
ignorableWhitespace ,
processingInstruction ,
xmlParserWarning ,
xmlParserError ,
xmlParserError ,
} ;
1998-10-20 06:14:16 +00:00
/**
* xmlDefaultSAXHandlerInit :
*
* Initialize the default SAX handler
*/
void
xmlDefaultSAXHandlerInit ( void )
{
1998-08-13 03:39:55 +00:00
xmlDefaultSAXHandler . resolveEntity = resolveEntity ;
xmlDefaultSAXHandler . notationDecl = notationDecl ;
xmlDefaultSAXHandler . unparsedEntityDecl = unparsedEntityDecl ;
xmlDefaultSAXHandler . setDocumentLocator = setDocumentLocator ;
xmlDefaultSAXHandler . startDocument = startDocument ;
xmlDefaultSAXHandler . endDocument = endDocument ;
xmlDefaultSAXHandler . startElement = startElement ;
xmlDefaultSAXHandler . endElement = endElement ;
1998-10-24 18:27:49 +00:00
xmlDefaultSAXHandler . attribute = attribute ;
1998-08-13 03:39:55 +00:00
xmlDefaultSAXHandler . characters = characters ;
xmlDefaultSAXHandler . ignorableWhitespace = ignorableWhitespace ;
xmlDefaultSAXHandler . processingInstruction = processingInstruction ;
xmlDefaultSAXHandler . warning = xmlParserWarning ;
xmlDefaultSAXHandler . error = xmlParserError ;
xmlDefaultSAXHandler . fatalError = xmlParserError ;
}