bytes XML serialization of this relationship collection. This value is suitable for storage as a .rels file in an OPC package. Includes a `<?xml..` declaration header with encoding as UTF-8.
(self)
| 593 | |
| 594 | @property |
| 595 | def xml(self): |
| 596 | """bytes XML serialization of this relationship collection. |
| 597 | |
| 598 | This value is suitable for storage as a .rels file in an OPC package. Includes a `<?xml..` |
| 599 | declaration header with encoding as UTF-8. |
| 600 | """ |
| 601 | rels_elm = CT_Relationships.new() |
| 602 | |
| 603 | # -- Sequence <Relationship> elements deterministically (in numerical order) to |
| 604 | # -- simplify testing and manual inspection. |
| 605 | def iter_rels_in_numerical_order(): |
| 606 | sorted_num_rId_pairs = sorted( |
| 607 | ( |
| 608 | int(rId[3:]) if rId.startswith("rId") and rId[3:].isdigit() else 0, |
| 609 | rId, |
| 610 | ) |
| 611 | for rId in self.keys() |
| 612 | ) |
| 613 | return (self[rId] for _, rId in sorted_num_rId_pairs) |
| 614 | |
| 615 | for rel in iter_rels_in_numerical_order(): |
| 616 | rels_elm.add_rel(rel.rId, rel.reltype, rel.target_ref, rel.is_external) |
| 617 | |
| 618 | return rels_elm.xml_file_bytes |
| 619 | |
| 620 | def _add_relationship(self, reltype: str, target: Part | str, is_external: bool = False) -> str: |
| 621 | """Return str rId of |_Relationship| newly added to spec.""" |