Supported element substitution in XML schema

This commit is contained in:
Zane U. Ji 2012-08-17 01:49:57 +08:00
parent 0263408aef
commit 7bad0039c5
2 changed files with 61 additions and 8 deletions

View File

@ -451,6 +451,9 @@ void XmlPromptGenerator::handleSchema (
return; return;
} }
SubstitutionMap substitutions;
buildSubstitutionMap ( substitutions, *grammar );
while ( elemEnum.hasMoreElements() ) while ( elemEnum.hasMoreElements() )
{ {
const SchemaElementDecl& curElem = elemEnum.nextElement(); const SchemaElementDecl& curElem = elemEnum.nextElement();
@ -473,7 +476,7 @@ void XmlPromptGenerator::handleSchema (
const ContentSpecNode *spec = curElem.getContentSpec(); const ContentSpecNode *spec = curElem.getContentSpec();
if ( spec != NULL ) if ( spec != NULL )
{ {
getContent ( spec, d->elementMap[element] ); getContent ( d->elementMap[element], spec, substitutions );
} }
// fetch attributes // fetch attributes
@ -508,22 +511,64 @@ void XmlPromptGenerator::handleSchema (
} }
} }
void XmlPromptGenerator::buildSubstitutionMap (
SubstitutionMap &substitutions,
const SchemaGrammar &grammar )
{
substitutions.clear();
RefHash2KeysTableOfEnumerator<ElemVector> list ( grammar.getValidSubstitutionGroups() );
if ( !list.hasMoreElements() )
return;
while ( list.hasMoreElements() )
{
const ElemVector &elmts = list.nextElement();
const QName *qnm;
const SchemaElementDecl *cur, *substitution;
substitution = elmts.elementAt ( 0 )->getSubstitutionGroupElem();
size_t index = elmts.size();
while ( index-- > 0 )
{
cur = elmts.elementAt ( index );
qnm = cur->getElementName();
wxString element = WrapXerces::toString ( qnm->getRawName() );
substitutions[substitution].insert ( element );
}
}
}
void XmlPromptGenerator::getContent ( void XmlPromptGenerator::getContent (
std::set<wxString> &list,
const ContentSpecNode *spec, const ContentSpecNode *spec,
std::set<wxString> &list ) SubstitutionMap &substitutions )
{ {
//if ( spec == NULL) return; //if ( spec == NULL) return;
const QName *qnm = spec->getElement(); const QName *qnm = spec->getElement();
if ( qnm ) if ( qnm )
{
const SchemaElementDecl *elem = (const SchemaElementDecl *)spec->getElementDecl();
SubstitutionMap::const_iterator itr = substitutions.find ( elem );
if ( itr == substitutions.end() )
itr = substitutions.find ( elem->getSubstitutionGroupElem() );
if ( itr != substitutions.end() )
{
list.insert ( itr->second.begin(), itr->second.end() );
}
else
{ {
wxString element = WrapXerces::toString ( qnm->getRawName() ); wxString element = WrapXerces::toString ( qnm->getRawName() );
if ( !element.IsEmpty() ) if ( !element.IsEmpty() )
list.insert( element ); list.insert( element );
} }
}
if ( spec->getFirst() != NULL) if ( spec->getFirst() != NULL)
getContent( spec->getFirst(), list ); getContent( list, spec->getFirst(), substitutions );
if ( spec->getSecond() != NULL) if ( spec->getSecond() != NULL)
getContent( spec->getSecond(), list ); getContent( list, spec->getSecond(), substitutions );
} }

View File

@ -28,6 +28,7 @@
#include "wrapexpat.h" #include "wrapexpat.h"
#include "parserdata.h" #include "parserdata.h"
#include <xercesc/validators/common/ContentSpecNode.hpp> #include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/schema/SchemaGrammar.hpp>
struct PromptGeneratorData : public ParserData struct PromptGeneratorData : public ParserData
{ {
@ -43,6 +44,9 @@ struct PromptGeneratorData : public ParserData
XML_Parser p; XML_Parser p;
}; };
typedef std::map<const xercesc::SchemaElementDecl *, std::set<wxString> >
SubstitutionMap;
class XmlPromptGenerator : public WrapExpat class XmlPromptGenerator : public WrapExpat
{ {
public: public:
@ -114,9 +118,13 @@ class XmlPromptGenerator : public WrapExpat
PromptGeneratorData *d, PromptGeneratorData *d,
const XML_Char *el, const XML_Char *el,
const XML_Char **attr ); const XML_Char **attr );
static void buildSubstitutionMap (
SubstitutionMap &substitutions,
const xercesc::SchemaGrammar &grammar );
static void getContent ( static void getContent (
std::set<wxString> &list,
const xercesc::ContentSpecNode *spec, const xercesc::ContentSpecNode *spec,
std::set<wxString> &list ); SubstitutionMap &substitutions );
}; };
#endif #endif