-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXmlDatabase
More file actions
81 lines (45 loc) · 1.13 KB
/
Copy pathXmlDatabase
File metadata and controls
81 lines (45 loc) · 1.13 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-----students.xml-------
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student>
<id>101</id>
<name>binary shade</name>
<age>20</age>
<major>Computer Science</major>
</student>
<student>
<id>102</id>
<name>Dj dark cyber</name>
<age>22</age>
<major>Business Administration</major>
</student>
</students>
students.xsd--------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.google.com/XMLSchema">
<xs:element name="students">
<xs:complexType>
<xs:sequence>
<xs:element name="student" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:integer"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="major" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
import xmlschema
schema = xmlschema.XMLSchema('books.xsd')
# Load the XML file
xml = 'books.xml'
# Validate the XML file against the schema
if schema.is_valid(xml):
print('Validation successful')
else:
print('Validation failed')