Fixed structure prompt of a DTD element
This commit is contained in:
parent
865701cf62
commit
0b1dcb4729
|
@ -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,29 +208,64 @@ 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 );
|
||||||
|
if ( !children.empty() )
|
||||||
|
d->elementMap[myElement] = children;
|
||||||
|
|
||||||
|
XML_FreeContentModel ( d->p, model );
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlPromptGenerator::getContent (
|
||||||
|
const XML_Content &content,
|
||||||
|
std::string &contentModel,
|
||||||
|
std::set<std::string> &list )
|
||||||
|
{
|
||||||
|
switch ( content.type )
|
||||||
{
|
{
|
||||||
XML_Content myContent = model->children[i];
|
case XML_CTYPE_EMPTY:
|
||||||
XML_Char *myName = myContent.name;
|
contentModel += "EMPTY";
|
||||||
if ( myName )
|
return;
|
||||||
d->elementMap[myElement].insert ( ( const char * ) myName );
|
case XML_CTYPE_ANY:
|
||||||
else
|
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++ )
|
||||||
{
|
{
|
||||||
// recurse
|
if ( i > 0 )
|
||||||
XmlPromptGenerator::elementdeclhandler ( ( void * ) d, name, &myContent );
|
contentModel += sep;
|
||||||
|
getContent ( content.children[i], contentModel, list);
|
||||||
}
|
}
|
||||||
|
contentModel += ")";//_T(")");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
d->elementDeclRecurseLevel -= 1;
|
|
||||||
|
|
||||||
// only one call to XML_FreeContentModel per content tree
|
switch ( content.quant )
|
||||||
if ( d->elementDeclRecurseLevel == 0 )
|
|
||||||
{
|
{
|
||||||
XML_FreeContentModel ( d->p, model );
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue