Fixed structure prompt of a DTD element

This commit is contained in:
Zane U. Ji 2012-08-06 20:21:10 +08:00
parent 865701cf62
commit 0b1dcb4729
2 changed files with 54 additions and 17 deletions

View File

@ -56,7 +56,6 @@ XmlPromptGenerator::XmlPromptGenerator (
d->catalogPath = catalogPath; d->catalogPath = catalogPath;
d->basePath = basePath; d->basePath = basePath;
d->auxPath = auxPath; d->auxPath = auxPath;
d->elementDeclRecurseLevel = 0;
d->isRootElement = true; d->isRootElement = true;
d->grammarFound = false; d->grammarFound = false;
d->attributeValueCutoff = 12; // this prevents enums being stored in their thousands d->attributeValueCutoff = 12; // this prevents enums being stored in their thousands
@ -209,30 +208,65 @@ void XMLCALL XmlPromptGenerator::elementdeclhandler (
PromptGeneratorData *d; PromptGeneratorData *d;
d = ( PromptGeneratorData * ) data; d = ( PromptGeneratorData * ) data;
d->elementDeclRecurseLevel += 1;
std::string myElement = name; std::string myElement = name;
unsigned num = model->numchildren;
for ( unsigned i = 0; i < num; i++ ) std::set<std::string> children;
{ getContent ( *model, d->elementStructureMap[myElement], children );
XML_Content myContent = model->children[i]; if ( !children.empty() )
XML_Char *myName = myContent.name; d->elementMap[myElement] = children;
if ( myName )
d->elementMap[myElement].insert ( ( const char * ) myName );
else
{
// recurse
XmlPromptGenerator::elementdeclhandler ( ( void * ) d, name, &myContent );
}
}
d->elementDeclRecurseLevel -= 1;
// only one call to XML_FreeContentModel per content tree
if ( d->elementDeclRecurseLevel == 0 )
{
XML_FreeContentModel ( d->p, model ); XML_FreeContentModel ( d->p, model );
} }
void XmlPromptGenerator::getContent (
const XML_Content &content,
std::string &contentModel,
std::set<std::string> &list )
{
switch ( content.type )
{
case XML_CTYPE_EMPTY:
contentModel += "EMPTY";
return;
case XML_CTYPE_ANY:
contentModel += "ANY";
return;
case XML_CTYPE_NAME:
list.insert ( content.name );
contentModel += content.name;
break;
case XML_CTYPE_CHOICE:
case XML_CTYPE_SEQ:
case XML_CTYPE_MIXED:
default:
std::string sep;
sep = ( content.type == XML_CTYPE_CHOICE ) ? "|" : ",";//_T("|") : _T(",");
contentModel += ( content.type == XML_CTYPE_MIXED ) ? "(#PCDATA|" : "(";
for ( unsigned i = 0; i < content.numchildren; i++ )
{
if ( i > 0 )
contentModel += sep;
getContent ( content.children[i], contentModel, list);
}
contentModel += ")";//_T(")");
break;
}
switch ( content.quant )
{
case XML_CQUANT_OPT:
contentModel += "?";//_T("?");
break;
case XML_CQUANT_REP:
contentModel += "*";//_T("*");
break;
case XML_CQUANT_PLUS:
contentModel += "+";//_T("+");
break;
case XML_CQUANT_NONE:
default:
break;
}
} }
void XMLCALL XmlPromptGenerator::attlistdeclhandler ( void XMLCALL XmlPromptGenerator::attlistdeclhandler (

View File

@ -37,7 +37,6 @@ struct PromptGeneratorData : public ParserData
std::map<std::string, std::string> elementStructureMap; std::map<std::string, std::string> elementStructureMap;
std::set<std::string> entitySet; std::set<std::string> entitySet;
std::string catalogPath, basePath, auxPath, rootElement; std::string catalogPath, basePath, auxPath, rootElement;
int elementDeclRecurseLevel;
bool isRootElement, grammarFound; bool isRootElement, grammarFound;
unsigned attributeValueCutoff; unsigned attributeValueCutoff;
XML_Parser p; XML_Parser p;
@ -83,6 +82,10 @@ class XmlPromptGenerator : public WrapExpat
void *userData, void *userData,
const XML_Char *name, const XML_Char *name,
XML_Content *model ); XML_Content *model );
static void getContent (
const XML_Content &content,
std::string &contentModel,
std::set<std::string> &list );
static void XMLCALL attlistdeclhandler ( static void XMLCALL attlistdeclhandler (
void *userData, void *userData,
const XML_Char *elname, const XML_Char *elname,