Virtlab:Validace XML
Z VirtlabWiki
V prvních verzích Virtlabu jsme validovali XML pomocí DTD, nicméně tento způsob má velké limity, proto jsme přešli na validaci pomocí Relax-ng (jde o variantu XMLSchema).
Soubory relax-ng používané pro validaci jsou uloženy v SVN
- DISTR/xml/RELAXNG/ ... což je symbolický odkaz do DISTR/web/relax
- SVN
Ukázka (taskupload.rng)
<?xml version="1.0" encoding="UTF-8"?> <!-- RELAX NG schema pro popis ulohy --> <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:html="http://www.w3.org/1999/xhtml" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <!-- zacatek --> <element name="task"> <!-- atribut "name" --> <attribute name="name"> <data type="string"> <param name="minLength">1</param> <param name="maxLength">35</param> </data> </attribute> <!-- nepovinny atribut "time" --> <optional> <attribute name="time"> <data type="decimal"> <param name="minInclusive">0</param> <param name="maxExclusive">10000000</param> </data> </attribute> </optional> <!-- Element popisující jméno v dlouhém formátu --> <element name="longname"> <data type="string"> <param name="minLength">1</param> <param name="maxLength">150</param> </data> </element> <!-- Element pro popis --> <element name="description"> <data type="string"> <param name="minLength">1</param> <param name="maxLength">250</param> </data> </element> <!-- Popis zadani --> <element name="specification"> <zeroOrMore> <ref name="file" /> </zeroOrMore> </element> <!-- Popis obrazku --> <element name="picture"> <optional> <ref name="file" /> </optional> </element> <!-- Popis preconf --> <element name="pre_conf"> <optional> <ref name="file" /> </optional> </element> <!-- Popis postconf --> <element name="post_conf"> <optional> <ref name="file" /> </optional> </element> <!-- Popis topology --> <element name="topology"> <optional> <ref name="file" /> </optional> </element> <!-- Popis dia obrazku --> <element name="dia_picture"> <optional> <ref name="file" /> </optional> </element> </element> </start> <!-- konec hlavni casti --> <!-- nasleduje definice pouzitych elementu a atributu --> <!-- Definice elementu "file". Na definici se odkazuji pomoci 'ref name="file"' --> <define name="file"> <element name="file"> <attribute name="name"> <data type="string"> <param name="minLength">1</param> <param name="maxLength">49</param> </data> </attribute> <optional> <attribute name="lang"> <data type="string"> <param name="minLength">1</param> <param name="maxLength">5</param> </data> </attribute> </optional> <attribute name="filepath"> <data type="string"> <param name="minLength">1</param> <param name="maxLength">299</param> </data> </attribute> <attribute name="exists"> <choice> <value>yes</value> <value>no</value> </choice> </attribute> </element> </define> <!-- konec RELAX NG schematu --> </grammar>