Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QXmlSchema Class Reference

The QXmlSchema class provides loading and validation of a W3C XML Schema. More...

 #include <QXmlSchema>

Note: All functions in this class are reentrant.

This class was introduced in Qt 4.6.

Public Functions

QXmlSchema ()
QXmlSchema ( const QXmlSchema & other )
~QXmlSchema ()
QUrl documentUri () const
bool isValid () const
bool load ( const QUrl & source )
bool load ( QIODevice * source, const QUrl & documentUri = QUrl() )
bool load ( const QByteArray & data, const QUrl & documentUri = QUrl() )
QAbstractMessageHandler * messageHandler () const
QXmlNamePool namePool () const
QNetworkAccessManager * networkAccessManager () const
void setMessageHandler ( QAbstractMessageHandler * handler )
void setNetworkAccessManager ( QNetworkAccessManager * manager )
void setUriResolver ( const QAbstractUriResolver * resolver )
const QAbstractUriResolver * uriResolver () const

Detailed Description

The QXmlSchema class provides loading and validation of a W3C XML Schema.

The QXmlSchema class loads, compiles and validates W3C XML Schema files that can be used further for validation of XML instance documents via QXmlSchemaValidator.

The following example shows how to load a XML Schema file from the network and test whether it is a valid schema document:

     QUrl url("http://www.schema-example.org/myschema.xsd");

     QXmlSchema schema;
     if (schema.load(url) == true)
         qDebug() << "schema is valid";
     else
         qDebug() << "schema is invalid";

XML Schema Version

This class is used to represent schemas that conform to the XML Schema 1.0 specification.

See also QXmlSchemaValidator and XML Schema Validation Example.

Member Function Documentation

QXmlSchema::QXmlSchema ()

Constructs an invalid, empty schema that cannot be used until load() is called.

QXmlSchema::QXmlSchema ( const QXmlSchema & other )

Constructs a QXmlSchema that is a copy of other. The new instance will share resources with the existing schema to the extent possible.

QXmlSchema::~QXmlSchema ()

Destroys this QXmlSchema.

QUrl QXmlSchema::documentUri () const

Returns the document URI of the schema or an empty URI if no schema has been set.

bool QXmlSchema::isValid () const

Returns true if this schema is valid. Examples of invalid schemas are ones that contain syntax errors or that do not conform the W3C XML Schema specification.

bool QXmlSchema::load ( const QUrl & source )

Sets this QXmlSchema to a schema loaded from the source URI.

If the schema is invalid, false is returned and the behavior is undefined.

Example:

     QUrl url("http://www.schema-example.org/myschema.xsd");

     QXmlSchema schema;
     if (schema.load(url) == true)
         qDebug() << "schema is valid";
     else
         qDebug() << "schema is invalid";

See also isValid().

bool QXmlSchema::load ( QIODevice * source, const QUrl & documentUri = QUrl() )

Sets this QXmlSchema to a schema read from the source device. The device must have been opened with at least QIODevice::ReadOnly.

documentUri represents the schema obtained from the source device. It is the base URI of the schema, that is used internally to resolve relative URIs that appear in the schema, and for message reporting.

If source is null or not readable, or if documentUri is not a valid URI, behavior is undefined.

If the schema is invalid, false is returned and the behavior is undefined.

Example:

     QFile file("myschema.xsd");
     file.open(QIODevice::ReadOnly);

     QXmlSchema schema;
     schema.load(&file, QUrl::fromLocalFile(file.fileName()));

     if (schema.isValid())
         qDebug() << "schema is valid";
     else
         qDebug() << "schema is invalid";

See also isValid().

bool QXmlSchema::load ( const QByteArray & data, const QUrl & documentUri = QUrl() )

Sets this QXmlSchema to a schema read from the data

documentUri represents the schema obtained from the data. It is the base URI of the schema, that is used internally to resolve relative URIs that appear in the schema, and for message reporting.

If documentUri is not a valid URI, behavior is undefined.

If the schema is invalid, false is returned and the behavior is undefined.

Example:

     QByteArray data( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                      "<xsd:schema"
                      "        xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
                      "        xmlns=\"http://qt.nokia.com/xmlschematest\""
                      "        targetNamespace=\"http://qt.nokia.com/xmlschematest\""
                      "        version=\"1.0\""
                      "        elementFormDefault=\"qualified\">"
                      "</xsd:schema>" );

     QXmlSchema schema;
     schema.load(data);

     if (schema.isValid())
         qDebug() << "schema is valid";
     else
         qDebug() << "schema is invalid";

See also isValid() and isValid().

QAbstractMessageHandler * QXmlSchema::messageHandler () const

Returns the message handler that handles compile and validation messages for this QXmlSchema.

See also setMessageHandler().

QXmlNamePool QXmlSchema::namePool () const

Returns the name pool used by this QXmlSchema for constructing names. There is no setter for the name pool, because mixing name pools causes errors due to name confusion.

QNetworkAccessManager * QXmlSchema::networkAccessManager () const

Returns the network manager, or 0 if it has not been set.

See also setNetworkAccessManager().

void QXmlSchema::setMessageHandler ( QAbstractMessageHandler * handler )

Changes the message handler for this QXmlSchema to handler. The schema sends all compile and validation messages to this message handler. QXmlSchema does not take ownership of handler.

Normally, the default message handler is sufficient. It writes compile and validation messages to stderr. The default message handler includes color codes if stderr can render colors.

When QXmlSchema calls QAbstractMessageHandler::message(), the arguments are as follows:

message() argumentSemantics
QtMsgType typeOnly QtWarningMsg and QtFatalMsg are used. The former identifies a warning, while the latter identifies an error.
const QString & descriptionAn XHTML document which is the actual message. It is translated into the current language.
const QUrl &identifierIdentifies the error with a URI, where the fragment is the error code, and the rest of the URI is the error namespace.
const QSourceLocation & sourceLocationIdentifies where the error occurred.

See also messageHandler().

void QXmlSchema::setNetworkAccessManager ( QNetworkAccessManager * manager )

Sets the network manager to manager. QXmlSchema does not take ownership of manager.

See also networkAccessManager().

void QXmlSchema::setUriResolver ( const QAbstractUriResolver * resolver )

Sets the URI resolver to resolver. QXmlSchema does not take ownership of resolver.

See also uriResolver().

const QAbstractUriResolver * QXmlSchema::uriResolver () const

Returns the schema's URI resolver. If no URI resolver has been set, QtXmlPatterns will use the URIs in schemas as they are.

The URI resolver provides a level of abstraction, or polymorphic URIs. A resolver can rewrite logical URIs to physical ones, or it can translate obsolete or invalid URIs to valid ones.

When QtXmlPatterns calls QAbstractUriResolver::resolve() the absolute URI is the URI mandated by the schema specification, and the relative URI is the URI specified by the user.

See also setUriResolver().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web