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