Virtlab:Validace XML
Z VirtlabWiki
(Rozdíly mezi verzemi)
| Verze z 20:11, 8. 10. 2007 Vav166 (Diskuse | příspěvky) ← Předchozí porovnání |
Verze z 14:50, 18. 10. 2007 Vav166 (Diskuse | příspěvky) Následující porovnání → |
||
| Řádka 169: | Řádka 169: | ||
| </pre> | </pre> | ||
| + | |||
| + | [[Kategorie:XML]] | ||
Verze z 14:50, 18. 10. 2007
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 skupiny - group_descrip -->
<element name="group_descrip">
<ref name="attlist.all_groups" />
<zeroOrMore>
<ref name="file" />
</zeroOrMore>
</element>
<!-- Popis skupiny - group_pics -->
<element name="group_pics">
<ref name="attlist.all_groups" />
<zeroOrMore>
<ref name="file" />
</zeroOrMore>
</element>
<!-- Popis skupiny - group_preconf -->
<element name="group_preconf">
<ref name="attlist.all_groups" />
<zeroOrMore>
<ref name="file" />
</zeroOrMore>
</element>
<!-- Popis skupiny - group_postconf -->
<element name="group_postconf">
<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>
</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>
<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>
<!-- 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 -->
</grammar>
