Add test.c : This file is not in the client build but is meant as

a sample file for those who want to use the XML module in standalone
mode.

Added a bunch of ifdefs for getting the standalone mode.


git-svn-id: svn://10.0.0.236/trunk@2248 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
guha
1998-05-24 00:27:54 +00:00
parent a329725d0b
commit 36a7576bb9
5 changed files with 98 additions and 13 deletions

View File

@@ -20,9 +20,9 @@
DEPTH = ..\..\..
MODULE = xmlglue
CSRCS= xmlglue.c xmlss.c xmldom.c
CSRCS= xmlglue.c xmlss.c xmldom.c test.c
EXPORTS = xmlglue.h
C_OBJS=.\$(OBJDIR)\xmlglue.obj .\$(OBJDIR)\xmlss.obj .\$(OBJDIR)\xmldom.obj
C_OBJS=.\$(OBJDIR)\xmlglue.obj .\$(OBJDIR)\xmlss.obj .\$(OBJDIR)\xmldom.obj
LINCS=-I$(XPDIST)\public\nspr -I$(XPDIST)\public\expat -I$(XPDIST)\public\js

View File

@@ -0,0 +1,71 @@
/* this is to test the expat parser and dom builder in standalone mode
(i.e., without the rest of communicator).
We read in an XML file, build the dom and write out the parse
structure */
#include <stdio.h>
#include "xmlglue.h"
#define testIn "foo.xml"
#define testOut "foo.out"
void outputXMLParseTree (FILE *out, XMLElement el) ;
void main () {
FILE *stream = fopen(testIn, "r");
FILE *out = fopen(testOut, "w");
char *string = getMem(512);
XMLFile xmlf = getMem(sizeof(XMLFileStruct));
xmlf->parser = XML_ParserCreate(NULL) ;
XML_SetElementHandler(xmlf->parser,
(void (*)(void*, const char*, const char**))XMLDOM_StartHandler,
(void (*)(void*, const char*))XMLDOM_EndHandler);
XML_SetCharacterDataHandler(xmlf->parser,
(void (*)(void*, const char*, int))XMLDOM_CharHandler);
XML_SetProcessingInstructionHandler(xmlf->parser,
(void (*)(void*, const char*, const char*))XMLDOM_PIHandler);
XML_SetUserData(xmlf->parser, xmlf);
xmlf->status = 1;
while (fgets(string, 512, stream)) {
if (xmlf->status == 1) xmlf->status = XML_Parse(xmlf->parser, string, 512, 0);
memset(string, '\0', 512);
}
if (xmlf->status != 1) {
const char* error = XML_ErrorString(XML_GetErrorCode(xmlf->parser));
char* buff = getMem(150);
int n = XML_GetErrorLineNumber(xmlf->parser);
fprintf(out, "<B>Bad XML at line %i :</B><BR><P> ERROR = ", n);
fprintf(out, error);
} else {
outputXMLParseTree(out, xmlf->top);
}
fclose(out);
fclose(stream);
}
void outputXMLParseTree (FILE *out, XMLElement el) {
XMLElement child = el->child;
if (strcmp(el->tag, "xml:content") == 0) {
fprintf(out, "\n\nContent : %s\n", el->content);
} else {
fprintf(out, "\n\nElement name = %s\n", el->tag);
if (el->attributes) {
int32 n = 0;
fprintf(out, "Attributes : \n");
while (*(el->attributes + n)) {
char* attname = *(el->attributes + n);
char* attval = *(el->attributes + n + 1);
fprintf(out, "%s = %s\n", attname, attval);
n = n + 2;
}
}
}
while (el->child) {
outputXMLParseTree(out, child);
child = child->next;
}
}

View File

@@ -69,7 +69,7 @@ copyCharStarList (char** list)
}
#ifdef MOZILLA_CLIENT
char *
makeAbsoluteURL (char* p1, char* p2)
{
@@ -78,6 +78,8 @@ makeAbsoluteURL (char* p1, char* p2)
}
#endif
void
addStyleSheet(XMLFile f, StyleSheet ss)
{
@@ -115,6 +117,7 @@ void XMLDOM_StartHandler (XMLFile f, const char* elementName, const char** attli
xmle->attributes = copyCharStarList((char**)attlist);
if (f->current) addChild(f->current, xmle);
f->current = xmle;
#ifdef MOZILLA_CLIENT
if (xmlgetAttributeValue(xmle->attributes, XLL) != NULL) {
char* linkTag = xmlgetAttributeValue(xmle->attributes, XLL);
char* hrefVal = xmlgetAttributeValue(xmle->attributes, href);
@@ -137,9 +140,10 @@ void XMLDOM_StartHandler (XMLFile f, const char* elementName, const char** attli
#ifdef DOM
ET_ReflectObject(f->mwcontext, f->transclusions[f->numTransclusions - 1], NULL, LO_DOCUMENT_LAYER_ID,
f->numTransclusions - 1, LM_TRANSCLUSIONS);
#endif
#endif
}
}
#endif
}
@@ -165,7 +169,7 @@ setAttribute (char** attlist, char* elName, char* elValue)
return nattlist;
}
#ifdef MOZILLA_CLIENT
void XMLSetTransclusionProperty( XMLFile f, uint index, char* propName, char* propValue ) {
XMLElement el = f->transclusions[index];
if (!el) return;
@@ -219,7 +223,10 @@ void * /* XMLElement */ XMLGetTransclusionByIndex( MWContext *context, uint inde
return f->transclusions[index];
}
#endif
void XMLDOM_PIHandler (XMLFile f, const char *elementName, const char *data) {
#ifdef MOZILLA_CLIENT
if (startsWith("xml:stylesheet", elementName)) {
char* url ;
char* attlist[2*MAX_ATTRIBUTES+1];
@@ -245,7 +252,7 @@ void XMLDOM_PIHandler (XMLFile f, const char *elementName, const char *data) {
freeMem(xdata);
return;
}
#endif
}

View File

@@ -27,6 +27,8 @@
If you have questions, send them to guha@netscape.com
*/
#ifdef MOZILLA_CLIENT
#include "xmlglue.h"
#include "xmlparse.h"
#include "xmlss.h"
@@ -54,7 +56,7 @@ int xml_parse_abort (NET_StreamClass *stream) {
StrAllocCopy(nurls->content_type, TEXT_HTML);
newstream = NET_StreamBuilder(1, nurls, (MWContext*)obj->mwcontext);
sprintf(buff, "<B>Bad XML at line %i :</B><BR><P> ERROR = ", n);
(*(newstream->put_block))(newstream, buff, strlen(buff));
(*(newstream->put_block))(newstream, buff, strlen(buff));
(*(newstream->put_block))(newstream, error, strlen(error));
newstream->complete(newstream);
freeMem(buff);
@@ -140,9 +142,6 @@ outputToStream (XMLFile f, char* s)
}
return;
}
#ifdef DEBUG
/* FE_Trace(s); */
#endif
if (f->outputBuffer == NULL) f->outputBuffer = getMem(OUTPUT_BUFFER_SIZE+1);
if ((strlen(s) > OUTPUT_BUFFER_SIZE)) {
char* buff = copyString(s);
@@ -405,3 +404,5 @@ readHTML (char* url, XMLHTMLInclusion ss)
urls->fe_data = ss;
NET_GetURL(urls, FO_CACHE_AND_XMLHTML, ss->xml->mwcontext, xmlhtml_GetUrlExitFunc);
}
#endif

View File

@@ -26,10 +26,15 @@
#include "xmlparse.h"
#ifdef MOZILLA_CLIENT
#include "jscompat.h"
#include "lo_ele.h"
#include "libevent.h"
#include "libmocha.h"
#include "net.h"
#include "xp.h"
#include "xp_str.h"
#endif
#ifdef XP_UNIX
#include <sys/fcntl.h>
@@ -49,9 +54,6 @@
#include "nspr.h"
#include "plhash.h"
#include "ntypes.h"
#include "net.h"
#include "xp.h"
#include "xp_str.h"
#include "utils.h"
#include "xmlparse.h"
@@ -88,7 +90,9 @@ typedef struct _XMLFileStruct {
void* stream;
int8 numOpenStreams;
void* urls;
#ifdef MOZILLA_CLIENT
MWContext* mwcontext;
#endif
char* address;
char* outputBuffer;
XML_Parser parser;
@@ -125,7 +129,9 @@ typedef struct _XMLElementStruct {
char* tag;
char** attributes;
char* content;
#ifdef MOZILLA_CLIENT
JSObject *mocha_object;
#endif
struct _XMLElementStruct* parent;
struct _XMLElementStruct* child;
struct _XMLElementStruct* next;