bool XsdSchemaChecker::particleEqualsRecursively(const XsdParticle::Ptr &particle, const XsdParticle::Ptr &otherParticle) const
{
    // @see http://www.w3.org/TR/xmlschema11-1/#cos-particle-extend
    //TODO: find out what 'properties' of a particle should be checked here...

    if (particle->minimumOccurs() != otherParticle->minimumOccurs())
        return false;

    if (particle->maximumOccursUnbounded() != otherParticle->maximumOccursUnbounded())
        return false;

    if (particle->maximumOccurs() != otherParticle->maximumOccurs())
        return false;

    const XsdTerm::Ptr term = particle->term();
    const XsdTerm::Ptr otherTerm = otherParticle->term();

    if (term->isElement() && !(otherTerm->isElement()))
        return false;

    if (term->isModelGroup() && !(otherTerm->isModelGroup()))
        return false;

    if (term->isWildcard() && !(otherTerm->isWildcard()))
        return false;

    if (term->isElement()) {
        const XsdElement::Ptr element = term;
        const XsdElement::Ptr otherElement = otherTerm;

        if (element->name(m_namePool) != otherElement->name(m_namePool))
            return false;

        if (element->type()->name(m_namePool) != otherElement->type()->name(m_namePool))
            return false;
    }

    if (term->isModelGroup()) {
        const XsdModelGroup::Ptr group = term;
        const XsdModelGroup::Ptr otherGroup = otherTerm;

        if (group->particles().count() != otherGroup->particles().count())
            return false;

        for (int i = 0; i < group->particles().count(); ++i) {
            if (!particleEqualsRecursively(group->particles().at(i), otherGroup->particles().at(i)))
                return false;
        }
    }

    if (term->isWildcard()) {
    }

    return true;
}
Esempio n. 2
0
/**
 * Internal helper method that checks if the given @p particle contains an element with the
 * same name and type twice.
 */
static bool hasDuplicatedElementsInternal(const XsdParticle::Ptr &particle, const NamePool::Ptr &namePool, ElementHash &hash, XsdElement::Ptr &conflictingElement)
{
    const XsdTerm::Ptr term = particle->term();
    if (term->isElement()) {
        const XsdElement::Ptr mainElement(term);
        XsdElement::WeakList substGroups = mainElement->substitutionGroups();
        if (substGroups.isEmpty())
            substGroups << mainElement.data();

        for (int i = 0; i < substGroups.count(); ++i) {
            const XsdElement::Ptr element(substGroups.at(i));
            if (hash.contains(element->name(namePool))) {
                if (element->type()->name(namePool) != hash.value(element->name(namePool))->type()->name(namePool)) {
                    conflictingElement = element;
                    return true;
                }
            } else {
                hash.insert(element->name(namePool), element);
            }
        }
    } else if (term->isModelGroup()) {
        const XsdModelGroup::Ptr group(term);
        const XsdParticle::List particles = group->particles();
        for (int i = 0; i < particles.count(); ++i) {
            if (hasDuplicatedElementsInternal(particles.at(i), namePool, hash, conflictingElement))
                return true;
        }
    }

    return false;
}
void XsdSchemaDebugger::dumpElement(const XsdElement::Ptr &element)
{
    QStringList disallowedSubstGroup;
    if (element->disallowedSubstitutions() & XsdElement::RestrictionConstraint)
        disallowedSubstGroup << QLatin1String("restriction");
    if (element->disallowedSubstitutions() & XsdElement::ExtensionConstraint)
        disallowedSubstGroup << QLatin1String("extension");
    if (element->disallowedSubstitutions() & XsdElement::SubstitutionConstraint)
        disallowedSubstGroup << QLatin1String("substitution");


    qDebug() << "Name:" << element->displayName(m_namePool);
    qDebug() << "IsAbstract:" << (element->isAbstract() ? "yes" : "no");
    qDebug() << "Type:" << element->type()->displayName(m_namePool);
    qDebug() << "DisallowedSubstitutionGroups:" << disallowedSubstGroup.join(QLatin1String("' "));
}