Register a namespace prefix. The registry is global, and any existing mapping for either the given prefix or the namespace URI will be removed. *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and attributes in this namespace will be serialized with prefix if possib
(prefix, uri)
| 977 | |
| 978 | |
| 979 | def register_namespace(prefix, uri): |
| 980 | """Register a namespace prefix. |
| 981 | |
| 982 | The registry is global, and any existing mapping for either the |
| 983 | given prefix or the namespace URI will be removed. |
| 984 | |
| 985 | *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and |
| 986 | attributes in this namespace will be serialized with prefix if possible. |
| 987 | |
| 988 | ValueError is raised if prefix is reserved or is invalid. |
| 989 | |
| 990 | """ |
| 991 | if re.match(r"ns\d+$", prefix): |
| 992 | raise ValueError("Prefix format reserved for internal use") |
| 993 | for k, v in list(_namespace_map.items()): |
| 994 | if k == uri or v == prefix: |
| 995 | del _namespace_map[k] |
| 996 | _namespace_map[uri] = prefix |
| 997 | |
| 998 | _namespace_map = { |
| 999 | # "well-known" namespace prefixes |