ik ben bezig een xml schema te maken bij een xml, zodat we de xml kunnen valideren. Ik gebruik http://www.xmlvalidation.com/ om de xml en de xml schema te testen. Wat er fout gaat is als volgt: in het chapter element worden twee attributes verwacht. Maar als in de xml het attribute mist (ik had bijvoorbeeld chaoternumber opgenomen, in plaats van chapternumber), dan triggert de validator geen fout. Ziet iemand wat ik fout doe? Ik ben al behoorlijk lang aan het zoeken, oa op w3 schools en stackoverflow.
Kort gezegd: er staat een fout in de XML, namelijk het attribuut chaoternumber op regel 2 van de xml is niet toegestaan (zie regel 16 van de schema)
[edit] het gekke is dat als ik dezelfde 'fout' toevoeg bij het element section, dat dan wel de fout getriggerd wordt, terwijl voor zover ik het zie, de xml schema identiek is in beide gevallen (chapter en section)
xml
xml schema
Kort gezegd: er staat een fout in de XML, namelijk het attribuut chaoternumber op regel 2 van de xml is niet toegestaan (zie regel 16 van de schema)
[edit] het gekke is dat als ik dezelfde 'fout' toevoeg bij het element section, dat dan wel de fout getriggerd wordt, terwijl voor zover ik het zie, de xml schema identiek is in beide gevallen (chapter en section)
xml
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| <book booktitle="havo/vwo"> <chapter chaptertitle="Fictie lezen" chaoternumber="1"> <section sectiontitle="Soorten boeken" sectionnumber="1"> <block type="standaard" page="10" year="1"> <title>Fictie en non-fictie</title> <text><![CDATA[Je hebt in je leven al veel]]></text> <title>Realistisch en onrealistisch</title> <text><![CDATA[Er bestaan twee soorten fictieve verhalen: van J.R.R. Tolkien.]]></text> </block> <block type="plus" page="10" year="1"> <title>Schema</title> <misc>image</misc> </block> <block type="plus" page="10" year="1"> <title>Fragment uit een realistisch verhaal</title> <text><![CDATA[<i>Toen hij daarmee moeten?</i>]]></text> <misc>image</misc> </block> <block type="plus" page="10" year="1"> <title>Fragment uit een onrealistisch verhaal</title> <text><![CDATA[Professor Anderling was weer anders. ]]></text> <misc>image</misc> </block> </section> </chapter> </book> |
xml schema
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="book"> <xs:complexType> <xs:sequence> <xs:element name="chapter" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute ref="booktitle" use="required"/> </xs:complexType> </xs:element> <xs:element name="chapter"> <xs:complexType> <xs:sequence> <xs:element name="section" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="chaptertitle" type="xs:string" use="required"/> <xs:attribute name="chapternumber" type="xs:positiveInteger" use="required"/> </xs:complexType> </xs:element> <xs:element name="section"> <xs:complexType> <xs:sequence> <xs:element name="block" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="sectiontitle" type="xs:string" use="required"/> <xs:attribute name="sectionnumber" type="xs:positiveInteger" use="required"/> </xs:complexType> </xs:element> <xs:element name="block"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="title" minOccurs="0"/> <xs:element name="text" minOccurs="0"/> <xs:element name="misc" minOccurs="0"/> </xs:choice> <xs:attribute ref="year" use="required"/> <xs:attribute name="page" type="xs:positiveInteger" use="required"/> <xs:attribute ref="type" use="required"/> </xs:complexType> </xs:element> <xs:attribute name="year"> <xs:simpleType> <xs:restriction base="xs:positiveInteger"> <xs:enumeration value="1"/> <xs:enumeration value="2"/> <xs:enumeration value="3"/> <xs:enumeration value="4"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="type"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="standaard"/> <xs:enumeration value="plus"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="booktitle"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="vmbo"/> <xs:enumeration value="havo/vwo"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:schema> |
[ Voor 5% gewijzigd door huistra op 28-06-2016 22:13 . Reden: extra inzicht toegevoegd ]