This Python script facilitates the transfer of Bible verses from one XML file to another while preserving the hierarchical structure and formatting. It's designed to work with XML files that follow a specific structure of testament > book > chapter > verse.
- Preserves XML hierarchy and structure
- Maintains verse attributes during transfer
- Performs verse count validation
- Handles XML parsing errors gracefully
The script follows these steps to transfer verses:
- XML Loading: Loads both input and output XML files using ElementTree
- Hierarchical Traversal: Iterates through the XML structure in parallel
- Verse Transfer: Copies verse text while preserving attributes
- Validation: Verifies the total number of verses transferred (expected: 31,102)
graph TD
A[Load Input XML] --> C{Parse Successful?}
B[Load Output XML] --> C
C -->|Yes| D[Traverse XML Structure]
C -->|No| E[Error Handling]
D --> F[Testament Level]
F --> G[Book Level]
G --> H[Chapter Level]
H --> I[Verse Level]
I --> J[Transfer Verse Text]
J --> K[Update Count]
K --> L{All Verses Done?}
L -->|No| I
L -->|Yes| M[Save Output XML]
M --> N[Verify Verse Count]
graph TD
A[XML Root] --> B[Testament]
B --> C[Book]
C --> D[Chapter]
D --> E[Verse]
E --> F[Verse Text & Attributes]
- Prepare your input XML file (
input-bible.xml) with the source verses - Create an output XML file (
output-file.xml) with the desired structure - Run the script:
python transfer_verses.py
- The script will transfer verses and display the results
- Python 3.x
- xml.etree.ElementTree (built-in Python library)
- Loads and parses XML file
- Returns root element or None if error occurs
- Handles parsing and file not found errors
- Traverses XML structure in parallel
- Transfers verse text while preserving attributes
- Returns total number of verses transferred
- Orchestrates the overall process
- Performs validation and error checking
- Displays transfer statistics
The script includes built-in validation:
- Verifies successful XML parsing
- Counts total verses transferred
- Compares against expected verse count (31,102)
- Warns if verse count doesn't match expected total
The script handles common errors:
- XML parsing errors
- Missing input/output files
- Structure mismatches
- Invalid XML format