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) {
843 while (xParser_->getEventType() != xParser_->START_TAG)
846 if(elemName==
"selector"){
847 c->setSelector(xParser_->getAttributeValue(
"",
"xpath"));
850 else if(elemName==
"field"){
851 c->addField(xParser_->getAttributeValue(
"",
"xpath"));
866 attcnt = xParser_->getAttributeCount();
867 for (
int i = 0; i < attcnt; i++)
869 std::string attr = xParser_->getAttributeName(i);
870 if (
"namespace" == attr)
871 ns = xParser_->getAttributeValue(i);
873 else if (
"minOccurs" == attr)
876 else if (
"maxOccurs" == attr)
878 if (
"unbounded" == xParser_->getAttributeValue(i))
883 error(
"<element>:Invalid value for maxOccurs",1);
888 else if (
"processContents" == attr ||
"id" == attr) {
893 error(
"<any>:Unsupported Attribute "+attr,2);
899 if (xParser_->getEventType() == xParser_->END_TAG)
901 if (xParser_->getName() ==
"any")
905 xParser_->nextToken();
926 bool qualified =
true;
929 attcnt = xParser_->getAttributeCount();
930 for (
int i = 0; i < attcnt; i++)
932 std::string attr = xParser_->getAttributeName(i);
933 if (
"namespace" == attr)
934 ns = xParser_->getAttributeValue(i);
936 else if (
"processContents" == attr ||
"id" == attr)
942 error(
"<anyAttribute>:Unsupported Attribute "+attr,1);
949 cType->addAttribute(a);
951 while (xParser_->getName() ==
"annotation")
963SchemaParser::parseAttribute(
bool & fwdRef)
965 std::string name, fixedVal, defaultVal;
966 int type_id = 0, attcnt;
967 bool qualified =
false, use =
false;
971 attcnt = xParser_->getAttributeCount();
972 for (
int i = 0; i < attcnt; i++) {
973 std::string attName = xParser_->getAttributeName(i);
974 std::string attNs=xParser_->getAttributeNamespace(i);
975 std::string attVal=xParser_->getAttributeValue(i);
978 if (
"name" == attName)
980 else if (
"type" == attName) {
982 error(
"<attribute>:type and ref are mutually exclusive in element decl");
983 Qname typeName(attVal);
984 typeName.setNamespace(xParser_->
988 error(
"<attribute>:Could not resolve type " +
989 typeName.getNamespace() +
990 ":" +typeName.getLocalName(),1);
992 else if (
"form" == attName) {
993 if (
"qualified" == attVal)
998 else if (
"ref" == attName) {
1000 error(
"<attribute>:name and ref are mutually exclusive in element decl");
1002 error(
"<attribute>:type and ref are mutually exclusive in element decl");
1003 refAttribute = attVal;
1010 if(i >=0 && importedSchemas_[i].sParser){
1011 a=importedSchemas_[i].sParser->getAttribute(refAttribute);
1020 lForwardAttributeRefs_.push_back(refAttribute);
1023 name = a->getName();
1024 type_id = a->getType();
1025 qualified = a->isQualified();
1026 if (defaultVal.empty())
1027 defaultVal = a->defaultVal();
1028 if (fixedVal.empty())
1029 fixedVal = a->fixedVal();
1032 else if (
"default" == attName) {
1033 if (fixedVal.empty())
1034 defaultVal = attVal;
1037 (
"<attribute>:fixed and default cannot occur together");
1039 else if (
"fixed" == attName) {
1040 if (defaultVal.empty())
1043 error(
"<attribute>:fixed and default cannot occur together");
1045 else if (
"use" == attName) {
1046 if (attVal ==
"required")
1053 if(!attNs.empty() && ((n=checkImport(attNs))!=-1)){
1057 error(
"<attribute>:Unsupported attribute {"+ attNs+
"}:"+attName,2);
1064 xParser_->nextTag();
1065 if (xParser_->getEventType() == xParser_->END_TAG)
1067 if (xParser_->getName() ==
"attribute")
1071 while (xParser_->getEventType() != xParser_->START_TAG)
1072 xParser_->nextTag();
1075 else if (xParser_->getName() ==
"simpleType")
1077 XSDType *elemType = parseSimpleType();
1080 type_id = typesTable_.addType(elemType);
1083 else if (xParser_->getName() ==
"annotation")
1086 error(
"<attribute>:Syntax error or unkown tag "+xParser_->getName());
1101SchemaParser::parseSimpleType()
1103 SimpleType *st =
new SimpleType(tnsUri_);
1104 int basetype_id = 0;
1106 attcnt = xParser_->getAttributeCount();
1107 for (
int i = 0; i < attcnt; i++)
1109 if (
"name" == xParser_->getAttributeName(i))
1110 st->setName(xParser_->getAttributeValue(i));
1113 error(
"<simpleType> :" + xParser_->getAttributeName(i) +
1114 ":Unknown/Unsupported attribute ",2);
1119 xParser_->nextTag();
1120 if (xParser_->getEventType() == xParser_->END_TAG)
1122 if (xParser_->getName() ==
"simpleType")
1126 while (xParser_->getEventType() != xParser_->START_TAG)
1127 xParser_->nextTag();
1129 if (xParser_->getName() ==
"restriction")
1131 attcnt = xParser_->getAttributeCount();
1132 for (
int i = 0; i < attcnt; i++)
1134 if (
"base" == xParser_->getAttributeName(i))
1136 Qname typeName(xParser_->getAttributeValue(i));
1137 typeName.setNamespace(xParser_->
1140 st->setBaseType(basetype_id =
1142 if (basetype_id == 0)
1143 error(
"<simpleType>:" +
1144 xParser_->getAttributeValue(i) +
1145 ":Unknown base type ",1);
1148 error(
"<simpleType>:" + xParser_->getAttributeName(i) +
1149 ":Unknown/Unsupported attribute for <restriction>",2);
1151 parseRestriction(st);
1153 else if (xParser_->getName() ==
"union"){
1155 std::string members = xParser_->getAttributeValue(
"",
"memberTypes");
1157 while(s < members.length()){
1158 while(members[s]==
' ')s++;
1159 std::string type = members.substr(s,members.find(
' ',s)-s);
1160 Qname typeName(type);
1161 typeName.setNamespace(xParser_->getNamespace(typeName.getPrefix()));
1163 st->setUnionType(basetype_id);
1167 xParser_->nextTag();
1168 while(xParser_->getName() ==
"simpleType"){
1169 XSDType * t = parseSimpleType();
1172 st->setUnionType(i);
1173 xParser_->nextTag();
1176 else if(xParser_->getName() ==
"list"){
1178 basetype_id =
getTypeId(xParser_->getAttributeValue(
"",
"itemType"));
1179 st->setListType(basetype_id);
1180 xParser_->nextTag();
1182 else if (xParser_->getName() ==
"annotation")
1185 error(
"<simpleType>:Syntax error");
1192SchemaParser::parseRestriction(
SimpleType * st,
1195 if (st->getBaseTypeId() == 0)
1196 error(
"<restriction>:unkown BaseType",1);
1199 xParser_->nextTag();
1200 if (xParser_->getEventType() == xParser_->END_TAG)
1202 if (xParser_->getName() ==
"restriction")
1205 xParser_->nextTag();
1206 if (xParser_->getName() ==
"restriction"
1207 && xParser_->getEventType() == xParser_->END_TAG)
1210 while (xParser_->getName() ==
"annotation") {
1212 xParser_->nextTag();
1214 if(xParser_->getName()==
"attribute" && ct!=0){
1216 Attribute a=parseAttribute(f);
1217 ct->addAttribute(a,f);
1219 else if (st->isvalidFacet(xParser_->getName())){
1222 st->setFacetValue(xParser_->getName(),
1223 xParser_->getAttributeValue(
"",
"value"));
1225 error(
"<restriction>:" + xParser_->getName() +
1226 " is not a valid facet /attribute for the type",1);
1232SchemaParser::parseComplexContent(
ComplexType * ct)
1234 int attcnt = xParser_->getAttributeCount();
1239 xParser_->nextTag();
1241 while (xParser_->getName() ==
"annotation") {
1243 xParser_->nextTag();
1246 if (xParser_->getName() ==
"restriction") {
1247 attcnt = xParser_->getAttributeCount();
1248 for (i = 0; i < attcnt; i++) {
1249 if (
"base" == xParser_->getAttributeName(i))
1251 typeName = xParser_->getAttributeValue(i);
1256 ct->setBaseType(
getTypeId(typeName,
true),
1259 else if (xParser_->getName() ==
"extension") {
1260 attcnt = xParser_->getAttributeCount();
1261 for (i = 0; i < attcnt; i++) {
1262 if (
"base" == xParser_->getAttributeName(i)) {
1263 typeName = xParser_->getAttributeValue(i);
1268 ct->setBaseType(
getTypeId(typeName,
true),
1272 xParser_->nextTag();
1273 while (xParser_->getName() ==
"annotation") {
1275 xParser_->nextTag();
1279 std::string elemName=xParser_->getName();
1280 ContentModel * cm=0;
1281 if (elemName ==
"all"){
1284 else if (elemName ==
"sequence"){
1287 else if (elemName ==
"choice"){
1293 ct->setContents(cm);
1294 xParser_->nextTag();
1298 while (xParser_->getEventType() != xParser_->END_TAG){
1300 if (xParser_->getName() ==
"attribute") {
1302 Attribute a=parseAttribute(f);
1303 ct->addAttribute(a,f);
1305 else if(xParser_->getName() ==
"attributeGroup")
1307 parseAttributeGroup(ct);
1310 else if (xParser_->getName() ==
"anyAttribute")
1311 addAnyAttribute(ct);
1313 xParser_->nextTag();
1318 if (xParser_->getEventType() == xParser_->END_TAG)
1319 if ((xParser_->getName() ==
"restriction" ||
1320 xParser_->getName() ==
"extension") )
1322 xParser_->nextTag();
1326 xParser_->nextTag();
1334 xParser_->nextTag();
1335 if (xParser_->getName() ==
"restriction")
1337 SimpleType *st =
new SimpleType(tnsUri_);
1338 int attcnt = xParser_->getAttributeCount();
1339 int basetype_id = 0;
1340 for (
int i = 0; i < attcnt; i++)
1342 if (
"base" == xParser_->getAttributeName(i))
1344 Qname typeName(xParser_->getAttributeValue(i));
1347 st->setBaseType(basetype_id =
getTypeId(typeName,
true));
1348 if (basetype_id == 0)
1349 error(
"<simpleContent> :" +
1350 xParser_->getAttributeValue(i) +
1351 ":Unknown base type ",1);
1355 error(
"<simpleContent> :" + xParser_->getAttributeName(i) +
1356 ":Unknown/Unsupported attribute ",2);
1358 parseRestriction(st,ct);
1359 int typeId = typesTable_.addType(st);
1360 ct->setSimpleContentType(typeId);
1363 else if (xParser_->getName() ==
"extension")
1367 int attcnt = xParser_->getAttributeCount();
1368 int basetype_id = 0;
1369 for (
int i = 0; i < attcnt; i++)
1371 if (
"base" == xParser_->getAttributeName(i))
1373 Qname typeName(xParser_->getAttributeValue(i));
1376 ct->setSimpleContentType(basetype_id =
1378 if (basetype_id == 0)
1379 error(
"<simpleContent> :" +
1380 xParser_->getAttributeValue(i) +
1381 ":Unknown base type ",1);
1385 error(
"<simpleContent> :" + xParser_->getAttributeName(i) +
1386 ":Unknown/Unsupported attribute ");
1388 xParser_->nextTag();
1392 if (xParser_->getName() ==
"attribute")
1395 Attribute a=parseAttribute(f);
1396 ct->addAttribute(a,f);
1400 else if(xParser_->getName() ==
"attributeGroup")
1402 parseAttributeGroup(ct);
1406 else if (xParser_->getName() ==
"anyAttribute")
1407 addAnyAttribute(ct);
1410 xParser_->nextTag();
1414 (xParser_->getName() ==
"extension"
1415 && xParser_->getEventType() == xParser_->END_TAG))
1416 error(
"<simpleContent> :Syntax error :extension");
1418 xParser_->nextTag();
1420 (xParser_->getName() ==
"simpleContent"
1421 && xParser_->getEventType() == xParser_->END_TAG))
1422 error(
"<simpleContent> :Syntax error ");
1427SchemaParser::parseRedefine()
1430 resolveFwdRefs_=
false;
1431 parseSchema(
"redefine");
1432 resolveFwdRefs_=
true;
1437SchemaParser::parseInclude()
1440 std::string loc = xParser_->getAttributeValue(
"",
"schemaLocation");
1447 if ( loc.find(
"/",0) != 0 &&
1448 loc.find(
"file:/",0) == std::string::npos &&
1449 loc.find(
"http://") == std::string::npos)
1457 std::string schemaconf= confPath_ +
"schema.conf";
1459 ConfigFile cf(schemaconf);
1460 cf.readInto<std::string>(loc,loc);
1461 }
catch (
const ConfigFile::file_not_found & e) {}
1475 xsdStream.open(fname_.c_str());
1477 XmlPullParser * xpp =
new XmlPullParser(xsdStream);
1478 XmlPullParser * tmpXparser=xParser_;
1483 while (xParser_->getEventType() != xParser_->END_DOCUMENT){
1484 xParser_->nextTag();
1485 if (xParser_->getEventType() == xParser_->START_TAG &&
1486 xParser_->getName() ==
"schema"){
1487 resolveFwdRefs_=
false;
1490 error(
"Error while parsing the included schema " + loc);
1493 resolveFwdRefs_=
true;
1498 xParser_=tmpXparser;
1503 error(
"Error while opening the included schema " + loc);
1508 error(
"schemaLocation is a required attribute for <include>");
1511 xParser_->nextTag();
1516SchemaParser::parseImport()
1519 std::string xsdFile;
1520 std::string ns = xParser_->getAttributeValue(
"",
"namespace");
1521 std::string loc=xParser_->getAttributeValue(
"",
"schemaLocation");
1524 return parseInclude();
1534 if ( !loc.empty() &&
1535 loc.find(
"/",0) != 0 &&
1536 loc.find(
"file:/",0) == std::string::npos &&
1537 loc.find(
"http://") == std::string::npos)
1543 std::string schemaconf= confPath_ +
"schema.conf";
1545 ConfigFile cf(schemaconf);
1546 cf.readInto<std::string>(loc,loc);
1547 }
catch (
const ConfigFile::file_not_found &e) {}
1562 for (
size_t i = 0; i < importedSchemas_.size(); i++) {
1564 if(importedSchemas_[i].sParser ) {
1565 sp->addImport(importedSchemas_[i].sParser);
1569 if(sp->parseSchemaTag())
1572 error(
"Error while parsing imported namespace "+ns,0);
1577 error(
"could not import namespace from location "+loc);
1586 error(
"Imported namespace "+ns+
" from " + loc,2);
1589 error(
"No location supplied for the import"+ns,2);
1591 xParser_->nextTag();
1616 if (typens.empty()||
1617 typens == tnsUri_ ||
1620 return typesTable_.getTypeId(type, create);
1624 if (importedSchemas_.size() == 0 && create) {
1626 return typesTable_.addExternalTypeId(type, 0);
1631 for (
size_t i = 0; i < importedSchemas_.size(); i++) {
1635 if(importedSchemas_[i].sParser ) {
1637 typeId = importedSchemas_[i].sParser->getTypeId(type,
false);
1641 return typesTable_.addExternalTypeId(type,
1642 (
XSDType *) importedSchemas_[i].sParser->getType(typeId));
1652 return typesTable_.addExternalTypeId(type, 0);
1663 int unresolved=typesTable_.getNumExtRefs();
1664 if(unresolved > 0) {
1665 for (
int i = 0; i < unresolved; i++){
1667 Qname & type = typesTable_.getExtRefName(i);
1668 int localId = typesTable_.getExtRefType(i);
1672 for (
size_t n = 0; n < importedSchemas_.size(); n++)
1676 if(importedSchemas_[n].sParser){
1677 typeId = importedSchemas_[n].sParser->getTypeId(type);
1679 typesTable_.addExtType((
XSDType *) importedSchemas_[n].sParser->getType(typeId),
1687 logFile_<<
"Undefined type "<<type<<std::endl;
1691 if (typesTable_.detectUndefinedTypes())
1693 typesTable_.printUndefinedTypes(logFile_);logFile_.flush();
1694 logFile_<<
"Unresolved types in namespace "<<tnsUri_<<std::endl;
1708SchemaParser::resolveForwardElementRefs()
1711 if (lForwardElemRefs_.empty())
1713 for (list < Qname >::iterator pQnames = lForwardElemRefs_.begin();
1714 pQnames != lForwardElemRefs_.end(); pQnames++) {
1723 error(
"Could not resolve element reference "+pQnames->getLocalName(),1);
1728 error(
"Unresolved element references",1);
1733SchemaParser::resolveForwardAttributeRefs()
1736 if (lForwardAttributeRefs_.empty())
1738 for (list < Qname >::iterator pQnames = lForwardAttributeRefs_.begin();
1739 pQnames != lForwardAttributeRefs_.end(); pQnames++)
1743 typesTable_.resolveForwardAttributeRefs(pQnames-> getLocalName(), *a);
1745 error(
"Could not resolve attribute reference {"+pQnames->getNamespace()
1746 +
"}"+pQnames->getLocalName(),1);
1751 error(
"Unresolved attributes references");
1766 for (std::list<Element>::const_iterator eli=lElems_.begin();
1767 eli!= lElems_.end();
1773 else if (checkImports)
1775 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1777 if ( importedSchemas_[i].ns == typens)
1779 if(importedSchemas_[i].sParser )
1781 return importedSchemas_[i].sParser->getElement(element);
1799 for(std::list<Attribute>::iterator ali=lAttributes_.begin();
1800 ali!=lAttributes_.end();
1806 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1808 if ( importedSchemas_[i].ns == typens)
1810 if(importedSchemas_[i].sParser )
1812 return importedSchemas_[i].sParser->getAttribute(attribute);
1831 for (std::list<Group>::iterator gli =lGroups_.begin();
1832 gli!= lGroups_.end();
1840 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1842 if ( importedSchemas_[i].ns == typens)
1844 if(importedSchemas_[i].sParser )
1846 return importedSchemas_[i].sParser->getGroup(name);
1864 for (AttributeGroupList::iterator agli = lAttributeGroups_.begin();
1865 agli!= lAttributeGroups_.end();
1873 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1875 if ( importedSchemas_[i].ns == typens)
1877 if(importedSchemas_[i].sParser )
1879 return importedSchemas_[i].sParser->getAttributeGroup(name);
1897 return (
const XSDType *) typesTable_.getTypePtr(
id);
1910 const XSDType* pType = (
const XSDType *) typesTable_.getTypePtr(
id);
1911 if (!checkImports) {
1944 for (
size_t i = 0; i < importedSchemas_.size(); i++)
1946 if ( importedSchemas_[i].ns == nameSpace)
1948 return importedSchemas_[i].sParser;
1954list < const XSDType *>*
1957 list < const XSDType *>*pLTypes =
new list < const XSDType * >;
1961 pLTypes->push_back(pType);
1970 return typesTable_.getNumTypes();
1977 return lElems_.size();
1984 return lAttributes_.size();
1991 for (
size_t i=0;i<schemaParsers.size() ;i++){
2009 importedSchemas_[i].sParser=sp;
2017 importedSchemas_.push_back(imp);
2025 for(
size_t i=0;i<importedSchemas_.size();i++) {
2027 if (importedSchemas_[i].sParser)
2028 sp->
addImport(importedSchemas_[i].sParser);
2033SchemaParser::checkImport(std::string nsp)
const
2035 for(
size_t i=0;i<importedSchemas_.size();i++)
2037 if(importedSchemas_[i].ns==nsp)
2045 std::string location)
2048 int i= checkImport(ns);
2053 importedSchemas_.push_back(imp);
2054 i =importedSchemas_.size()-1;
2059 if(location.empty())
2061 std::string xsdFile;
2072 importedSchemas_[i].sParser=sp;
2082void SchemaParser::error(std::string mesg,
int level)
2093 else if (level_ >=1 && level == 1){
2095 logFile_ <<
"Error @" << xParser_->
2096 getLineNumber() <<
":" << xParser_->
2099 else if (level_ >= 2 && level == 2) {
2101 logFile_ <<
"Alert @" << xParser_->
2102 getLineNumber() <<
":" << xParser_->
2135 id = (
static_cast<const SimpleType *
>(pType))->getBaseTypeId();
2146 return typesTable_.getAtomicTypeName(t);
2149 const XSDType * pType = (
const XSDType *) typesTable_.getTypePtr(t);
2159SchemaParser::makeListFromSoapArray (
ComplexType * ct)
2163 if(baseType->
getNamespace()==
"http://schemas.xmlsoap.org/soap/encoding/" &&
2164 baseType->
getName()==
"Array"){
2172 array = q.getLocalName();
2173 while (array[array.length()-1] ==
']' &&
2174 array[array.length()-2] ==
'[')
2175 array = array.substr(0,array.length()-2);
2177 std::string arrayNs = xParser_->
getNamespace(q.getPrefix());
2179 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)