Parse XML document from string constant for its IDs. *text* is a string containing XML data, *parser* is an optional parser instance, defaulting to the standard XMLParser. Returns an (Element, dict) tuple, in which the dict maps element id:s to elements.
(text, parser=None)
| 1352 | |
| 1353 | |
| 1354 | def XMLID(text, parser=None): |
| 1355 | """Parse XML document from string constant for its IDs. |
| 1356 | |
| 1357 | *text* is a string containing XML data, *parser* is an |
| 1358 | optional parser instance, defaulting to the standard XMLParser. |
| 1359 | |
| 1360 | Returns an (Element, dict) tuple, in which the |
| 1361 | dict maps element id:s to elements. |
| 1362 | |
| 1363 | """ |
| 1364 | if not parser: |
| 1365 | parser = XMLParser(target=TreeBuilder()) |
| 1366 | parser.feed(text) |
| 1367 | tree = parser.close() |
| 1368 | ids = {} |
| 1369 | for elem in tree.iter(): |
| 1370 | id = elem.get("id") |
| 1371 | if id: |
| 1372 | ids[id] = elem |
| 1373 | return tree, ids |
| 1374 | |
| 1375 | # Parse XML document from string constant. Alias for XML(). |
| 1376 | fromstring = XML |