mixins
xsdata.formats.dataclass.parsers.mixins
PushParser
dataclass
Bases: AbstractParser
A generic interface for event based content handlers like sax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | ParserConfig | The parser configuration instance | field(default_factory=ParserConfig) |
Attributes:
Name | Type | Description |
---|---|---|
ns_map | Dict[Optional[str], str] | The parsed namespace prefix-URI map |
Source code in xsdata/formats/dataclass/parsers/mixins.py
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 |
|
start(clazz, queue, objects, qname, attrs, ns_map)
abstractmethod
Build and queue the XmlNode for the starting element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clazz | Optional[Type] | The target class type, auto locate if omitted | required |
queue | List[Any] | The XmlNode queue list | required |
objects | List[Any] | The list of all intermediate parsed objects | required |
qname | str | The element qualified name | required |
attrs | Dict[str, str] | The element attributes | required |
ns_map | Dict[Optional[str], str] | The element namespace prefix-URI map | required |
Source code in xsdata/formats/dataclass/parsers/mixins.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
end(queue, objects, qname, text, tail)
abstractmethod
Parse the last xml node and bind any intermediate objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
queue | List | The XmlNode queue list | required |
objects | List | The list of all intermediate parsed objects | required |
qname | str | The element qualified name | required |
text | NoneStr | The element text content | required |
tail | NoneStr | The element tail content | required |
Returns:
Type | Description |
---|---|
bool | Whether the binding process was successful. |
Source code in xsdata/formats/dataclass/parsers/mixins.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
register_namespace(prefix, uri)
Register the uri prefix in the namespace registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix | NoneStr | Namespace prefix | required |
uri | str | Namespace uri | required |
Source code in xsdata/formats/dataclass/parsers/mixins.py
70 71 72 73 74 75 76 77 78 |
|
XmlNode
Bases: ABC
The xml node interface.
The nodes are responsible to find and queue the child nodes when a new element starts and build the resulting object tree when the element ends. The parser needs to maintain a queue for these nodes and a list of all the intermediate objects.
Source code in xsdata/formats/dataclass/parsers/mixins.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
child(qname, attrs, ns_map, position)
abstractmethod
Initialize the next child node to be queued, when an element starts.
This entry point is responsible to create the next node type with all the necessary information on how to bind the incoming input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qname | str | The element qualified name | required |
attrs | Dict | The element attributes | required |
ns_map | Dict | The element namespace prefix-URI map | required |
position | int | The current length of the intermediate objects | required |
Returns:
Type | Description |
---|---|
XmlNode | The child xml node instance. |
Source code in xsdata/formats/dataclass/parsers/mixins.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
bind(qname, text, tail, objects)
abstractmethod
Bind the parsed data into an object for the ending element.
This entry point is called when a xml element ends and is responsible to parse the current element attributes/text, bind any children objects and initialize new object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qname | str | The element qualified name | required |
text | NoneStr | The element text content | required |
tail | NoneStr | The element tail content | required |
objects | List[Any] | The list of intermediate parsed objects | required |
Returns:
Type | Description |
---|---|
bool | Whether the binding process was successful or not. |
Source code in xsdata/formats/dataclass/parsers/mixins.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
XmlHandler
Abstract content handler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser | PushParser | The parser instance to feed with events | required |
clazz | Optional[Type] | The target class type, auto locate if omitted | required |
Attributes:
Name | Type | Description |
---|---|---|
queue | List | The XmlNode queue list |
objects | List | The list of intermediate parsed objects |
Source code in xsdata/formats/dataclass/parsers/mixins.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
parse(source)
Parse the source XML document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source | Any | The xml source, can be a file resource or an input stream. | required |
Returns:
Type | Description |
---|---|
Any | An instance of the class type representing the parsed content. |
Source code in xsdata/formats/dataclass/parsers/mixins.py
153 154 155 156 157 158 159 160 161 162 |
|
merge_parent_namespaces(ns_map)
Merge the given prefix-URI map with the parent node map.
This method also registers new prefixes with the parser.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns_map | Dict[Optional[str], str] | The current element namespace prefix-URI map | required |
Returns:
Type | Description |
---|---|
Dict | The new merged namespace prefix-URI map. |
Source code in xsdata/formats/dataclass/parsers/mixins.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
EventsHandler
Bases: XmlHandler
Sax content handler for pre-recorded events.
Source code in xsdata/formats/dataclass/parsers/mixins.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
parse(source)
Forward the pre-recorded events to the main parser.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source | List[Tuple] | A list of event data | required |
Returns:
Type | Description |
---|---|
Any | An instance of the class type representing the parsed content. |
Source code in xsdata/formats/dataclass/parsers/mixins.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|