41#include "XML_Parser.h"
50 known_ids.
add_item(id_pattern, directory);
57 for(p=known_ids.
head(); p != 0; p= p->next())
69 return new XML_Parser(*
this, source, ent, data);
74 return new XML_Parser(*
this, source, NULL, data);
82 Entity ent = NewExternalEntity(0,0,strdup8(desc),0,0);
84 FILE16 *input16=MakeFILE16FromFILE(input,
"r");
87 EST_sys_error(
"Can't open 16 bit '%s'", (
const char *)desc);
89 SetCloseUnderlying(input16, 0);
91 return make_parser(NewInputSource(ent, input16), ent, data);
105 if ( filename ==
"-" )
108 FILE *input = fopen(filename,
"r");
111 EST_sys_error(
"Can't open '%s'", (
const char *)filename);
113 Entity ent = NewExternalEntity(0,0,strdup8(filename),0,0);
115 FILE16 *input16=MakeFILE16FromFILE(input,
"r");
118 EST_sys_error(
"Can't open 16 bit '%s'", (
const char *)filename);
120 SetCloseUnderlying(input16, 1);
122 return make_parser(NewInputSource(ent, input16), data);
128 EST_String id = ent->publicid?ent->publicid:ent->systemid;
131 int starts[EST_Regex_max_subexpressions];
132 int ends[EST_Regex_max_subexpressions];
133 for (p = known_ids.
head(); p != 0; p = p->next())
138 if (
id.matches(re, 0, starts, ends))
141 res.
subst(
id, starts, ends);
145 if((f = fopen(res,
"r")))
147 if(!(f16 = MakeFILE16FromFILE(f,
"r")))
149 SetCloseUnderlying(f16, 1);
151 return NewInputSource(ent, f16);
156 return EntityOpen(ent);
164 return parser->
open(ent);
172{ (void)c; (void)p; (void)data; }
177{ (void)c; (void)p; (void)data; }
184{ (void)c; (void)p; (void)data; (void)name; (void)attributes; }
191{ (void)c; (void)p; (void)data; (void)name; (void)attributes;
200{ (void)c; (void)p; (void)data; (void)name; }
206{ (void)c; (void)p; (void)data; (void)chars; }
212{ (void)c; (void)p; (void)data; (void)chars; }
217 const char *instruction)
218{ (void)c; (void)p; (void)data; (void)instruction; }
223{ (void)c; (void)p; (void)data; }
257 ParserSetFlag(
p, ReturnDefaultedAttributes, 1);
258 ParserSetCallbackArg(
p, (
void *)
this);
280 if (ParserPush(
p,
source) == -1)
281 EST_error(
"XML Parser error in push");
289 if (bit->type == XBIT_eof)
291 else if (bit->type == XBIT_start || bit->type == XBIT_empty)
296 for (b=bit->attributes; b; b=b->next)
301 if (bit->type == XBIT_start)
306 bit->element_definition->name,
320 bit->element_definition->name,
324 else if (bit->type == XBIT_end)
332 bit->element_definition->name
335 else if (bit->type == XBIT_pcdata)
343 else if (bit->type == XBIT_cdsect)
351 else if (bit->type == XBIT_pi)
359 else if (bit->type == XBIT_error)
385 p_track_context=flag;
390 p_track_contents=flag;
397 int linenum, charnum;
402 return "No Parse In Progress";
406 bit->type == XBIT_error ?
"Error" :
"Warning",
408 bit->error_message?bit->error_message:
"non XML error"
411 for(s=
p->source; s; s=s->parent)
415 p_error_message +=
" in entity \"";
416 p_error_message += s->entity->name;
417 p_error_message +=
"\"";
420 p_error_message +=
" in unnamed entity";
422 switch(SourceLineAndChar(s, &linenum, &charnum))
439 p_error_message +=
" defined in ";
443 p_error_message += EntityDescription(s->entity);
444 p_error_message +=
"\n";
447 return (
const char *)p_error_message;
EST_String tostring(void) const
Get the expression as a string.
static EST_String Number(int i, int base=10)
Build string from an integer.
int subst(EST_String source, int(&starts)[EST_Regex_max_subexpressions], int(&ends)[EST_Regex_max_subexpressions])
Substitute the result of a match into a string.
static EST_String cat(const EST_String s1, const EST_String s2=Empty, const EST_String s3=Empty, const EST_String s4=Empty, const EST_String s5=Empty, const EST_String s6=Empty, const EST_String s7=Empty, const EST_String s8=Empty, const EST_String s9=Empty)
void clear(void)
Empty it out.
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
EST_Litem * head() const
Return First key value pair in list.
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
const K & key(EST_Litem *ptr, int m=1) const
find key, reference by ptr
void append(const T &item)
add item onto end of list
const char * get_error(XML_Parser &p)
Get the error message for the last error.
virtual void element(XML_Parser_Class &c, XML_Parser &p, void *data, const char *name, XML_Attribute_List &attributes)
XML_Parser * make_parser(InputSource source, void *data)
Create a parser for the RXP InputSource.
void register_id(EST_Regex id_pattern, EST_String directory)
virtual void error(XML_Parser_Class &c, XML_Parser &p, void *data)
InputSource try_and_open(Entity ent)
virtual void processing(XML_Parser_Class &c, XML_Parser &p, void *data, const char *instruction)
virtual void document_close(XML_Parser_Class &c, XML_Parser &p, void *data)
virtual void pcdata(XML_Parser_Class &c, XML_Parser &p, void *data, const char *chars)
virtual void document_open(XML_Parser_Class &c, XML_Parser &p, void *data)
virtual void element_open(XML_Parser_Class &c, XML_Parser &p, void *data, const char *name, XML_Attribute_List &attributes)
virtual void cdata(XML_Parser_Class &c, XML_Parser &p, void *data, const char *chars)
void registered_ids(EST_TList< EST_String > &list)
virtual void element_close(XML_Parser_Class &c, XML_Parser &p, void *data, const char *name)
static InputSource open_entity(Entity ent, void *arg)
Parser p
The RXP parser object.
XBit current_bit
The piece of markup being processed.
const char * get_error()
Get the error message for the last error.
XML_Parser(XML_Parser_Class &parent, InputSource source, Entity initial_entity, void *data)
Creator used by XML_Parser_Class::make_parser()
void * data
Arbitrary data which can be used by callbacks.
~XML_Parser()
Destructor, may close input if required.
InputSource open(Entity ent)
Open. Asks the parser class to do the work.
void track_contents(bool flag)
EST_String context(int n)
EST_TDeque< EST_String > p_context
If context is being tracked, this is a stack of element names.
void track_context(bool flag)
XML_Parser_Class * pclass
InputSource source
Where we are reading from.