35 const std::string & s)
38 elementQualified_ (false),
39 attributeQualified_ (false),
40 deleteXmlParser_(false),
41 resolveFwdRefs_(true),
52 const std::string & s)
55 elementQualified_ (false),
56 attributeQualified_ (false),
57 deleteXmlParser_(false),
58 resolveFwdRefs_(true),
65 xmlStream_.open(fname_.c_str());
69 while (!xmlStream_.fail() && xParser_->getEventType() != xParser_->END_DOCUMENT)
72 if (xParser_->getEventType() == xParser_->START_TAG &&
73 xParser_->getName() ==
"schema")
75 deleteXmlParser_=
true;
89 uri_ = Uri.substr(0,Uri.rfind(
'/') + 1);
97 lAttributeGroups_.clear();
98 importedSchemas_.clear();
101 if (confPath_.empty()) {
103 confPath_ = SCHEMADIR;
105 confPath_ =
"src/schemas";
113 lElems_.push_back(e);
126 if(deleteXmlParser_) {
132 for (ConstraintList::iterator ci=constraints_.begin();
133 ci != constraints_.end();
136 for (AttributeGroupList::iterator agi = lAttributeGroups_.begin();
137 agi != lAttributeGroups_.end();
154 while (xParser_->getEventType() != xParser_->START_TAG)
157 int attcnt = xParser_->getAttributeCount();
160 for (i = 0; i < attcnt; i++) {
161 std::string attName = xParser_->getAttributeName(i);
162 if (
"targetNamespace" == attName)
164 tnsUri_ = xParser_->getAttributeValue(i);
165 if (
"version" == attName)
166 version_ = xParser_->getAttributeValue(i);
167 if (
"elementFormDefault" == attName){
168 if (xParser_->getAttributeValue(i) ==
"unqualified")
169 elementQualified_ =
false;
171 else if (xParser_->getAttributeValue(i) ==
"qualified")
172 elementQualified_ =
true;
174 if (
"attributeFormDefault" == attName) {
175 if (xParser_->getAttributeValue(i) ==
"unqualified")
176 attributeQualified_ =
false;
178 else if (xParser_->getAttributeValue(i) ==
"qualified")
179 attributeQualified_ =
true;
183 for (i = xParser_->getNamespaceCount(xParser_->getDepth()) - 1;
184 i > xParser_->getNamespaceCount(xParser_->getDepth() - 1) - 1; i--)
185 if (xParser_->getNamespaceUri(i) == tnsUri_)
186 tnsPrefix_ = xParser_->getNamespacePrefix(i);
187 typesTable_.setTargetNamespace(tnsUri_);
190 return parseSchema();
193 logFile_ <<
"Error parsing schema for namespace "<<tnsUri_<<std::endl;
201 spe.
line = xParser_->getLineNumber();
202 spe.
col = xParser_->getColumnNumber();
214SchemaParser::parseSchema(std::string tag)
223 if (xParser_->
getName() == tag)
238 std::string elemName = xParser_->
getName();
239 if (elemName ==
"element") {
241 Element e = parseElement(fwd);
242 lElems_.push_back(e);
244 else if (elemName ==
"complexType")
246 XSDType *t = parseComplexType();
247 typesTable_.addType(t);
249 else if (elemName ==
"simpleType")
251 XSDType *t = parseSimpleType();
252 typesTable_.addType(t);
254 else if (elemName ==
"attribute") {
256 lAttributes_.push_back(parseAttribute(fwd));
258 else if (elemName ==
"annotation"){
261 else if (elemName ==
"import") {
264 else if (elemName==
"include"){
267 else if(elemName==
"attributeGroup") {
268 AttributeGroup* ag = parseAttributeGroup();
270 lAttributeGroups_.push_back(ag);
272 }
else if(elemName==
"group") {
274 lGroups_.push_back(parseGroup());
275 Group & g=lGroups_.back();
277 g.setContents(g.getContents(),
false);
279 else if( elemName==
"key") {
281 constraints_.push_back(parseConstraint(
Schema::Key));
283 else if( elemName==
"keyref") {
286 else if( elemName==
"unique") {
288 }
else if (elemName==
"redefine"){
292 error(
"Unknown element "+ elemName,1);
298 if ((importedSchemas_.size() == 0) &&
299 typesTable_.detectUndefinedTypes()){
301 typesTable_.printUndefinedTypes(logFile_);logFile_.flush();
302 error(
"Undefined Types in namespace "+tnsUri_);
307 resolveForwardElementRefs();
308 resolveForwardAttributeRefs();
312 catch(SchemaParserException spe)
314 spe.line = xParser_->getLineNumber();
315 spe.col = xParser_->getColumnNumber();
317 logFile_ << spe.description <<
" at "
318 << spe.line <<
":" << spe.col
327void SchemaParser::parseAnnotation()
332 xParser_->nextToken();
333 if (xParser_->getEventType() == xParser_->END_TAG
334 && xParser_->getName() ==
"annotation")
342SchemaParser::parseComplexType()
344 ComplexType *newType =
new ComplexType(tnsUri_);
345 int attcnt = xParser_->getAttributeCount();
346 for (
int i = 0; i < attcnt; i++)
348 if (
"name" == xParser_->getAttributeName(i))
349 newType->setName(xParser_->getAttributeValue(i));
351 if (
"mixed" == xParser_->getAttributeName(i) &&
352 (xParser_->getAttributeValue(i).empty() ||
353 xParser_->getAttributeValue(i)==
"true"))
363 if (xParser_->getEventType() == xParser_->END_TAG)
365 if (xParser_->getName() ==
"complexType")
369 while (xParser_->getEventType() != xParser_->START_TAG)
372 std::string elemName = xParser_->getName();
375 if (elemName ==
"all"){
377 newType->setContents(cm);
380 else if (elemName ==
"sequence"){
382 newType->setContents(cm);
385 else if (elemName ==
"choice"){
387 newType->setContents(cm);
390 else if (elemName ==
"attribute") {
392 Attribute a=parseAttribute(f);
393 newType->addAttribute(a,f);
394 }
else if (elemName==
"attributeGroup"){
395 parseAttributeGroup(newType);
397 else if (elemName==
"group"){
400 newType->setContents(cm);
403 else if (elemName ==
"anyAttribute")
404 addAnyAttribute(newType);
406 else if (elemName ==
"complexContent")
407 parseComplexContent(newType);
409 else if (elemName ==
"simpleContent")
410 parseSimpleContent(newType);
412 else if (xParser_->getName() ==
"annotation")
416 error(
"Unexpected tag: '"+elemName+
"' in "+newType->getName() );
419 makeListFromSoapArray(newType);
424SchemaParser::parseAttributeGroup(
ComplexType* cType)
426 std::string name,ref;
427 ref = xParser_->getAttributeValue(
"",
"ref");
434 for(list<Attribute>::iterator ai= ag->begin();
437 cType->addAttribute(*ai);
440 cType->addAttributeGroupName(ref);
446 name = xParser_->getAttributeValue(
"",
"name");
447 AttributeGroup *ag =
new AttributeGroup(name);
449 while (xParser_->getName() ==
"annotation")
454 std::string elemName=xParser_->getName();
455 while (!((xParser_->getEventType() == xParser_->END_TAG) &&
456 (elemName ==
"attributeGroup"))){
458 if(elemName==
"attribute"){
460 ag->addAttribute(parseAttribute(fwd));
461 }
else if(elemName==
"attributeGroup"){
462 AttributeGroup* ag1=parseAttributeGroup();
463 for(list<Attribute>::iterator ai= ag1->begin();
466 ag->addAttribute(*ai);
467 }
else if(elemName==
"anyAttribute"){
468 ag->addAttribute(addAnyAttribute(cType));
471 elemName=xParser_->getName();
476 for(list<Attribute>::iterator ai= ag->begin();
479 cType->addAttribute(*ai);
489 int minimum = 1, maximum = 1;
490 std::string tmp, name,ref;
492 tmp = xParser_->getAttributeValue(
"",
"minOccurs");
495 tmp = xParser_->getAttributeValue(
"",
"maxOccurs");
497 if (
"unbounded" == tmp)
502 ref = xParser_->getAttributeValue(
"",
"ref");
515 Group g(gName.getLocalName(),minimum,maximum);
522 name = xParser_->getAttributeValue(
"",
"name");
523 Group g(name,minimum,maximum);
525 while (xParser_->getName() ==
"annotation") {
530 std::string elemName = xParser_->getName();
532 if (elemName ==
"all"){
535 else if (elemName ==
"sequence"){
538 else if (elemName ==
"choice"){
541 g.setContents(cm,
true);
546 c->addGroup(g,
false);
553 int minimum = 1, maximum = 1;
556 tmp = xParser_->getAttributeValue(
"",
"minOccurs");
559 tmp = xParser_->getAttributeValue(
"",
"maxOccurs");
562 if (
"unbounded" == tmp)
571 while (xParser_->getName() ==
"annotation")
577 while (!((xParser_->getEventType() == xParser_->END_TAG) &&
578 (xParser_->getName() ==
"choice"
579 || xParser_->getName() ==
"sequence"
580 || xParser_->getName() ==
"all")))
582 if (xParser_->getName() ==
"element") {
584 Element e =parseElement(f);
588 if (xParser_->getName() ==
"any")
590 else if (xParser_->getName() ==
"choice"){
592 cm->addContentModel(cmc);
595 else if (xParser_->getName() ==
"sequence"){
597 cm->addContentModel(cms);
600 else if (xParser_->getName() ==
"group"){
603 else if(xParser_->getName() ==
"annotation") {
607 error(
"parseContent: Unexpected tag "+xParser_->getName());
610 error(
"parseContent <all>:Syntax Error");
617SchemaParser::parseElement(
bool & fwdRef)
619 std::string name, fixedVal, defaultVal,
622 typeNs = tnsUri_,elemNs = tnsUri_;
624 int type_id = 0, minimum = 1, maximum = 1, attcnt;
626 bool qualified =
false,nill =
false;
629 attcnt = xParser_->getAttributeCount();
630 for (
int i = 0; i < attcnt; i++)
632 std::string attName = xParser_->getAttributeName(i);
633 if (
"name" == attName)
634 name = xParser_->getAttributeValue(i);
636 else if (
"type" == attName)
638 Qname typeName(xParser_->getAttributeValue(i));
641 (
"<element> : type and ref are mutually exclusive in element decl");
642 typeName.setNamespace(typeNs=xParser_->getNamespace(typeName.getPrefix()));
645 error(
"<element>:Could not resolve type " +
646 typeName.getNamespace() +
":" +
647 typeName.getLocalName(),0);
650 else if (
"form" == attName)
652 if (
"qualified" == xParser_->getAttributeValue(i))
655 else if (
"unqualified" == xParser_->getAttributeValue(i))
658 error(
"<element>:Invalid value for form in element " +
662 else if (
"ref" == attName)
666 (
"<element>:name and ref are mutually exclusive in element decl");
669 (
"<element>:type and ref are mutually exclusive in element decl");
670 refName = xParser_->getAttributeValue(i);
677 e =
const_cast<Element*
>(
getElement(refName));
679 type_id = e->getType();
684 if(i>=0 && importedSchemas_[i].sParser) {
686 e=
const_cast<Element*
>(importedSchemas_[i].sParser->getElement(refName));
691 const XSDType* pType = importedSchemas_[i].sParser->getType(e->getType());
692 type_id= typesTable_.addExternalTypeId(e->getName()+
"_"+e->getTypeNamespace(),
702 lForwardElemRefs_.push_back(refName);
707 qualified = e->isQualified();
708 defaultVal = e->defaultVal();
709 fixedVal = e->fixedVal();
710 typeNs = e->getTypeNamespace();
711 elemNs = e->getNamespace();
715 logFile_<<elemNs<<
":"<<name<<
" -> element reference("<<type_id<<
")"<<std::endl;
719 else if (
"minOccurs" == attName){
722 else if (
"maxOccurs" == attName){
723 if (
"unbounded" == xParser_->getAttributeValue(i))
728 error(
"<element>:Invalid value for maxOccurs",1);
732 else if (
"default" == attName){
733 if (fixedVal.empty())
734 defaultVal = xParser_->getAttributeValue(i);
737 error(
"<element>:fixed and default cannot occur together");
739 else if (
"fixed" == attName){
740 if (defaultVal.empty())
741 fixedVal = xParser_->getAttributeValue(i);
744 error(
"<element>:fixed and default cannot occur together");
747 else if (
"substitutionGroup" == attName) {
751 else if (
"nillable" == attName) {
758 error(
"<element>:Unsupported Attribute "+attName ,2) ;
764 std::string elemName=xParser_->getName();
765 if (xParser_->getEventType() == xParser_->END_TAG) {
766 if (elemName ==
"element")
770 while (xParser_->getEventType() != xParser_->START_TAG)
774 if (elemName ==
"complexType"){
775 elemType = parseComplexType();
776 type_id = typesTable_.addType(elemType);
777 typeNs = elemType->getNamespace();
779 else if (elemName ==
"simpleType"){
780 elemType = parseSimpleType();
781 type_id = typesTable_.addType(elemType);
782 typeNs = elemType->getNamespace();
784 else if (elemName ==
"annotation"){
787 else if( elemName==
"key") {
792 else if( elemName==
"keyref") {
797 else if( elemName==
"unique") {
803 error(
"<element> : syntax error or unkown tag :"+elemName);
808 if (nill && type_id == 0) {
812 constraints_.push_back(c);
829 Constraint * c=
new Constraint(cstr);
830 c->setName(xParser_->getAttributeValue(
"",
"name"));
835 std::string elemName=xParser_->getName();
836 if (xParser_->getEventType() == xParser_->END_TAG) {
844 while (xParser_->getEventType() != xParser_->START_TAG)
847 if(elemName==
"selector"){
848 c->setSelector(xParser_->getAttributeValue(
"",
"xpath"));
851 else if(elemName==
"field"){
852 c->addField(xParser_->getAttributeValue(
"",
"xpath"));
867 attcnt = xParser_->getAttributeCount();
868 for (
int i = 0; i < attcnt; i++)
870 std::string attr = xParser_->getAttributeName(i);
871 if (
"namespace" == attr)
872 ns = xParser_->getAttributeValue(i);
874 else if (
"minOccurs" == attr)
877 else if (
"maxOccurs" == attr)
879 if (
"unbounded" == xParser_->getAttributeValue(i))
884 error(
"<element>:Invalid value for maxOccurs",1);
889 else if (
"processContents" == attr ||
"id" == attr) {
894 error(
"<any>:Unsupported Attribute "+attr,2);
900 if (xParser_->getEventType() == xParser_->END_TAG)
902 if (xParser_->getName() ==
"any")
906 xParser_->nextToken();
927 bool qualified =
true;
930 attcnt = xParser_->getAttributeCount();
931 for (
int i = 0; i < attcnt; i++)
933 std::string attr = xParser_->getAttributeName(i);
934 if (
"namespace" == attr)
935 ns = xParser_->getAttributeValue(i);
937 else if (
"processContents" == attr ||
"id" == attr)
943 error(
"<anyAttribute>:Unsupported Attribute "+attr,1);
950 cType->addAttribute(a);
952 while (xParser_->getName() ==
"annotation")
964SchemaParser::parseAttribute(
bool & fwdRef)
966 std::string name, fixedVal, defaultVal;
967 int type_id = 0, attcnt;
968 bool qualified =
false, use =
false;
972 attcnt = xParser_->getAttributeCount();
973 for (
int i = 0; i < attcnt; i++) {
974 std::string attName = xParser_->getAttributeName(i);
975 std::string attNs=xParser_->getAttributeNamespace(i);
976 std::string attVal=xParser_->getAttributeValue(i);
979 if (
"name" == attName)
981 else if (
"type" == attName) {
983 error(
"<attribute>:type and ref are mutually exclusive in element decl");
984 Qname typeName(attVal);
985 typeName.setNamespace(xParser_->
989 error(
"<attribute>:Could not resolve type " +
990 typeName.getNamespace() +
991 ":" +typeName.getLocalName(),1);
993 else if (
"form" == attName) {
994 if (
"qualified" == attVal)
999 else if (
"ref" == attName) {
1001 error(
"<attribute>:name and ref are mutually exclusive in element decl");
1003 error(
"<attribute>:type and ref are mutually exclusive in element decl");
1004 refAttribute = attVal;
1011 if(i >=0 && importedSchemas_[i].sParser){
1012 a=importedSchemas_[i].sParser->getAttribute(refAttribute);
1021 lForwardAttributeRefs_.push_back(refAttribute);
1024 name = a->getName();
1025 type_id = a->getType();
1026 qualified = a->isQualified();
1027 if (defaultVal.empty())
1028 defaultVal = a->defaultVal();
1029 if (fixedVal.empty())
1030 fixedVal = a->fixedVal();
1033 else if (
"default" == attName) {
1034 if (fixedVal.empty())
1035 defaultVal = attVal;
1038 (
"<attribute>:fixed and default cannot occur together");
1040 else if (
"fixed" == attName) {
1041 if (defaultVal.empty())
1044 error(
"<attribute>:fixed and default cannot occur together");
1046 else if (
"use" == attName) {
1047 if (attVal ==
"required")
1054 if(!attNs.empty() && ((n=checkImport(attNs))!=-1)){
1058 error(
"<attribute>:Unsupported attribute {"+ attNs+
"}:"+attName,2);
1065 xParser_->nextTag();
1066 if (xParser_->getEventType() == xParser_->END_TAG)
1068 if (xParser_->getName() ==
"attribute")
1072 while (xParser_->getEventType() != xParser_->START_TAG)
1073 xParser_->nextTag();
1076 else if (xParser_->getName() ==
"simpleType")
1078 XSDType *elemType = parseSimpleType();
1081 type_id = typesTable_.addType(elemType);
1084 else if (xParser_->getName() ==
"annotation")
1087 error(
"<attribute>:Syntax error or unkown tag "+xParser_->getName());
1102SchemaParser::parseSimpleType()
1104 SimpleType *st =
new SimpleType(tnsUri_);
1105 int basetype_id = 0;
1107 attcnt = xParser_->getAttributeCount();
1108 for (
int i = 0; i < attcnt; i++)
1110 if (
"name" == xParser_->getAttributeName(i))
1111 st->setName(xParser_->getAttributeValue(i));
1114 error(
"<simpleType> :" + xParser_->getAttributeName(i) +
1115 ":Unknown/Unsupported attribute ",2);
1120 xParser_->nextTag();
1121 if (xParser_->getEventType() == xParser_->END_TAG)
1123 if (xParser_->getName() ==
"simpleType")
1127 while (xParser_->getEventType() != xParser_->START_TAG)
1128 xParser_->nextTag();
1130 if (xParser_->getName() ==
"restriction")
1132 attcnt = xParser_->getAttributeCount();
1133 for (
int i = 0; i < attcnt; i++)
1135 if (
"base" == xParser_->getAttributeName(i))
1137 Qname typeName(xParser_->getAttributeValue(i));
1138 typeName.setNamespace(xParser_->
1141 st->setBaseType(basetype_id =
1143 if (basetype_id == 0)
1144 error(
"<simpleType>:" +
1145 xParser_->getAttributeValue(i) +
1146 ":Unknown base type ",1);
1149 error(
"<simpleType>:" + xParser_->getAttributeName(i) +
1150 ":Unknown/Unsupported attribute for <restriction>",2);
1152 parseRestriction(st);
1154 else if (xParser_->getName() ==
"union"){
1156 std::string members = xParser_->getAttributeValue(
"",
"memberTypes");
1158 while(s < members.length()){
1159 while(members[s]==
' ')s++;
1160 std::string type = members.substr(s,members.find(
' ',s)-s);
1161 Qname typeName(type);
1162 typeName.setNamespace(xParser_->getNamespace(typeName.getPrefix()));
1164 st->setUnionType(basetype_id);
1168 xParser_->nextTag();
1169 while(xParser_->getName() ==
"simpleType"){
1170 XSDType * t = parseSimpleType();
1173 st->setUnionType(i);
1174 xParser_->nextTag();
1177 else if(xParser_->getName() ==
"list"){
1179 basetype_id =
getTypeId(xParser_->getAttributeValue(
"",
"itemType"));
1180 st->setListType(basetype_id);
1181 xParser_->nextTag();
1183 else if (xParser_->getName() ==
"annotation")
1186 error(
"<simpleType>:Syntax error");
1193SchemaParser::parseRestriction(
SimpleType * st,
1196 if (st->getBaseTypeId() == 0)
1197 error(
"<restriction>:unkown BaseType",1);
1200 xParser_->nextTag();
1201 if (xParser_->getEventType() == xParser_->END_TAG)
1203 if (xParser_->getName() ==
"restriction")
1206 xParser_->nextTag();
1207 if (xParser_->getName() ==
"restriction"
1208 && xParser_->getEventType() == xParser_->END_TAG)
1211 while (xParser_->getName() ==
"annotation") {
1213 xParser_->nextTag();
1215 if(xParser_->getName()==
"attribute" && ct!=0){
1217 Attribute a=parseAttribute(f);
1218 ct->addAttribute(a,f);
1220 else if (st->isvalidFacet(xParser_->getName())){
1223 st->setFacetValue(xParser_->getName(),
1224 xParser_->getAttributeValue(
"",
"value"));
1226 error(
"<restriction>:" + xParser_->getName() +
1227 " is not a valid facet /attribute for the type",1);
1233SchemaParser::parseComplexContent(
ComplexType * ct)
1235 int attcnt = xParser_->getAttributeCount();
1240 xParser_->nextTag();
1242 while (xParser_->getName() ==
"annotation") {
1244 xParser_->nextTag();
1247 if (xParser_->getName() ==
"restriction") {
1248 attcnt = xParser_->getAttributeCount();
1249 for (i = 0; i < attcnt; i++) {
1250 if (
"base" == xParser_->getAttributeName(i))
1252 typeName = xParser_->getAttributeValue(i);
1257 ct->setBaseType(
getTypeId(typeName,
true),
1260 else if (xParser_->getName() ==
"extension") {
1261 attcnt = xParser_->getAttributeCount();
1262 for (i = 0; i < attcnt; i++) {
1263 if (
"base" == xParser_->getAttributeName(i)) {
1264 typeName = xParser_->getAttributeValue(i);
1269 ct->setBaseType(
getTypeId(typeName,
true),
1273 xParser_->nextTag();
1274 while (xParser_->getName() ==
"annotation") {
1276 xParser_->nextTag();
1280 std::string elemName=xParser_->getName();
1281 ContentModel * cm=0;
1282 if (elemName ==
"all"){
1285 else if (elemName ==
"sequence"){
1288 else if (elemName ==
"choice"){
1294 ct->setContents(cm);
1295 xParser_->nextTag();
1299 while (xParser_->getEventType() != xParser_->END_TAG){
1301 if (xParser_->getName() ==
"attribute") {
1303 Attribute a=parseAttribute(f);
1304 ct->addAttribute(a,f);
1306 else if(xParser_->getName() ==
"attributeGroup")
1308 parseAttributeGroup(ct);
1311 else if (xParser_->getName() ==
"anyAttribute")
1312 addAnyAttribute(ct);
1314 xParser_->nextTag();
1319 if (xParser_->getEventType() == xParser_->END_TAG)
1320 if ((xParser_->getName() ==
"restriction" ||
1321 xParser_->getName() ==
"extension") )
1323 xParser_->nextTag();
1327 xParser_->nextTag();
1335 xParser_->nextTag();
1336 if (xParser_->getName() ==
"restriction")
1338 SimpleType *st =
new SimpleType(tnsUri_);
1339 int attcnt = xParser_->getAttributeCount();
1340 int basetype_id = 0;
1341 for (
int i = 0; i < attcnt; i++)
1343 if (
"base" == xParser_->getAttributeName(i))
1345 Qname typeName(xParser_->getAttributeValue(i));
1348 st->setBaseType(basetype_id =
getTypeId(typeName,
true));
1349 if (basetype_id == 0)
1350 error(
"<simpleContent> :" +
1351 xParser_->getAttributeValue(i) +
1352 ":Unknown base type ",1);
1356 error(
"<simpleContent> :" + xParser_->getAttributeName(i) +
1357 ":Unknown/Unsupported attribute ",2);
1359 parseRestriction(st,ct);
1360 int typeId = typesTable_.addType(st);
1361 ct->setSimpleContentType(typeId);
1364 else if (xParser_->getName() ==
"extension")
1368 int attcnt = xParser_->getAttributeCount();
1369 int basetype_id = 0;
1370 for (
int i = 0; i < attcnt; i++)
1372 if (
"base" == xParser_->getAttributeName(i))
1374 Qname typeName(xParser_->getAttributeValue(i));
1377 ct->setSimpleContentType(basetype_id =
1379 if (basetype_id == 0)
1380 error(
"<simpleContent> :" +
1381 xParser_->getAttributeValue(i) +
1382 ":Unknown base type ",1);
1386 error(
"<simpleContent> :" + xParser_->getAttributeName(i) +
1387 ":Unknown/Unsupported attribute ");
1389 xParser_->nextTag();
1393 if (xParser_->getName() ==
"attribute")
1396 Attribute a=parseAttribute(f);
1397 ct->addAttribute(a,f);
1401 else if(xParser_->getName() ==
"attributeGroup")
1403 parseAttributeGroup(ct);
1407 else if (xParser_->getName() ==
"anyAttribute")
1408 addAnyAttribute(ct);
1411 xParser_->nextTag();
1415 (xParser_->getName() ==
"extension"
1416 && xParser_->getEventType() == xParser_->END_TAG))
1417 error(
"<simpleContent> :Syntax error :extension");
1419 xParser_->nextTag();
1421 (xParser_->getName() ==
"simpleContent"
1422 && xParser_->getEventType() == xParser_->END_TAG))
1423 error(
"<simpleContent> :Syntax error ");
1428SchemaParser::parseRedefine()
1431 resolveFwdRefs_=
false;
1432 parseSchema(
"redefine");
1433 resolveFwdRefs_=
true;
1438SchemaParser::parseInclude()
1441 std::string loc = xParser_->getAttributeValue(
"",
"schemaLocation");
1448 if ( loc.find(
"/",0) != 0 &&
1449 loc.find(
"file:/",0) == std::string::npos &&
1450 loc.find(
"http://") == std::string::npos)
1458 std::string schemaconf= confPath_ +
"schema.conf";
1460 ConfigFile cf(schemaconf);
1461 cf.readInto<std::string>(loc,loc);
1462 }
catch (
const ConfigFile::file_not_found & e) {}
1476 xsdStream.open(fname_.c_str());
1478 XmlPullParser * xpp =
new XmlPullParser(xsdStream);
1479 XmlPullParser * tmpXparser=xParser_;
1484 while (xParser_->getEventType() != xParser_->END_DOCUMENT){
1485 xParser_->nextTag();
1486 if (xParser_->getEventType() == xParser_->START_TAG &&
1487 xParser_->getName() ==
"schema"){
1488 resolveFwdRefs_=
false;
1491 error(
"Error while parsing the included schema " + loc);
1494 resolveFwdRefs_=
true;
1499 xParser_=tmpXparser;
1504 error(
"Error while opening the included schema " + loc);
1509 error(
"schemaLocation is a required attribute for <include>");
1512 xParser_->nextTag();
1517SchemaParser::parseImport()
1520 std::string xsdFile;
1521 std::string ns = xParser_->getAttributeValue(
"",
"namespace");
1522 std::string loc=xParser_->getAttributeValue(
"",
"schemaLocation");
1525 return parseInclude();
1536 if ( !loc.empty() &&
1537 loc.find(
"/",0) != 0 &&
1538 loc.find(
"file:/",0) == std::string::npos &&
1539 loc.find(
"http://") == std::string::npos)
1545 std::string schemaconf= confPath_ +
"schema.conf";
1547 ConfigFile cf(schemaconf);
1548 cf.readInto<std::string>(loc,loc);
1549 }
catch (
const ConfigFile::file_not_found &e) {}
1564 for (
size_t i = 0; i < importedSchemas_.size(); i++) {
1566 if(importedSchemas_[i].sParser ) {
1567 sp->addImport(importedSchemas_[i].sParser);
1573 if(sp->parseSchemaTag())
1576 error(
"Error while parsing imported namespace "+ns,0);
1581 error(
"could not import namespace from location "+loc);
1590 error(
"Imported namespace "+ns+
" from " + loc,2);
1593 error(
"No location supplied for the import"+ns,2);
1595 xParser_->nextTag();
1620 if (typens.empty()||
1621 typens == tnsUri_ ||
1624 return typesTable_.getTypeId(type, create);
1628 if (importedSchemas_.size() == 0 && create) {
1630 return typesTable_.addExternalTypeId(type, 0);
1635 for (
size_t i = 0; i < importedSchemas_.size(); i++) {
1639 if(importedSchemas_[i].sParser ) {
1641 typeId = importedSchemas_[i].sParser->getTypeId(type,
false);
1645 return typesTable_.addExternalTypeId(type,
1646 (
XSDType *) importedSchemas_[i].sParser->getType(typeId));
1656 return typesTable_.addExternalTypeId(type, 0);
1667 int unresolved=typesTable_.getNumExtRefs();
1668 if(unresolved > 0) {
1669 for (
int i = 0; i < unresolved; i++){
1671 Qname & type = typesTable_.getExtRefName(i);
1672 int localId = typesTable_.getExtRefType(i);
1676 for (
size_t n = 0; n < importedSchemas_.size(); n++)
1680 if(importedSchemas_[n].sParser){
1681 typeId = importedSchemas_[n].sParser->getTypeId(type);
1683 typesTable_.addExtType((
XSDType *) importedSchemas_[n].sParser->getType(typeId),
1691 logFile_<<
"Undefined type "<<type<<std::endl;
1695 if (typesTable_.detectUndefinedTypes())
1697 typesTable_.printUndefinedTypes(logFile_);logFile_.flush();
1698 logFile_<<
"Unresolved types in namespace "<<tnsUri_<<std::endl;
1712SchemaParser::resolveForwardElementRefs()
1715 if (lForwardElemRefs_.empty())
1717 for (list < Qname >::iterator pQnames = lForwardElemRefs_.begin();
1718 pQnames != lForwardElemRefs_.end(); pQnames++) {
1727 error(
"Could not resolve element reference "+pQnames->getLocalName(),1);
1732 error(
"Unresolved element references",1);
1737SchemaParser::resolveForwardAttributeRefs()
1740 if (lForwardAttributeRefs_.empty())
1742 for (list < Qname >::iterator pQnames = lForwardAttributeRefs_.begin();
1743 pQnames != lForwardAttributeRefs_.end(); pQnames++)
1747 typesTable_.resolveForwardAttributeRefs(pQnames-> getLocalName(), *a);
1749 error(
"Could not resolve attribute reference {"+pQnames->getNamespace()
1750 +
"}"+pQnames->getLocalName(),1);
1755 error(
"Unresolved attributes references");
1770 for (std::list<Element>::const_iterator eli=lElems_.begin();
1771 eli!= lElems_.end();
1777 else if (checkImports)
1779 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1781 if ( importedSchemas_[i].ns == typens)
1783 if(importedSchemas_[i].sParser )
1785 return importedSchemas_[i].sParser->getElement(element);
1803 for(std::list<Attribute>::iterator ali=lAttributes_.begin();
1804 ali!=lAttributes_.end();
1810 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1812 if ( importedSchemas_[i].ns == typens)
1814 if(importedSchemas_[i].sParser )
1816 return importedSchemas_[i].sParser->getAttribute(attribute);
1835 for (std::list<Group>::iterator gli =lGroups_.begin();
1836 gli!= lGroups_.end();
1844 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1846 if ( importedSchemas_[i].ns == typens)
1848 if(importedSchemas_[i].sParser )
1850 return importedSchemas_[i].sParser->getGroup(name);
1868 for (AttributeGroupList::iterator agli = lAttributeGroups_.begin();
1869 agli!= lAttributeGroups_.end();
1877 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1879 if ( importedSchemas_[i].ns == typens)
1881 if(importedSchemas_[i].sParser )
1883 return importedSchemas_[i].sParser->getAttributeGroup(name);
1901 return (
const XSDType *) typesTable_.getTypePtr(
id);
1914 const XSDType* pType = (
const XSDType *) typesTable_.getTypePtr(
id);
1915 if (!checkImports) {
1948 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1950 if ( importedSchemas_[i].ns == nameSpace)
1952 return importedSchemas_[i].sParser;
1958list < const XSDType *>*
1961 list < const XSDType *>*pLTypes =
new list < const XSDType * >;
1965 pLTypes->push_back(pType);
1974 return typesTable_.getNumTypes();
1981 return lElems_.size();
1988 return lAttributes_.size();
1995 for (
size_t i=0;i<schemaParsers.size() ;i++){
2013 importedSchemas_[i].sParser=sp;
2021 importedSchemas_.push_back(imp);
2029 for(
size_t i=0;i<importedSchemas_.size();i++) {
2031 if (importedSchemas_[i].sParser)
2032 sp->
addImport(importedSchemas_[i].sParser);
2037SchemaParser::checkImport(std::string nsp)
const
2039 for(
size_t i=0;i<importedSchemas_.size();i++)
2041 if(importedSchemas_[i].ns==nsp)
2049 std::string location)
2052 int i= checkImport(ns);
2057 importedSchemas_.push_back(imp);
2058 i =importedSchemas_.size()-1;
2063 if(location.empty())
2065 std::string xsdFile;
2076 importedSchemas_[i].sParser=sp;
2086void SchemaParser::error(std::string mesg,
int level)
2097 else if (level_ >=1 && level == 1){
2099 logFile_ <<
"Error @" << xParser_->
2100 getLineNumber() <<
":" << xParser_->
2103 else if (level_ >= 2 && level == 2) {
2105 logFile_ <<
"Alert @" << xParser_->
2106 getLineNumber() <<
":" << xParser_->
2139 id = (
static_cast<const SimpleType *
>(pType))->getBaseTypeId();
2150 return typesTable_.getAtomicTypeName(t);
2153 const XSDType * pType = (
const XSDType *) typesTable_.getTypePtr(t);
2163SchemaParser::makeListFromSoapArray (
ComplexType * ct)
2167 if(baseType->
getNamespace()==
"http://schemas.xmlsoap.org/soap/encoding/" &&
2168 baseType->
getName()==
"Array"){
2176 array = q.getLocalName();
2177 while (array[array.length()-1] ==
']' &&
2178 array[array.length()-2] ==
'[')
2179 array = array.substr(0,array.length()-2);
2181 std::string arrayNs = xParser_->
getNamespace(q.getPrefix());
2183 q.setNamespace(arrayNs);
#define FEATURE_PROCESS_NAMESPACES
std::string getLocalName(void) const
void setNamespace(std::string uri)
std::string getPrefix(void) const
std::string getNamespace(void) const
std::string defaultVal() const
ContentModel * getContents() const
void setContents(ContentModel *ct)
const Attribute * getAttribute(const std::string &name) const
int getContentType() const
void addElement(const Element &e)
std::string getNamespace(void) const
Group * getGroup(const Qname &name)
SchemaParser(const std::string &Uri, std::string tns="", std::ostream &log=std::cout, const std::string &confPath="")
int getBasicContentType(int typeId) const
void setUri(const std::string &u)
bool addImports(const std::vector< SchemaParser * > &schemaParsers)
std::string getTypeName(Schema::Type t) const
Attribute * getAttribute(const Qname &attribute)
int getNumElements() const
int getNumAttributes() const
const SchemaParser * getImportedSchema(std::string &nameSpace)
const XSDType * getType(const Qname &type, bool checkImports=true)
const Element * getElement(const Qname &element, bool checkImports=true) const
ConstTypeList * getAllTypes() const
int getTypeId(const Qname &, bool create=false)
bool addImport(std::string ns, std::string location="")
AttributeGroup * getAttributeGroup(const Qname &name)
bool isBasicType(int sType) const
void resolveForwardElementRefs(const std::string &name, Element &e)
std::string getNamespace() const
int getBaseTypeId() const
std::string getName() const
virtual bool isSimple() const =0
Schema::ContentModelType getContentModel() const
std::string getNamespace(std::string prefix)
void setFeature(std::string feature, bool value)
const std::string SchemaUri
int parseInt(std::string s, int radix=10)
bool WSDLPULL_EXPORT fetchUri(std::string uri, std::string &path)
std::ostream & dbsp(std::ostream &str)