v2 / vlib / encoding / xml / types.v
75 lines · 63 sloc · 1.59 KB · c51d30bf5309653c6b573ec815268e69a78ea8cc
Raw
1module xml
2
3pub type XMLNodeContents = XMLCData | XMLComment | XMLNode | string
4
5pub struct XMLCData {
6pub:
7 text string @[required]
8}
9
10pub struct XMLComment {
11pub:
12 text string @[required]
13}
14
15// XMLNode represents a single XML node. It contains the node name,
16// a map of attributes, and a list of children. The children can be
17// other XML nodes, CDATA, plain text, or comments.
18pub struct XMLNode {
19pub:
20 name string @[required]
21 attributes map[string]string
22 children []XMLNodeContents
23}
24
25// XMLDocument is the struct that represents a single XML document.
26// It contains the prolog and the single root node. The prolog struct
27// is embedded into the XMLDocument struct, so that the prolog fields
28// are accessible directly from the this struct.
29// Public prolog fields include version, enccoding, comments preceding
30// the root node, and the document type definition.
31pub struct XMLDocument {
32 Prolog
33pub:
34 root XMLNode @[required]
35}
36
37pub type DTDListItem = DTDElement | DTDEntity
38
39pub struct DTDEntity {
40pub:
41 name string @[required]
42 value string @[required]
43}
44
45pub struct DTDElement {
46pub:
47 name string @[required]
48 definition []string @[required]
49}
50
51pub struct DocumentTypeDefinition {
52pub:
53 name string
54 list []DTDListItem
55}
56
57pub struct DocumentType {
58pub:
59 name string @[required]
60 dtd DTDInfo
61}
62
63type DTDInfo = DocumentTypeDefinition | string
64
65struct Prolog {
66 parsed_reverse_entities map[string]string = default_entities_reverse.clone()
67pub:
68 version string = '1.0'
69 encoding string = 'UTF-8'
70 doctype DocumentType = DocumentType{
71 name: ''
72 dtd: ''
73 }
74 comments []XMLComment
75}
76