例如,以下代码声明并定义了一个名为 InputxParser 的解析器:
{
CciFactory* factoryObject;
int rc = 0;
CciChar factoryName[] = L"MyParserFactory";
CCI_EXCEPTION_ST exception_st;
/* Create the Parser Factory for this parser */
factoryObject = cpiCreateParserFactory(0, factoryName);
if (factoryObject == CCI_NULL_ADDR) {
/* Any local error handling can go here */
}
else {
/* Define the parsers supported by this factory */
static CNI_VFT vftable = {CNI_VFT_DEFAULT};
/* Setup function table with pointers to parser implementation functions */
vftable.iFpCreateContext = cpiCreateContext;
vftable.iFpParseBufferEncoded = cpiParseBufferEncoded;
vftable.iFpParseFirstChild = cpiParseFirstChild;
vftable.iFpParseLastChild = cpiParseLastChild;
vftable.iFpParsePreviousSibling = cpiParsePreviousSibling;
vftable.iFpParseNextSibling = cpiParseNextSibling;
vftable.iFpWriteBufferEncoded = cpiWriteBufferEncoded;
vftable.iFpDeleteContext = cpiDeleteContext;
vftable.iFpSetElementValue = cpiSetElementValue;
vftable.iFpElementValue = cpiElementValue;
vftable.iFpNextParserClassName = cpiNextParserClassName;
vftable.iFpSetNextParserClassName = cpiSetNextParserClassName;
vftable.iFpNextParserEncoding = cpiNextParserEncoding;
vftable.iFpNextParserCodedCharSetId = cpiNextParserCodedCharSetId;
cpiDefineParserClass(0, factoryObject, L"InputxParser", &vftable);
}
/* Return address of this factory object to the broker */
return(factoryObject);
}