DOMUtils
dcmspec.dom_utils.DOMUtils
Utility class for DOM navigation and extraction in DICOM XHTML documents.
Provides methods for locating tables and table IDs within a parsed BeautifulSoup DOM, with optional logging for warnings and debug information.
Typical usage
dom_utils = DOMUtils(logger=logger)
table = dom_utils.get_table(dom, table_id)
table_id = dom_utils.get_table_id_from_section(dom, section_id)
Source code in src/dcmspec/dom_utils.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 116 | |
__init__(logger=None)
Initialize DOMUtils with an optional logger.
| PARAMETER | DESCRIPTION |
|---|---|
logger
|
Logger instance to use for warnings and debug messages. If None, a default logger is created.
TYPE:
|
Source code in src/dcmspec/dom_utils.py
31 32 33 34 35 36 37 38 39 40 41 | |
get_table(dom, table_id)
Retrieve the table element with the specified ID from the DOM.
DocBook XML to XHTML conversion stylesheets enclose tables in a
| PARAMETER | DESCRIPTION |
|---|---|
dom
|
The BeautifulSoup DOM object.
TYPE:
|
table_id
|
The ID of the table to retrieve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[Tag]
|
The table element if found, otherwise None. |
Source code in src/dcmspec/dom_utils.py
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 | |
get_table_id_from_section(dom, section_id)
Get the id of the first table in a section.
Retrieve the first table_id (anchor id) of a <div class="table"> inside a <div class="section">
that contains an anchor tag with the given section id, e.g.:
<a id="table_C.7-1" shape="rect"></a>
| PARAMETER | DESCRIPTION |
|---|---|
dom
|
The parsed XHTML DOM object.
TYPE:
|
section_id
|
The id of the section to search for the table_id.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
Optional[str]: The id of the first table anchor found, or None if not found. |
Source code in src/dcmspec/dom_utils.py
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 116 | |