Virtlab:Validace XML
Z VirtlabWiki
(Rozdíly mezi verzemi)
Verze z 14:50, 18. 10. 2007 Vav166 (Diskuse | příspěvky) ← Předchozí porovnání |
Verze z 06:08, 9. 9. 2008 Bam015 (Diskuse | příspěvky) (→Ukázka (taskupload.rng)) Následující porovnání → |
||
Řádka 51: | Řádka 51: | ||
</element> | </element> | ||
- | <!-- Popis skupiny - group_descrip --> | + | |
- | <element name="group_descrip"> | + | <!-- Popis zadani --> |
- | <ref name="attlist.all_groups" /> | + | <element name="specification"> |
- | + | ||
<zeroOrMore> | <zeroOrMore> | ||
- | |||
<ref name="file" /> | <ref name="file" /> | ||
- | |||
</zeroOrMore> | </zeroOrMore> | ||
+ | </element> | ||
- | </element> | + | <!-- Popis obrazku --> |
+ | <element name="picture"> | ||
+ | <optional> | ||
+ | <ref name="file" /> | ||
+ | </optional> | ||
+ | </element> | ||
- | <!-- Popis skupiny - group_pics --> | + | <!-- Popis preconf --> |
- | <element name="group_pics"> | + | <element name="pre_conf"> |
- | <ref name="attlist.all_groups" /> | + | <optional> |
- | <zeroOrMore> | + | <ref name="file" /> |
- | + | </optional> | |
- | <ref name="file" /> | + | |
- | + | ||
- | </zeroOrMore> | + | |
- | + | ||
</element> | </element> | ||
- | |||
- | <!-- Popis skupiny - group_preconf --> | ||
- | <element name="group_preconf"> | ||
- | <ref name="attlist.all_groups" /> | ||
- | <zeroOrMore> | ||
- | <ref name="file" /> | + | <!-- Popis postconf --> |
+ | <element name="post_conf"> | ||
+ | <optional> | ||
+ | <ref name="file" /> | ||
+ | </optional> | ||
+ | </element> | ||
+ | |||
+ | <!-- Popis topology --> | ||
+ | <element name="topology"> | ||
+ | <optional> | ||
+ | <ref name="file" /> | ||
+ | </optional> | ||
+ | </element> | ||
- | </zeroOrMore> | + | <!-- Popis dia obrazku --> |
- | + | <element name="dia_picture"> | |
- | </element> | + | <optional> |
- | + | <ref name="file" /> | |
- | <!-- Popis skupiny - group_postconf --> | + | </optional> |
- | <element name="group_postconf"> | + | </element> |
- | <ref name="attlist.all_groups" /> | + | |
- | <zeroOrMore> | + | |
- | + | ||
- | <ref name="file" /> | + | |
- | + | ||
- | </zeroOrMore> | + | |
- | + | ||
- | </element> | + | |
- | + | ||
- | <!-- Popis skupiny - group_topology --> | + | |
- | <element name="group_topology"> | + | |
- | <ref name="attlist.all_groups" /> | + | |
- | <zeroOrMore> | + | |
- | + | ||
- | <ref name="file" /> | + | |
- | + | ||
- | </zeroOrMore> | + | |
- | + | ||
- | </element> | + | |
Řádka 112: | Řádka 99: | ||
</start> | </start> | ||
<!-- konec hlavni casti --> | <!-- konec hlavni casti --> | ||
+ | |||
<!-- nasleduje definice pouzitych elementu a atributu --> | <!-- nasleduje definice pouzitych elementu a atributu --> | ||
Řádka 124: | Řádka 112: | ||
</data> | </data> | ||
</attribute> | </attribute> | ||
+ | <optional> | ||
+ | <attribute name="lang"> | ||
+ | <data type="string"> | ||
+ | <param name="minLength">1</param> | ||
+ | <param name="maxLength">5</param> | ||
+ | </data> | ||
+ | </attribute> | ||
+ | </optional> | ||
<attribute name="filepath"> | <attribute name="filepath"> | ||
<data type="string"> | <data type="string"> | ||
Řádka 139: | Řádka 135: | ||
</define> | </define> | ||
- | <!-- Definice elementu "attlist.all_groups". Na definici se odkazuji pomoci 'ref name="attlist.all_groups"' | ||
- | slouzi pro vsechny "groups" --> | ||
- | <define name="attlist.all_groups" combine="interleave"> | ||
- | |||
- | <attribute name="name"> | ||
- | <data type="string"> | ||
- | <param name="minLength">1</param> | ||
- | <param name="maxLength">100</param> | ||
- | </data> | ||
- | </attribute> | ||
- | |||
- | <attribute name="exists"> | ||
- | |||
- | <choice> | ||
- | |||
- | <value>yes</value> | ||
- | |||
- | <value>no</value> | ||
- | |||
- | </choice> | ||
- | |||
- | </attribute> | ||
- | |||
- | </define> | ||
- | |||
<!-- konec RELAX NG schematu --> | <!-- konec RELAX NG schematu --> | ||
</grammar> | </grammar> | ||
+ | |||
</pre> | </pre> | ||
[[Kategorie:XML]] | [[Kategorie:XML]] |
Verze z 06:08, 9. 9. 2008
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>