summaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp')
-rw-r--r--doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp b/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp
new file mode 100644
index 0000000..5c15482
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/qxmlschemavalidator/main.cpp
@@ -0,0 +1,63 @@
+
+def validateFromUrl():
+//! [0]
+ schema = getSchema()
+
+ url = QUrl("http://www.schema-example.org/test.xml")
+
+ validator = QXmlSchemaValidator(schema)
+ if validator.validate(url):
+ print "instance document is valid"
+ else:
+ print "instance document is invalid"
+//! [0]
+
+def validateFromFile():
+//! [1]
+ schema = getSchema()
+
+ file = QFile("test.xml")
+ file.open(QIODevice.ReadOnly)
+
+ validator = QXmlSchemaValidator(schema)
+ if validator.validate(file, QUrl.fromLocalFile(file.fileName())):
+ print "instance document is valid"
+ else:
+ print "instance document is invalid"
+//! [1]
+}
+
+def validateFromData():
+//! [2]
+ schema = getSchema()
+
+ data = QByteArray("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test></test>")
+
+ buffer = QBuffer(data)
+ buffer.open(QIODevice.ReadOnly)
+
+ QXmlSchemaValidator validator(schema)
+ if validator.validate(buffer):
+ print "instance document is valid"
+ else:
+ print "instance document is invalid"
+//! [2]
+
+def validateComplete():
+//! [3]
+ schemaUrl = QUrl("file:///home/user/schema.xsd")
+
+ schema = QXmlSchema()
+ schema.load(schemaUrl)
+
+ if schema.isValid():
+ file = QFile("test.xml")
+ file.open(QIODevice.ReadOnly)
+
+ validator = QXmlSchemaValidator(schema)
+ if validator.validate(file, QUrl.fromLocalFile(file.fileName())):
+ print "instance document is valid"
+ else:
+ print "instance document is invalid"
+ }
+//! [3]