62 string elemName = xpp->
getName();
74 error(
"Fatal error ,container's type is not same as the validated type",xpp);
106 t->sParser_ = sParser_;
113 if (sParser_->
getType(typeId) == 0
140 if (xpp->
getName() != elemName)
141 error(
"Syntax error "+elemName,xpp);
144 error(
"Expected a closing tag for " + elemName,xpp);
173 for (
int i = 0; i < attcnt; i++) {
178 if (!attNsp.empty() && attNsp != sParser_->
getNamespace())
195 error(
"Unknown attribute \"" + attName +
"\"",xpp);
201 checkAttributeOccurence(ct,xpp);
203 checkAttributeOccurence(bt,xpp);
224 if (xpp->
getName() != elemName)
225 error(
"Syntax error",xpp);
228 error(
"Expected a closing tag for " + elemName,xpp);
237 validateContentModel(xpp,
244 validateContentModel(xpp,
261 if (!ipTc && t)
delete t;
277 const string & elemName,
289 for (ci=cit_b;ci!=cit_e;ci++){
291 ci->first.e->nOccurrences=0;
297 const ComplexType* ct =
static_cast<const ComplexType*
>(btCnt->
schemaParser()->
getType(t));
298 bCm = ct->getContents();
313 if (xpp->
getName() == elemName)
320 if(!findElement(cit_b,cit_e,xpp->
getName(),ci))
321 error(
"Could not find element " +xpp->
getName()+
" in "+elemName,xpp);
322 ci->first.e->nOccurrences++;
324 validate(xpp, ci->first.e->getType(),
333 for (ci=cit_b;ci!=cit_e;ci++){
335 (ci->first.e->nOccurrences<ci->first.e->getMin()||
336 ci->first.e->nOccurrences>ci->first.e->getMax()))
337 error(ci->first.e->getName()+
" did not meet occurrence constraints",xpp);
351 if (xpp->
getName() == elemName)
372 validateContentModel(xpp,ci->first.c,
374 elemName,
true,btCnt);
381 findElement(ci,cit_e,xpp->
getName(), ci)){
383 ci->first.e->nOccurrences++;
384 validate(xpp,ci->first.e->getType(),
391 validate(xpp,bci->first.e->getType(),t->getChildContainer(bci->first.e->getName(),
true));
395 error(
"Could not find element " +xpp->
getName()+
" in "+elemName,xpp);
405 for (ci=cit_b;ci!=cit_e;ci++){
407 (ci->first.e->nOccurrences<ci->first.e->getMin()||
408 ci->first.e->nOccurrences>ci->first.e->getMax()))
409 error(ci->first.e->getName()+
" did not meet occurrence constraints",xpp);
420 if(findElement(ci,cit_e,xpp->
getName(), ci)) {
422 std::string choiceElem = xpp->
getName();
425 ci->first.e->nOccurrences++;
426 validate(xpp, ci->first.e->getType(),
429 }
while(xpp->
getName() == choiceElem);
440 validateContentModel(xpp,ci->first.c,
442 elemName,
true,btCnt);
444 catch (SchemaParserException spe){
448 validateContentModel(xpp,ci->first.c,
450 elemName,
true,btCnt);
455 error(
"Could not find element " +xpp->
getName()+
" in "+elemName,xpp);
466 (ci->first.e->nOccurrences<ci->first.e->getMin()||
467 ci->first.e->nOccurrences>ci->first.e->getMax()))
468 error(ci->first.e->getName()+
"did not meet occurrence constraints",xpp);
476 for (ci=cit_b;ci!=cit_e;ci++){
479 ci->first.e->nOccurrences=0;
515 std::string val = *((std::string*)value);
516 ipTc->
setValue(val,validateListOrUnion(st,val,xpp));
524 int x= *((
int*)value);
536 char c= *((
char*)value);
542 float f = *((
float*)value);
556 double db = *((
double*)value);
562 long l = *((
long*)value);
569 unsigned long ul= *((
unsigned long*)value);
575 bool b = *((
bool*)value);
588 std::string val = *((std::string* )value);
636 return validate(val,contentType,ipTc,xpp);
650 extractSimpleType(val, basetype, ipTc, st, xpp);
674SchemaValidator::extractSimpleType(
const std::string & val,
683 ipTc->
setValue(val,validateListOrUnion(st,val,xpp));
687 istringstream istr(val);
782SchemaValidator::validateListOrUnion(
const SimpleType* st,
783 const std::string &val,
790 while(s < val.length()){
791 while(val[s]==
' ')s++;
792 std::string t = val.substr(s,val.find(
' ',s)-s);
793 TypeContainer * tc =
validate(t,st->getBaseTypeId(),0,xpp);
794 if (!(tc && tc->isValueValid()))
800 }
else if (st->isUnion()){
802 std::list<int>::const_iterator it= st->unionTypes()->begin();
803 while (it!=st->unionTypes()->end()){
805 TypeContainer * tc =
validate(val,*it,0,xpp);
807 if (tc && tc->isValueValid())
837 std::cout<<
"Looking for "<< name<<
" found "<<ci->first.e->getName()<<std::endl;
839 if(ci->first.e->getName()==name ||
840 ci->first.e->getName() ==
"*")
850void SchemaValidator::error(
const std::string& mesg,
XmlPullParser* xpp)
853 SchemaParserException spe(mesg +
"\nError validating schema instance\n");
864SchemaValidator::checkAttributeOccurence(
const ComplexType* ct ,
868 if (ct->getNumAttributes() > 0)
870 for (
int i = 0; i < ct->getNumAttributes(); i++)
872 const Attribute*at = ct->getAttribute(i);
880 if (at->isRequired())
881 error(
"Required attribute \"" + at->getName() +
882 "\" missing or empty",xpp);
910 return instance1(tag,type_id);
914SchemaValidator::instance1(
const std::string &tag,
919 static bool first =
false;
932 const XSDType * pType = sParser_->
getType(type_id);
937 xmlStream_->
text(
"");
942 const ComplexType * ct =
943 static_cast<const ComplexType*
>(pType);
946 if (ct->getNumAttributes() > 0) {
948 for (
int i = 0; i < ct->getNumAttributes(); i++) {
950 const Attribute*at = ct->getAttribute(i);
958 xmlStream_->
text(
"");
962 ContentModel* cm=ct->getContents();
967 xmlStream_->
endTag(nsp,tag);
975SchemaValidator::instanceCM(ContentModel *cm)
983 switch (cm->getCompositor())
992 for (ci=cit_b;ci!=cit_e;ci++){
995 ci->first.e->getMax() > 0){
997 const SchemaParser* s1Parser = sParser_;
1000 if (!ci->first.e->getTypeNamespace().empty() &&
1001 sParser_->
isImported(ci->first.e->getTypeNamespace()) &&
1002 sParser_->
getNamespace() != ci->first.e->getTypeNamespace()) {
1010 instance1(ci->first.e->getName(),t);
1011 sParser_ = s1Parser;
1016 instanceCM(ci->first.c);
1022 instanceCM(ci->first.g->getContents());
ContentModel * getContents() const
const Attribute * getAttribute(const std::string &name) const
int getContentType() const
Schema::Compositor getCompositor() const
std::list< ContentHolder >::iterator ContentsIterator
std::string getNamespace(void) const
int getBasicContentType(int typeId) const
const XSDType * getType(const Qname &type, bool checkImports=true)
const SchemaParser * getImportedSchemaParser(const std::string &ns) const
bool isImported(const std::string &ns) const
bool isBasicType(int sType) const
bool instance(const std::string &tag, Schema::Type type_id)
SchemaValidator(const SchemaParser *sp, std::ostream &os=std::cout)
TypeContainer * validate(XmlPullParser *xpp, int typeId, TypeContainer *ipTc=0)
bool isValidFloat(float val) const
bool isValidInt(int val) const
bool isValidString(std::string val) const
TypeContainer * getChildContainer(std::string elemName, bool create=false)
TypeContainer * getBaseTypeContainer(bool create=false)
TypeContainer * getAttributeContainer(std::string attName, bool create=false)
const SchemaParser * schemaParser() const
void setValAsString(const std::string &v)
bool isValueValid() const
void setValue(const std::string &sValue, bool valid=true)
std::string getNamespace() const
int getBaseTypeId() const
virtual bool isSimple() const =0
Schema::ContentModelType getContentModel() const
std::string getNamespace(std::string prefix)
std::string getAttributeValue(int index)
std::string getAttributeNamespace(int index)
std::string getAttributeName(int index)
XmlSerializer & startTag(std::string nsp, std::string name)
XmlSerializer & text(std::string txt)
void setPrefix(std::string prefix, std::string nsp)
void startDocument(std::string encoding, bool standalone)
XmlSerializer & attribute(std::string nsp, std::string name, std::string value)
XmlSerializer & endTag(std::string nsp, std::string name)
const std::string SchemaInstaceUri