[Expat-discuss] Please help me about ExternalEntityRefHandler.
Alexander Lazic
al-expat1@none.at
Mon Mar 18 00:50:03 2002
Hi,
i need some explanation about the 'ExternalEntityRefHandler' ;-)
I need to check the definition in the DTD with the data which i get.
I'm not shure that expat is the right tool for that, can he parse DTD?
1.) what can the 'context' be?
2.) and which parser does i need the 'XML_ParserCreate' or
'XML_ExternalEntityParserCreate'?
typedef int
(*XML_ExternalEntityRefHandler)(XML_Parser p,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
The doc said:
.
.
>Second, instead of having userData as its first argument, it receives
>the parser that encountered the entity reference.
Therefore i need the 'XML_ExternalEntityParserCreate' or?
>This, along with the context parameter, may be used as arguments to a
>call to XML_ExternalEntityParserCreate. Using the returned parser, the
>body of the external entity can be recursively parsed.
I don't understand this right i think :-(
Test.xml:
<!DOCTYPE ZMR SYSTEM "zmr.dtd">
<ZMR>
<Action>MYA</Action>
<Person>
<IdentMerkmale>
<Familienname>Mustinger</Familienname>
<Vorname>Maximilian</Vorname>
<Staatsangehoerigkeit>Oesterr</Staatsangehoerigkeit>
<Geburtsdatum>01.01.2002</Geburtsdatum>
<Geburtsort>Port</Geburtsort>
</IdentMerkmale>
<Geschlecht>M</Geschlecht>
<Bundesland_der_Geburt>Blah</Bundesland_der_Geburt>
<Geburtsstaat>OEst</Geburtsstaat>
<Person_Grund_Beginn_Code>GEB</Person_Grund_Beginn_Code>
<Person_Grund_Beginn>Geburt</Person_Grund_Beginn>
<Person_Beschreibung_Beginn>Neujahrsbaby</Person_Beschreibung_Beginn>
</Person>
</ZMR>
Are the context ZMT or ACTION or PERSON ...?
And when should be called the ExternalParser bevor or after start?
Here the c-snipped:
FILE *infile=fopen(*++argv,"r");
outfile=fopen(*++argv,"w");
XML_Parser parser = XML_ParserCreate("UTF-8");
/* When should i use this? */
XML_Parser extparser = XML_ExternalEntityParserCreate(parser,"ZMR","UTF-8");
XML_SetElementHandler(parser, startElement, endElement);
XML_SetExternalEntityRefHandler(parser,externalEntityRefHandler);
XML_SetParamEntityParsing(parser,XML_PARAM_ENTITY_PARSING_ALWAYS);
XML_SetCharacterDataHandler(parser,characterDataHandler);
and the function 'externalEntityRefHandler':
int
externalEntityRefHandler(XML_Parser p, const XML_Char *context, const
XML_Char *base, const XML_Char *systemId, const XML_Char *publicId){
fprintf(outfile,"context :%s: base :%s: systemid :%s: pubid :%s:\n",
context,base,systemId,publicId);
return 0;
}
Please can anybody explain me Step by step how can i use this feature
from expat, a link whith a example?
Thanx
al ;-)