69 #include <QtCore/QFile> 70 #include <QtXmlPatterns/QXmlQuery> 71 #include <QtXmlPatterns/QXmlResultItems> 83 if (term->isElement()) {
85 }
else if (term->isWildcard()) {
101 , m_namePool(m_context->namePool())
102 , m_xsiNilName(m_namePool->allocateQName(CommonNamespaces::
XSI,
QLatin1String(
"nil")))
103 , m_xsiTypeName(m_namePool->allocateQName(CommonNamespaces::
XSI,
QLatin1String(
"type")))
104 , m_xsiSchemaLocationName(m_namePool->allocateQName(CommonNamespaces::
XSI,
QLatin1String(
"schemaLocation")))
105 , m_xsiNoNamespaceSchemaLocationName(m_namePool->allocateQName(CommonNamespaces::
XSI,
QLatin1String(
"noNamespaceSchemaLocation")))
106 , m_documentUri(documentUri)
142 bool hasStateMachine =
false;
145 if (!
validate(hasStateMachine, processedElement))
150 if (processedElement) {
173 while (it.hasNext()) {
176 error(QtXmlPatterns::tr(
"There is one IDREF value with no corresponding ID: %1.").arg(
formatKeyword(
id)));
203 error(QtXmlPatterns::tr(
"Loaded schema file is invalid."));
218 if ((parts.
count()%2) == 1) {
223 for (
int i = 0; i < parts.
count(); i += 2) {
232 error(QtXmlPatterns::tr(
"xsi:schemaLocation namespace %1 has already appeared earlier in the instance document.").arg(
formatKeyword(parts.
at(i))));
236 QUrl url(parts.
at(i + 1));
237 if (url.isRelative()) {
254 error(QtXmlPatterns::tr(
"xsi:noNamespaceSchemaLocation cannot appear after the first no-namespace element or attribute."));
258 QUrl url(schemaLocation);
272 error(QtXmlPatterns::tr(
"No schema defined for validation."));
307 processedElement = element;
324 processedElement = element;
333 if (!elementDeclaration) {
352 elementDeclaration->
setType(elementType);
356 if (!elementDeclaration) {
365 hasStateMachine =
true;
393 innerParticle->
setTerm(wildcard);
398 outerParticle->
setTerm(outerModelGroup);
401 hasStateMachine =
true;
428 stateMachine = stateMachine.
toDFA();
437 bool isNilled =
false;
466 error(QtXmlPatterns::tr(
"Element contains content although it is nillable."));
472 error(QtXmlPatterns::tr(
"Fixed value constraint not allowed if element is nillable."));
496 SchemaType::DerivationConstraints constraints = 0;
509 finalElementType = elementType;
546 elementAttributes.
subtract(allowedAttributes);
547 if (!elementAttributes.
isEmpty()) {
574 if (!checker.
isValidString(actualValue, type, errorMsg, &boundType)) {
603 for (
int i = 0; i < idRefs.
count(); ++i) {
615 const int count = uses.
count();
616 for (
int i = 0; i < count; ++i) {
695 hasStateMachine =
true;
732 for (
int i = 0; i < attributeUses.
count(); ++i)
733 attributeUseHash.
insert(attributeUses.
at(i)->attribute()->name(
m_namePool), attributeUses.
at(i));
739 QHashIterator<QXmlName, XsdAttributeUse::Ptr> usesIt(attributeUseHash);
740 while (usesIt.hasNext()) {
743 if (usesIt.value()->isRequired()) {
744 if (!attributes.
contains(usesIt.key())) {
755 QSetIterator<QXmlName>
it(attributes);
756 while (it.hasNext()) {
757 const QXmlName attributeName = it.next();
781 if (!attributeDeclaration) {
788 if (hasIDAttribute) {
789 error(QtXmlPatterns::tr(
"Element %1 contains two attributes of type %2.")
795 hasIDAttribute =
true;
846 if (!checker.
isValidString(actualValue, attributeType, errorMsg, &boundType)) {
847 error(QtXmlPatterns::tr(
"Content of attribute %1 does not match its type definition: %2.").arg(
formatKeyword(declaration->attribute()->displayName(
m_namePool))).arg(errorMsg));
854 if (!checker.
valuesAreEqual(actualValue, actualConstraintValue, attributeType)) {
855 error(QtXmlPatterns::tr(
"Content of attribute %1 does not match defined value constraint.").arg(
formatKeyword(declaration->attribute()->displayName(
m_namePool))));
866 for (
int i = 0; i < idRefs.
count(); ++i)
892 if (!checker.
isValidString(actualValue, attributeType, errorMsg, &boundType)) {
900 if (!checker.
valuesAreEqual(actualValue, actualConstraintValue, attributeType)) {
912 for (
int i = 0; i < idRefs.
count(); ++i)
941 for (
int i = 0; i < constraints.
count(); ++i) {
945 selectNodeSets(element, currentItem, constraint, targetNodeSet, qualifiedNodeSet);
957 for (
int i = 0; i < constraints.
count(); ++i) {
961 selectNodeSets(element, currentItem, constraint, targetNodeSet, qualifiedNodeSet);
978 QSetIterator<TargetNode>
it(qualifiedNodeSet);
979 while (it.hasNext()) {
981 QSetIterator<TargetNode> innerIt(qualifiedNodeSet);
982 while (innerIt.hasNext()) {
985 if (node == innerNode)
1008 if (targetNodeSet.
count() != qualifiedNodeSet.
count()) {
1018 QSetIterator<TargetNode>
it(qualifiedNodeSet);
1019 while (it.hasNext()) {
1022 for (
int i = 0; i < fieldItems.
count(); ++i) {
1026 if (declaration && declaration->
isNillable()) {
1027 error(QtXmlPatterns::tr(
"Key constraint %1 contains references nillable element %2.")
1050 QSetIterator<TargetNode>
it(qualifiedNodeSet);
1051 while (it.hasNext()) {
1054 bool foundMatching =
false;
1056 QSetIterator<TargetNode> keyIt(keySet);
1057 while (keyIt.hasNext()) {
1061 foundMatching =
true;
1066 if (!foundMatching) {
1086 for (
int i = 0; i < namespaceBindings.
count(); ++i) {
1092 query.setFocus(contextNode);
1115 for (
int i = 0; i < fields.
count(); ++i) {
1124 QXmlItem fieldItem(fieldResultItems.next());
1125 while (!fieldItem.isNull()) {
1126 fieldVector.
append(fieldItem);
1127 fieldItem = fieldResultItems.next();
1130 if (fieldVector.
count() > 1) {
1135 if (fieldVector.
count() == 1) {
1136 fieldItem = fieldVector.
first();
1179 targetNode.
addField(fieldItem, value, targetType);
1186 targetNodeSet.
insert(targetNode);
1188 item = resultItems.next();
1192 QSetIterator<TargetNode>
it(targetNodeSet);
1193 while (it.hasNext()) {
1196 qualifiedNodeSet.
insert(node);
1258 innerParticle->
setTerm(wildcard);
1263 outerParticle->
setTerm(outerModelGroup);
const QString & stringForLocalName(const QXmlName::LocalNameCode code) const
bool validateIdentityConstraint(const XsdElement::Ptr &element, const QXmlItem ¤tItem)
void setName(const QXmlName &name)
bool isStartElement() const
The complex type has further elements or attributes and text as content.
QString displayName(const QXmlName qName) const
void evaluateTo(QXmlResultItems *result) const
Starts the evaluation and makes it available in result.
static const AtomicType::Ptr xsID
XsdSchema::Ptr mergedSchema() const
QHash< QXmlName, TargetNode::Set > m_idcKeys
QSet< QString > m_processedNamespaces
QString qNameAttribute(const QXmlName &attributeName)
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual QNetworkAccessManager * networkAccessManager() const
void addSchema(const XsdSchema::Ptr &schema, const QUrl &url)
void setAssignedAttribute(const QXmlNodeModelIndex &index, const XsdAttribute::Ptr &attribute)
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
XsdStateMachine< TransitionType > toDFA() const
XsdStateMachine< XsdTerm::Ptr >::StateId addStartState(XsdStateMachine< XsdTerm::Ptr >::StateId state)
Represents a XSD element object.
static QString absentNamespace()
void setAssignedType(const QXmlNodeModelIndex &index, const SchemaType::Ptr &type)
A context for schema parsing and validation.
Represents a XSD model group object.
QList< QXmlName > namespaceBindings() const
Any namespace is allowed.
#define QT_END_NAMESPACE
This macro expands to.
XsdStateMachine< XsdTerm::Ptr >::StateId reset()
XsdElement::Ptr element(const QXmlName &name) const
virtual bool isSimpleType() const
bool validateElementType(const XsdElement::Ptr &declaration, const SchemaType::Ptr &type, bool isNilled, bool &hasStateMachine)
void addIdIdRefBinding(const QString &id, const NamedSchemaComponent::Ptr &binding)
QString formatKeyword(const QString &keyword)
virtual bool hasError() const
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
ProcessContents processContents() const
The attribute use has a fixed value set.
bool loadSchema(const QString &targetNamespace, const QUrl &location)
A smart pointer very similar to std::auto_ptr.
bool validateKeyIdentityConstraint(const XsdElement::Ptr &element, const XsdIdentityConstraint::Ptr &constraint, const TargetNode::Set &targetNodeSet, const TargetNode::Set &qualifiedNodeSet)
QXmlItem attributeItem(const QXmlName &name) const
T & first()
Returns a reference to the first item in the vector.
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
bool fieldsAreEqual(const TargetNode &other, const NamePool::Ptr &namePool, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection) const
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
XsdSchema::Ptr schema() const
SchemaType::Ptr m_idRefsType
The QXmlItem class contains either an XML node or an atomic value.
ValueConstraint::Ptr valueConstraint() const
XsdIdentityConstraint::List identityConstraints() const
void addField(const QXmlItem &item, const QString &data, const SchemaType::Ptr &type)
void setParticles(const XsdParticle::List &particles)
The attribute is not allowed to be there.
QPatternist::XsdSchemaParserContext::Ptr m_schemaParserContext
static bool hasIDAttributeUse(const XsdAttributeUse::List &uses)
const QXmlName m_xsiTypeName
XsdStateMachine< XsdTerm::Ptr >::StateId buildParticle(const XsdParticle::Ptr &particle, XsdStateMachine< XsdTerm::Ptr >::StateId endState)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
MergedSchemas m_mergedSchemas
QXmlName::NamespaceCode allocateNamespace(const QString &uri)
void setIsAbstract(bool abstract)
Represents a XSD wildcard object.
int count(const T &t) const
Returns the number of occurrences of value in the list.
const QLatin1String XSI("http://www.w3.org/2001/XMLSchema-instance")
void setMinimumOccurs(unsigned int occurrence)
Represents a XSD complexType object.
void addAdditionalNamespaceBinding(const QXmlName &binding)
const QXmlName m_xsiSchemaLocationName
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
XsdValidatedXmlNodeModel::Ptr m_model
XsdValidatingInstanceReader(XsdValidatedXmlNodeModel *model, const QUrl &documentUri, const XsdSchemaContext::Ptr &context)
The QVector class is a template class that provides a dynamic array.
A helper class for validating identity constraints.
The constraint is a keyref constraint.
SchemaType::Ptr typeByName(const QXmlName &name) const
QSet< NamedSchemaComponent::Ptr > idIdRefBindings(const QString &id) const
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
QStringList idIdRefBindingIds() const
virtual bool wxsTypeMatches(const SchemaType::Ptr &other) const =0
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
bool validateElement(const XsdElement::Ptr &declaration, bool &hasStateMachine)
SchemaTypeFactory::Ptr m_schemaTypeFactory
bool validateKeyRefIdentityConstraint(const XsdElement::Ptr &element, const XsdIdentityConstraint::Ptr &constraint, const TargetNode::Set &qualifiedNodeSet)
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
XsdAttribute::Ptr attributeByName(const QXmlName &name) const
QXmlName convertToQName(const QString &name) const
const T value(const Key &key) const
Returns the value associated with the key.
XsdAttributeUse::List attributeUses() const
The QXmlNamePool class is a table of shared strings referenced by instances of QXmlName.
ContentType::Ptr contentType() const
XsdWildcard::Ptr attributeWildcard() const
QSet< QString > m_processedSchemaLocations
void setProcessContents(ProcessContents contents)
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static const AtomicType::Ptr xsIDREF
SchemaType::Ptr type() const
static const AtomicType::Ptr xsString
void setMaximumOccurs(unsigned int occurrence)
static const SchemaType::Ptr xsAnyType
static AtomicValue::Ptr fromLexical(const QString &val)
SchemaType::Ptr assignedType(const QXmlNodeModelIndex &index) const
T * data() const
Returns a pointer to the shared data object.
void append(const T &t)
Inserts value at the end of the list.
bool selectNodeSets(const XsdElement::Ptr &element, const QXmlItem ¤tItem, const XsdIdentityConstraint::Ptr &constraint, TargetNode::Set &targetNodeSet, TargetNode::Set &qualifiedNodeSet)
virtual bool isElement() const
No constraints at all: the item must simply be well-formed XML.
#define QT_BEGIN_NAMESPACE
This macro expands to.
const TCastTarget * as() const
XsdElement::Ptr assignedElement(const QXmlNodeModelIndex &index) const
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
SchemaTypeFactory::Ptr schemaTypeFactory() const
There must be a top-level declaration for the item available, or the item must have an xsi:type...
static XsdFacet::Hash mergedFacetsForType(const SchemaType::Ptr &type, const XsdSchemaContext::Ptr &context)
void setAssignedElement(const QXmlNodeModelIndex &index, const XsdElement::Ptr &element)
bool contains(const T &value) const
QSet< QXmlName > attributeNames() const
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
QXmlQuery createXQuery(const QList< QXmlName > &namespaceBindings, const QXmlItem &contextNode, const QString &query) const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
XsdXPathExpression::List fields() const
AnySimpleType::Ptr type() const
QString expression() const
virtual bool isComplexType() const
The resource loader will report no error and return an empty QNetworkReply.
Represents a XSD particle object.
const T & at(int i) const
Returns the item at index position i in the list.
The schema instance reader.
The QStringList class provides a list of strings.
The namespace for the internal API of QtXmlPatterns.
virtual QString displayName(const NamePool::Ptr &namePool) const
The element has a fixed value set.
void append(const T &t)
Inserts value at the end of the vector.
const_iterator insert(const T &value)
void setDerivationMethod(DerivationMethod method)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
const QXmlName m_xsiNilName
static QString normalizedValue(const QString &value, const XsdFacet::Hash &facets)
void setIsAbstract(bool abstract)
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
XsdComplexType::Ptr m_anyType
void setName(const QXmlName &name)
bool isValidString(const QString &normalizedString, const AnySimpleType::Ptr &type, QString &errorMsg, AnySimpleType::Ptr *boundType=0) const
void setTerm(const XsdTerm::Ptr &term)
XsdComplexType::Ptr anyType()
static QString formatData(const QString &data)
SchemaType::Ptr type(const QXmlName &name) const
void setType(const SchemaType::Ptr &type)
QSet< T > & subtract(const QSet< T > &other)
virtual QXmlName name(const NamePool::Ptr &namePool) const
const T & at(int i) const
Returns the item at index position i in the vector.
The constraint is an unique constraint.
XsdXPathExpression::Ptr selector() const
QString localName(const QXmlNamePool &query) const
Returns the local name.
bool validateElementComplexType(const XsdElement::Ptr &declaration, const SchemaType::Ptr &type, bool isNilled, bool &hasStateMachine)
Implements the value instance of the xs:boolean type.
static QNetworkReply * load(const QUrl &uri, QNetworkAccessManager *const networkManager, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
Helper function that do NetworkAccessDelegator::get(), but does it blocked.
QString attribute(const QXmlName &name) const
The complex type has only simple type content (e.g. text, number etc.)
bool hasChildText() const
int emptyFieldsCount() const
NamespaceCode namespaceURI() const
bool valuesAreEqual(const QString &value, const QString &otherValue, const AnySimpleType::Ptr &type) const
bool validateAttributeWildcard(const QXmlName &attributeName, const XsdWildcard::Ptr &wildcard)
NamespaceConstraint::Ptr namespaceConstraint() const
void load(const QUrl &source, const QString &targetNamespace)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
A helper class that merges two schemas into one.
bool validate(bool &hasStateMachine, XsdElement::Ptr &element)
static const AtomicType::Ptr xsQName
A delegate class that wraps around a QAbstractXmlNodeModel and provides additional validation specifi...
void setIsNillable(bool nillable)
XsdElement::Ptr elementByName(const QXmlName &name) const
static bool wxsTypeMatches(const SchemaType::Ptr &type, const SchemaType::Ptr &otherType, QSet< SchemaType::Ptr > &visitedTypes, SchemaType::Ptr &conflictingType)
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
void setCompositor(ModelCompositor compositor)
bool isEndElement() const
An implementation of SourceLocationReflection that takes a QSourceLocation.
static const SchemaType::Ptr xsAnySimpleType
const QXmlName m_xsiNoNamespaceSchemaLocationName
bool hasAttribute(const QXmlName &name) const
static QTestResult::TestLocation location
void setAttributeWildcard(const XsdWildcard::Ptr &wildcard)
const QString & stringForNamespace(const QXmlName::NamespaceCode code) const
QXmlName allocateQName(const QString &uri, const QString &localName, const QString &prefix=QString())
Category category() const
AnySimpleType::Ptr primitiveType() const
ValueConstraint::Ptr valueConstraint() const
QSourceLocation sourceLocation() const
QExplicitlySharedDataPointer< XsdElement > Ptr
XsdAttribute::Ptr attribute(const QXmlName &name) const
XsdIdentityConstraint::Ptr referencedKey() const
const QLatin1String WXS("http://www.w3.org/2001/XMLSchema")
A state machine used for evaluation.
bool validateElementSimpleType(const XsdElement::Ptr &declaration, const SchemaType::Ptr &type, bool isNilled)
virtual SchemaType::Ptr createSchemaType(const QXmlName name) const =0
void error(const QString &msg) const
QStack< XsdStateMachine< XsdTerm::Ptr > > m_stateMachines
QVector< QXmlItem > fieldItems() const
XsdSchemaContext::Ptr m_context
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
BlockingConstraints disallowedSubstitutions() const
A helper class to build up validation state machines.
QExplicitlySharedDataPointer< XsdComplexType > Ptr
QString targetNamespace() const
QXmlNodeModelIndex toNodeModelIndex() const
If this QXmlItem represents a node, it returns the item as a QXmlNodeModelIndex.
If the item has a uniquely determined declaration available, it must be valid with respect to that de...
static bool isValidlySubstitutable(const SchemaType::Ptr &type, const SchemaType::Ptr &otherType, const SchemaType::DerivationConstraints &constraints)
bool validateAttribute(const XsdAttributeUse::Ptr &declaration, const QString &value)
The attribute has a fixed value set.
bool hasChildElement() const
static bool isQName(const QString &qName)
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
virtual bool isAbstract() const
void addIdIdRefBinding(const QString &id, const NamedSchemaComponent::Ptr &binding)
static bool wildcardAllowsExpandedName(const QXmlName &name, const XsdWildcard::Ptr &wildcard, const NamePool::Ptr &namePool)
virtual bool isDefinedBySchema() const
The complex type has further elements or attributes but no text as content.
The class that provides methods for checking a string against a type.
The complex type has no further content.
The model group is a sequence.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void setNamespaceURI(const NamespaceCode c)
virtual QXmlName name(const NamePool::Ptr &np) const =0
Returns the name of the type.
void setMaximumOccursUnbounded(bool unbounded)
The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML...
The constraint is a key constraint.
virtual QString stringValue(const QXmlNodeModelIndex &n) const
Returns the string value for node n.
QVector< QXmlName > namespaceBindings(const QXmlNodeModelIndex &index) const
bool isNull() const
Returns true if this QXmlItem is neither a node nor an atomic value.
const NamePool::Ptr m_namePool
void createAndPushStateMachine(const XsdParticle::Ptr &particle)
bool validateUniqueIdentityConstraint(const XsdElement::Ptr &element, const XsdIdentityConstraint::Ptr &constraint, const TargetNode::Set &qualifiedNodeSet)