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