40 #include "EST_error.h" 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);
264 FreeEntity(initial_entity);
271 return pclass->try_and_open(ent);
280 if (ParserPush(p, source) == -1)
281 EST_error(
"XML Parser error in push");
283 pclass->document_open(*pclass, *
this, data);
288 current_bit = bit = ReadXBit(p);
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)
303 pclass->element_open(*pclass,
306 bit->element_definition->name,
317 pclass->element(*pclass,
320 bit->element_definition->name,
324 else if (bit->type == XBIT_end)
329 pclass->element_close(*pclass,
332 bit->element_definition->name
335 else if (bit->type == XBIT_pcdata)
337 pclass->pcdata(*pclass,
343 else if (bit->type == XBIT_cdsect)
345 pclass->cdata(*pclass,
351 else if (bit->type == XBIT_pi)
353 pclass->processing(*pclass,
359 else if (bit->type == XBIT_error)
361 pclass->error(*pclass,
374 if (current_bit!=NULL)
380 pclass->document_close(*pclass, *
this, data);
385 p_track_context=flag;
390 p_track_contents=flag;
397 int linenum, charnum;
399 XBit bit = current_bit;
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;
452 return p_context.nth(n);
XBit current_bit
The piece of markup being processed.
EST_String tostring(void) const
Get the expression as a string.
void track_contents(bool flag)
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 Number(int i, int base=10)
Build string from an integer.
virtual void element_close(XML_Parser_Class &c, XML_Parser &p, void *data, const char *name)
virtual void pcdata(XML_Parser_Class &c, XML_Parser &p, void *data, const char *chars)
virtual void document_close(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)
void registered_ids(EST_TList< EST_String > &list)
const char * get_error(XML_Parser &p)
Get the error message for the last error.
~XML_Parser()
Destructor, may close input if required.
void register_id(EST_Regex id_pattern, EST_String directory)
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)
InputSource try_and_open(Entity ent)
static InputSource open_entity(Entity ent, void *arg)
XML_Parser(XML_Parser_Class &parent, InputSource source, Entity initial_entity, void *data)
Creator used by XML_Parser_Class::make_parser()
virtual void element(XML_Parser_Class &c, XML_Parser &p, void *data, const char *name, XML_Attribute_List &attributes)
void track_context(bool flag)
const char * get_error()
Get the error message for the last error.
virtual void cdata(XML_Parser_Class &c, XML_Parser &p, void *data, const char *chars)
EST_String context(int n)
void append(const T &item)
add item onto end of list
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
InputSource open(Entity ent)
Open. Asks the parser class to do the work.
XML_Parser * make_parser(InputSource source, void *data)
Create a parser for the RXP InputSource.
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)
virtual void error(XML_Parser_Class &c, XML_Parser &p, void *data)
virtual void processing(XML_Parser_Class &c, XML_Parser &p, void *data, const char *instruction)
const K & key(EST_Litem *ptr, int m=1) const
find key, reference by ptr
virtual void document_open(XML_Parser_Class &c, XML_Parser &p, void *data)
EST_Litem * head() const
Return First key value pair in list.