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->basePath = basePath;
d->auxPath = auxPath;
d->elementDeclRecurseLevel = 0;
d->isRootElement = true;
d->grammarFound = false;
d->attributeValueCutoff = 12; // this prevents enums being stored in their thousands
@ -209,30 +208,65 @@ void XMLCALL XmlPromptGenerator::elementdeclhandler (
PromptGeneratorData *d;
d = ( PromptGeneratorData * ) data;
d->elementDeclRecurseLevel += 1;
std::string myElement = name;
unsigned num = model->numchildren;
for ( unsigned i = 0; i < num; i++ )
{
XML_Content myContent = model->children[i];
XML_Char *myName = myContent.name;
if ( myName )
d->elementMap[myElement].insert ( ( const char * ) myName );
else
{
// recurse
XmlPromptGenerator::elementdeclhandler ( ( void * ) d, name, &myContent );
}
}
d->elementDeclRecurseLevel -= 1;
std::set<std::string> children;
getContent ( *model, d->elementStructureMap[myElement], children );
if ( !children.empty() )
d->elementMap[myElement] = children;
// only one call to XML_FreeContentModel per content tree
if ( d->elementDeclRecurseLevel == 0 )
{
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 (

View File

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