XMLElementDecl* SchemaGrammar::putElemDecl (const unsigned int uriId , const XMLCh* const baseName , const XMLCh* const prefixName , const XMLCh* const , unsigned int scope , const bool notDeclared) { SchemaElementDecl* retVal = new (fMemoryManager) SchemaElementDecl ( prefixName , baseName , uriId , SchemaElementDecl::Any , Grammar::TOP_LEVEL_SCOPE , fMemoryManager ); if(notDeclared) { if(!fElemNonDeclPool) fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); retVal->setId(fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal)); } else { retVal->setId(fElemDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal)); } return retVal; }
// ----------------------------------------------------------------------- // Virtual methods // ----------------------------------------------------------------------- XMLElementDecl* SchemaGrammar::findOrAddElemDecl (const unsigned int uriId , const XMLCh* const baseName , const XMLCh* const prefixName , const XMLCh* const qName , unsigned int scope , bool& wasAdded ) { // See it it exists SchemaElementDecl* retVal = (SchemaElementDecl*) getElemDecl(uriId, baseName, qName, scope); // if not, then add this in if (!retVal) { retVal = new (fMemoryManager) SchemaElementDecl ( prefixName , baseName , uriId , SchemaElementDecl::Any , Grammar::TOP_LEVEL_SCOPE , fMemoryManager ); if(!fElemNonDeclPool) fElemNonDeclPool = new (fMemoryManager) RefHash3KeysIdPool<SchemaElementDecl>(29, true, 128, fMemoryManager); const unsigned int elemId = fElemNonDeclPool->put((void*)retVal->getBaseName(), uriId, scope, retVal); retVal->setId(elemId); wasAdded = true; } else { wasAdded = false; } return retVal; }
void process(char* const xmlFile) { // // Create a Schema validator to be used for our validation work. Then create // a SAX parser object and pass it our validator. Then, according to what // we were told on the command line, set it to validate or not. He owns // the validator, so we have to allocate it. // SAXParser parser; parser.setValidationScheme(SAXParser::Val_Always); parser.setDoNamespaces(true); parser.setDoSchema(true); parser.parse(xmlFile); if (parser.getErrorCount()) { XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl; return; } if (!parser.getValidator().handlesSchema()) { XERCES_STD_QUALIFIER cout << "\n Non schema document, no output available\n" << XERCES_STD_QUALIFIER endl; return; } Grammar* rootGrammar = parser.getRootGrammar(); if (!rootGrammar || rootGrammar->getGrammarType() != Grammar::SchemaGrammarType) { XERCES_STD_QUALIFIER cout << "\n Non schema grammar, no output available\n" << XERCES_STD_QUALIFIER endl; return; } // // Now we will get an enumerator for the element pool from the validator // and enumerate the elements, printing them as we go. For each element // we get an enumerator for its attributes and print them also. // SchemaGrammar* grammar = (SchemaGrammar*) rootGrammar; RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = grammar->getElemEnumerator(); if (!elemEnum.hasMoreElements()) { XERCES_STD_QUALIFIER cout << "\nThe validator has no elements to display\n" << XERCES_STD_QUALIFIER endl; return; } while(elemEnum.hasMoreElements()) { const SchemaElementDecl& curElem = elemEnum.nextElement(); // Name XERCES_STD_QUALIFIER cout << "Name:\t\t\t" << StrX(curElem.getFullName()) << "\n"; // Model Type XERCES_STD_QUALIFIER cout << "Model Type:\t\t"; switch( curElem.getModelType() ) { case SchemaElementDecl::Empty: XERCES_STD_QUALIFIER cout << "Empty"; break; case SchemaElementDecl::Any: XERCES_STD_QUALIFIER cout << "Any"; break; case SchemaElementDecl::Mixed_Simple: XERCES_STD_QUALIFIER cout << "Mixed_Simple"; break; case SchemaElementDecl::Mixed_Complex: XERCES_STD_QUALIFIER cout << "Mixed_Complex"; break; case SchemaElementDecl::Children: XERCES_STD_QUALIFIER cout << "Children"; break; case SchemaElementDecl::Simple: XERCES_STD_QUALIFIER cout << "Simple"; break; case SchemaElementDecl::ElementOnlyEmpty: XERCES_STD_QUALIFIER cout << "ElementOnlyEmpty"; break; default: XERCES_STD_QUALIFIER cout << "Unknown"; break; } XERCES_STD_QUALIFIER cout << "\n"; // Create Reason XERCES_STD_QUALIFIER cout << "Create Reason:\t"; switch( curElem.getCreateReason() ) { case XMLElementDecl::NoReason: XERCES_STD_QUALIFIER cout << "Empty"; break; case XMLElementDecl::Declared: XERCES_STD_QUALIFIER cout << "Declared"; break; case XMLElementDecl::AttList: XERCES_STD_QUALIFIER cout << "AttList"; break; case XMLElementDecl::InContentModel: XERCES_STD_QUALIFIER cout << "InContentModel"; break; case XMLElementDecl::AsRootElem: XERCES_STD_QUALIFIER cout << "AsRootElem"; break; case XMLElementDecl::JustFaultIn: XERCES_STD_QUALIFIER cout << "JustFaultIn"; break; default: XERCES_STD_QUALIFIER cout << "Unknown"; break; } XERCES_STD_QUALIFIER cout << "\n"; // Content Spec Node processContentSpecNode( curElem.getContentSpec() ); // Misc Flags int mflags = curElem.getMiscFlags(); if( mflags !=0 ) { XERCES_STD_QUALIFIER cout << "Misc. Flags:\t"; } if ( mflags & SchemaSymbols::XSD_NILLABLE ) XERCES_STD_QUALIFIER cout << "Nillable "; if ( mflags & SchemaSymbols::XSD_ABSTRACT ) XERCES_STD_QUALIFIER cout << "Abstract "; if ( mflags & SchemaSymbols::XSD_FIXED ) XERCES_STD_QUALIFIER cout << "Fixed "; if( mflags !=0 ) { XERCES_STD_QUALIFIER cout << "\n"; } // Substitution Name SchemaElementDecl* subsGroup = curElem.getSubstitutionGroupElem(); if( subsGroup ) { const XMLCh* uriText = parser.getURIText(subsGroup->getURI()); XERCES_STD_QUALIFIER cout << "Substitution Name:\t" << StrX(uriText) << "," << StrX(subsGroup->getBaseName()) << "\n"; } // Content Model const XMLCh* fmtCntModel = curElem.getFormattedContentModel(); if( fmtCntModel != NULL ) { XERCES_STD_QUALIFIER cout << "Content Model:\t" << StrX(fmtCntModel) << "\n"; } const ComplexTypeInfo* ctype = curElem.getComplexTypeInfo(); if( ctype != NULL) { XERCES_STD_QUALIFIER cout << "ComplexType:\n"; XERCES_STD_QUALIFIER cout << "\tTypeName:\t" << StrX(ctype->getTypeName()) << "\n"; ContentSpecNode* cSpecNode = ctype->getContentSpec(); processContentSpecNode(cSpecNode, true ); } // Datatype DatatypeValidator* dtValidator = curElem.getDatatypeValidator(); processDatatypeValidator( dtValidator ); // Get an enumerator for this guy's attributes if any if ( curElem.hasAttDefs() ) { processAttributes( curElem.getAttDefList() ); } XERCES_STD_QUALIFIER cout << "--------------------------------------------"; XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; } return; }
XERCES_CPP_NAMESPACE_BEGIN bool SubstitutionGroupComparator::isEquivalentTo(QName* const anElement , QName* const exemplar) { if (!anElement && !exemplar) return true; if ((!anElement && exemplar) || (anElement && !exemplar)) return false; if (XMLString::equals(anElement->getLocalPart(), exemplar->getLocalPart()) && (anElement->getURI() == exemplar->getURI())) return true; // they're the same! if (!fGrammarResolver || !fStringPool ) { ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::SubGrpComparator_NGR, anElement->getMemoryManager()); } unsigned int uriId = anElement->getURI(); if (uriId == XMLContentModel::gEOCFakeId || uriId == XMLContentModel::gEpsilonFakeId || uriId == XMLElementDecl::fgPCDataElemId || uriId == XMLElementDecl::fgInvalidElemId) return false; const XMLCh* uri = fStringPool->getValueForId(uriId); const XMLCh* localpart = anElement->getLocalPart(); // In addition to simply trying to find a chain between anElement and exemplar, // we need to make sure that no steps in the chain are blocked. // That is, at every step, we need to make sure that the element // being substituted for will permit being substituted // for, and whether the type of the element will permit derivations in // instance documents of this sort. if (!uri) return false; SchemaGrammar *sGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(uri); if (!sGrammar || sGrammar->getGrammarType() == Grammar::DTDGrammarType) return false; SchemaElementDecl* anElementDecl = (SchemaElementDecl*) sGrammar->getElemDecl(uriId, localpart, 0, Grammar::TOP_LEVEL_SCOPE); if (!anElementDecl) return false; SchemaElementDecl* pElemDecl = anElementDecl->getSubstitutionGroupElem(); bool foundIt = false; while (pElemDecl) //(substitutionGroupFullName) { if (XMLString::equals(pElemDecl->getBaseName(), exemplar->getLocalPart()) && (pElemDecl->getURI() == exemplar->getURI())) { // time to check for block value on element if((pElemDecl->getBlockSet() & SchemaSymbols::XSD_SUBSTITUTION) != 0) return false; foundIt = true; break; } pElemDecl = pElemDecl->getSubstitutionGroupElem(); }//while if (!foundIt) return false; // this will contain anElement's complexType information. ComplexTypeInfo *aComplexType = anElementDecl->getComplexTypeInfo(); int exemplarBlockSet = pElemDecl->getBlockSet(); if(!aComplexType) { // check on simpleType case DatatypeValidator *anElementDV = anElementDecl->getDatatypeValidator(); DatatypeValidator *exemplarDV = pElemDecl->getDatatypeValidator(); return((anElementDV == 0) || ((anElementDV == exemplarDV) || ((exemplarBlockSet & SchemaSymbols::XSD_RESTRICTION) == 0))); } // now we have to make sure there are no blocks on the complexTypes that this is based upon int anElementDerivationMethod = aComplexType->getDerivedBy(); if((anElementDerivationMethod & exemplarBlockSet) != 0) return false; // this will contain exemplar's complexType information. ComplexTypeInfo *exemplarComplexType = pElemDecl->getComplexTypeInfo(); for(ComplexTypeInfo *tempType = aComplexType; tempType != 0 && tempType != exemplarComplexType; tempType = tempType->getBaseComplexTypeInfo()) { if((tempType->getBlockSet() & anElementDerivationMethod) != 0) return false; }//for return true; }