| 1 | module xml |
| 2 | |
| 3 | pub type XMLNodeContents = XMLCData | XMLComment | XMLNode | string |
| 4 | |
| 5 | pub struct XMLCData { |
| 6 | pub: |
| 7 | text string @[required] |
| 8 | } |
| 9 | |
| 10 | pub struct XMLComment { |
| 11 | pub: |
| 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. |
| 18 | pub struct XMLNode { |
| 19 | pub: |
| 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. |
| 31 | pub struct XMLDocument { |
| 32 | Prolog |
| 33 | pub: |
| 34 | root XMLNode @[required] |
| 35 | } |
| 36 | |
| 37 | pub type DTDListItem = DTDElement | DTDEntity |
| 38 | |
| 39 | pub struct DTDEntity { |
| 40 | pub: |
| 41 | name string @[required] |
| 42 | value string @[required] |
| 43 | } |
| 44 | |
| 45 | pub struct DTDElement { |
| 46 | pub: |
| 47 | name string @[required] |
| 48 | definition []string @[required] |
| 49 | } |
| 50 | |
| 51 | pub struct DocumentTypeDefinition { |
| 52 | pub: |
| 53 | name string |
| 54 | list []DTDListItem |
| 55 | } |
| 56 | |
| 57 | pub struct DocumentType { |
| 58 | pub: |
| 59 | name string @[required] |
| 60 | dtd DTDInfo |
| 61 | } |
| 62 | |
| 63 | type DTDInfo = DocumentTypeDefinition | string |
| 64 | |
| 65 | struct Prolog { |
| 66 | parsed_reverse_entities map[string]string = default_entities_reverse.clone() |
| 67 | pub: |
| 68 | version string = '1.0' |
| 69 | encoding string = 'UTF-8' |
| 70 | doctype DocumentType = DocumentType{ |
| 71 | name: '' |
| 72 | dtd: '' |
| 73 | } |
| 74 | comments []XMLComment |
| 75 | } |
| 76 | |