native
xsdata.formats.dataclass.parsers.handlers.native
XmlEventHandler
Bases: XmlHandler
A native xml event handler.
Source code in xsdata/formats/dataclass/parsers/handlers/native.py
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 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 |
|
parse(source, ns_map)
Parse the source XML document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source | Any | The xml source, can be a file resource or an input stream, or a xml tree/element. | required |
ns_map | dict[Optional[str], str] | A namespace prefix-URI recorder map | required |
Returns:
Type | Description |
---|---|
Any | An instance of the class type representing the parsed content. |
Source code in xsdata/formats/dataclass/parsers/handlers/native.py
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 |
|
process_context(context, ns_map)
Iterate context and push events to main parser.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context | Iterable[tuple[str, Any]] | The iterable xml context | required |
ns_map | dict[Optional[str], str] | A namespace prefix-URI recorder map | required |
Returns:
Type | Description |
---|---|
Any | An instance of the class type representing the parsed content. |
Source code in xsdata/formats/dataclass/parsers/handlers/native.py
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 82 83 84 85 86 87 88 89 |
|
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/handlers/native.py
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 |
|
iterwalk(element, ns_map)
Walk over the element tree and emit events.
The ElementTree doesn't preserve the original namespace prefixes, we have to generate new ones.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element | Element | The etree element instance | required |
ns_map | dict | The namespace prefix-URI mapping | required |
Yields:
Type | Description |
---|---|
tuple[str, Any] | An iterator of events |
Source code in xsdata/formats/dataclass/parsers/handlers/native.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
get_base_url(base_url, source)
Return the base url of the source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_url | Optional[str] | The base url from the parser config | required |
source | Any | The xml source input | required |
Returns:
Type | Description |
---|---|
Optional[str] | A base url str or None, if no base url is provided |
Optional[str] | and the source is not a string path. |
Source code in xsdata/formats/dataclass/parsers/handlers/native.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
xinclude_loader(href, parse, encoding=None, base_url=None)
Custom loader for xinclude parsing.
The base_url argument was added in python >= 3.9.
Source code in xsdata/formats/dataclass/parsers/handlers/native.py
161 162 163 164 165 166 167 168 169 170 171 |
|