Results 1 to 1 of 1

Thread: Infinite loop in QXmlSchemaValidator::validate()?

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Infinite loop in QXmlSchemaValidator::validate()?

    Using the following schema definition

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    3.  
    4. <xs:simpleType name="nonEmptyElement">
    5.  
    6. <xs:restriction base="xs:string">
    7.  
    8. <xs:minLength value="1"/>
    9.  
    10. </xs:restriction>
    11.  
    12. </xs:simpleType>
    13.  
    14. <xs:simpleType name="Alphanumeric">
    15.  
    16. <xs:restriction base="nonEmptyElement">
    17.  
    18. <xs:pattern value="[a-z A-Z0-9]*"/>
    19.  
    20. </xs:restriction>
    21.  
    22. </xs:simpleType>
    23.  
    24. <xs:simpleType name="nameType">
    25.  
    26. <xs:restriction base="nonEmptyElement"/>
    27.  
    28. </xs:simpleType>
    29.  
    30. <xs:simpleType name="shortnameType">
    31.  
    32. <xs:restriction base="Alphanumeric">
    33.  
    34. <xs:maxLength value="4096"/>
    35.  
    36. </xs:restriction>
    37.  
    38. </xs:simpleType>
    39.  
    40. <xs:simpleType name="developerType">
    41.  
    42. <xs:restriction base="nonEmptyElement"/>
    43.  
    44. </xs:simpleType>
    45.  
    46. <xs:simpleType name="publisherType">
    47.  
    48. <xs:restriction base="nonEmptyElement"/>
    49.  
    50. </xs:simpleType>
    51.  
    52. <xs:simpleType name="versionType">
    53.  
    54. <xs:restriction base="nonEmptyElement"/>
    55.  
    56. </xs:simpleType>
    57.  
    58. <xs:simpleType name="genreType">
    59.  
    60. <xs:restriction base="nonEmptyElement"/>
    61.  
    62. </xs:simpleType>
    63.  
    64. <xs:simpleType name="licenseType">
    65.  
    66. <xs:restriction base="nonEmptyElement">
    67.  
    68. <xs:maxLength value="4096"/>
    69.  
    70. </xs:restriction>
    71.  
    72. </xs:simpleType>
    73.  
    74. <xs:simpleType name="installerType">
    75.  
    76. <xs:restriction base="nonEmptyElement">
    77.  
    78. <xs:maxLength value="4096"/>
    79.  
    80. </xs:restriction>
    81.  
    82. </xs:simpleType>
    83.  
    84. <xs:simpleType name="childType">
    85.  
    86. <xs:restriction base="nonEmptyElement">
    87.  
    88. <xs:maxLength value="4096"/>
    89.  
    90. </xs:restriction>
    91.  
    92. </xs:simpleType>
    93.  
    94. <xs:simpleType name="iconPathType">
    95.  
    96. <xs:restriction base="xs:string">
    97.  
    98. <xs:maxLength value="4096"/>
    99.  
    100. <xs:minLength value="4096"/>
    101.  
    102. </xs:restriction>
    103.  
    104. </xs:simpleType>
    105.  
    106. <xs:complexType name="iconType">
    107.  
    108. <xs:simpleContent>
    109.  
    110. <xs:extension base="iconPathType">
    111.  
    112. <xs:attribute name="height" type="xs:integer"/>
    113.  
    114. <xs:attribute name="width" type="xs:integer"/>
    115.  
    116. </xs:extension>
    117.  
    118. </xs:simpleContent>
    119.  
    120. </xs:complexType>
    121.  
    122. <xs:complexType name="metaType">
    123.  
    124. <xs:all>
    125.  
    126. <xs:element name="name" type="nameType" nillable="false" minOccurs="1" maxOccurs="1"/>
    127.  
    128. <xs:element name="shortname" type="shortnameType" nillable="false" minOccurs="1" maxOccurs="1"/>
    129.  
    130. <xs:element name="developer" type="developerType" nillable="false" minOccurs="1" maxOccurs="1"/>
    131.  
    132. <xs:element name="publisher" type="publisherType" nillable="false" minOccurs="0" maxOccurs="1"/>
    133.  
    134. <xs:element name="version" type="versionType" nillable="false" minOccurs="1" maxOccurs="1"/>
    135.  
    136. <xs:element name="genre" type="genreType" nillable="false" minOccurs="0"/>
    137.  
    138. <xs:element name="summary" type="xs:string" nillable="false" minOccurs="0" maxOccurs="1"/>
    139.  
    140. <xs:element name="description" type="xs:string" nillable="false" minOccurs="0" maxOccurs="1"/>
    141.  
    142. <xs:element name="icon" type="iconType" nillable="false" minOccurs="0"/>
    143.  
    144. <xs:element name="license" type="licenseType" nillable="false" minOccurs="0" maxOccurs="1"/>
    145.  
    146. <xs:element name="installer" type="installerType" minOccurs="1" maxOccurs="1"/>
    147.  
    148. <xs:element name="child" type="childType" minOccurs="0"/>
    149.  
    150. </xs:all>
    151.  
    152. </xs:complexType>
    153.  
    154. <xs:element name="meta" type="metaType">
    155.  
    156. </xs:element>
    157.  
    158. </xs:schema>
    To copy to clipboard, switch view to plain text mode 

    In both the xmlpatterns/schema example that comes with the Qt examples (by replacing one of the included - and note, working - schemas), and this little test program

    Qt Code:
    1. #include <QtXmlPatterns>
    2.  
    3. #include <iostream>
    4.  
    5. class MessageHandler : public QAbstractMessageHandler
    6. {
    7. public:
    8. MessageHandler()
    9. : QAbstractMessageHandler(0)
    10. {
    11. }
    12.  
    13. QString statusMessage() const
    14. {
    15. return m_description;
    16. }
    17.  
    18. int line() const
    19. {
    20. return m_sourceLocation.line();
    21. }
    22.  
    23. int column() const
    24. {
    25. return m_sourceLocation.column();
    26. }
    27.  
    28. protected:
    29. virtual void handleMessage(QtMsgType type, const QString &description,
    30. const QUrl &identifier, const QSourceLocation &sourceLocation)
    31. {
    32. Q_UNUSED(type);
    33. Q_UNUSED(identifier);
    34.  
    35. m_messageType = type;
    36. m_description = description;
    37. m_sourceLocation = sourceLocation;
    38.  
    39. std::cerr << m_description.toUtf8().data() << ", " << m_sourceLocation.line() << std::endl;
    40. }
    41.  
    42. private:
    43. QtMsgType m_messageType;
    44. QString m_description;
    45. QSourceLocation m_sourceLocation;
    46. };
    47.  
    48. int main(int argc, char** argv)
    49. {
    50. QCoreApplication app(argc, argv);
    51.  
    52. QFile schemaFile("metadata.xsd");
    53. schemaFile.open(QIODevice::ReadOnly);
    54.  
    55. const QString schemaText(QString::fromUtf8(schemaFile.readAll()));
    56.  
    57. QFile instanceFile("test.xml");
    58. instanceFile.open(QIODevice::ReadOnly);
    59. const QString instanceText(QString::fromUtf8(instanceFile.readAll()));
    60.  
    61. const QByteArray schemaData = schemaText.toUtf8();
    62. const QByteArray instanceData = instanceText.toUtf8();
    63.  
    64. QXmlSchema schema;
    65. MessageHandler messageHandler;
    66. schema.setMessageHandler(&messageHandler);
    67. schema.load(schemaData);
    68.  
    69. bool errorOccurred = false;
    70. if (!schema.isValid()) {
    71. std::cerr << "Schema invalid." << std::endl;
    72. } else {
    73. std::cerr << "Schema is valid, proceeding" << std::endl;
    74. QXmlSchemaValidator validator(schema);
    75. std::cerr << "Created validator" << std::endl;
    76. if (!validator.validate(instanceData))
    77. std::cerr << "Failed validation" << std::endl;
    78. else
    79. std::cerr << "Validated." << std::endl;
    80. }
    81.  
    82. return app.exec();
    83. }
    To copy to clipboard, switch view to plain text mode 

    // It seems to encounter an infinite loop on the line

    Qt Code:
    1. if (!validator.validate(instanceData))
    To copy to clipboard, switch view to plain text mode 

    If I make the schema invalid by (for example) setting the 'mixed' attribute
    on the complexType element that contains simpleContent (iconType), then the
    program properly runs saying "Schema Invalid".

    It happens with the following XML data, but I'm not sure how much that
    should make a difference:

    Qt Code:
    1. <?xml version="1.0" encoding="utf-8" ?>
    2. <meta>
    3. <shortname>foo</shortname>
    4. <installer>install/fooinstall.xml</installer>
    5. <name>Foo</name>
    6. <version>0.1</version>
    7. <license>licenses/license.txt</license>
    8. <developer>Quixote</developer>
    9. <description>ABC</description>
    10. <child>children/bar.xml</child>
    11. </meta>
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

    EDIT: The kernel also kills the xmlpatternsvalidator command-line app that comes with the 'qt4-dev-tools' package under Ubuntu when it tries to validate that XML against the schema, too.
    Last edited by TropicalPenguin; 9th November 2010 at 16:10.

Similar Threads

  1. Replies: 0
    Last Post: 2nd July 2010, 14:25
  2. infinite loop
    By zakis in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2009, 17:52
  3. Replies: 4
    Last Post: 19th August 2009, 19:38
  4. Infinite loop - resize parent from child
    By bitChanger in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2006, 13:21
  5. is it possible to stay on a user defined infinite loop?
    By mahe2310 in forum Qt Programming
    Replies: 9
    Last Post: 24th March 2006, 14:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.