A Python script that counts the total number of verses in an XML-formatted Bible file (RVIC.xml) and compares it with the expected count of 31,102 verses.
This script parses an XML Bible file using the ElementTree library and traverses through its structure to count verses. It's designed to work with XML files that follow a specific hierarchical structure where books contain chapters, and chapters contain verses.
- XML parsing using ElementTree
- Hierarchical traversal of Bible structure
- Verse counting validation
- Error handling
- Python 3.x
- XML Bible file (RVIC.xml)
python count_verses.py
Total number of verses found: 31102
Expected number of verses: 31,102
Matches expected count: True
graph TD
A[Start] --> B[Parse XML File]
B --> C[Initialize Verse Counter]
C --> D[Iterate Through Books]
D --> E[Iterate Through Chapters]
E --> F[Count Verses in Chapter]
F --> G{More Chapters?}
G -->|Yes| E
G -->|No| H{More Books?}
H -->|Yes| D
H -->|No| I[Display Results]
I --> J[Compare with Expected Count]
J --> K[End]
style A fill:#98FB98
style K fill:#FF6B6B
style I fill:#87CEEB
style J fill:#87CEEB
The script expects the Bible XML file to follow this structure:
<bible>
<b> <!-- Book -->
<c> <!-- Chapter -->
<v>Verse content</v>
</c>
</b>
</bible>
The script includes error handling to catch and display any issues that might occur during:
- File reading
- XML parsing
- Tree traversal
The script validates the count against the known number of verses in the Bible (31,102) and reports whether the counts match.