Object Hierarchy:

Object hierarchy for SchemaValidCtxt


[ Compact ]
[ CCode ( cname = "xmlSchemaValidCtxt" , free_function = "xmlSchemaFreeValidCtxt" ) ]
public class SchemaValidCtxt

Example: Tree: XSD based validation:

<?xml version="1.0" encoding="utf-8"?>
<book id="1">
<title>The Royal Game</title>
<author>Stefan Zweig</author>
<book id="2">
<title>The Stoker</title>
<author>Franz Kafka</author>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="" elementFormDefault="qualified" xmlns:xs="">
<xs:element name="books">
<xs:element name="book" maxOccurs="unbounded">
<xs:element name="title" type="string"/>
<xs:element name="author" type="string"/>
<xs:attribute name="id" type="xs:integer"/>

public static int main (string[] args) {
// The document:
Xml.Doc* doc = Xml.Parser.parse_file ("books.xml");
if (doc == null) {
print ("File 'books.xml' not found or permissions missing\n");
return 0;

// The schema:
Xml.SchemaParserCtxt schema_parser = new Xml.SchemaParserCtxt ("books.xsd");
Xml.Schema schema = schema_parser.parse ();
if (schema == null) {
print ("Invalid/missing schema\n");
return 0;

Xml.SchemaValidCtxt valctxt = new Xml.SchemaValidCtxt (schema);
if (valctxt == null) {
print ("Unable to create a validation context\n");
return 0;

// Validation:
int is_valid = valctxt.validate_doc (doc);
if (is_valid == 0) {
print ("valid\n");
} else {
print ("invalid\n");

return 0;

valac --pkg libxml-2.0 schemas.vala

Namespace: Xml
Package: libxml-2.0


Creation methods: