| name | docx-tools |
| description | Extract, inspect, and compare .docx files by examining their XML structure. Use when analyzing Word documents, comparing versions, or debugging document issues. |
| allowed-tools | Bash, Read, Glob |
DOCX Tools
Extract, inspect, and compare .docx files by examining their underlying XML structure. Since .docx files are ZIP archives containing XML, we use standard Unix tools.
Installation
brew install tree
sudo apt install unzip libxml2-utils tree
Quick Reference
| Task | Command |
|---|
| List contents | unzip -l file.docx |
| View document XML | unzip -p file.docx word/document.xml | xmllint --format - |
| Extract to directory | unzip -o -d /tmp/docx-out file.docx |
| Compare content | diff <(unzip -p a.docx word/document.xml | xmllint --format -) <(unzip -p b.docx word/document.xml | xmllint --format -) |
| Compare structure | diff <(unzip -l a.docx) <(unzip -l b.docx) |
Inspection Workflow
Step 1: List archive contents
unzip -l document.docx
Step 2: View document structure (after extraction)
unzip -o -d /tmp/docx-out document.docx
tree /tmp/docx-out
Step 3: View formatted XML content
unzip -p document.docx word/document.xml | xmllint --format -
Comparison Workflow
Step 1: Quick structure check
unzip -l document-v1.docx
unzip -l document-v2.docx
Step 2: Compare main document content
diff -u <(unzip -p document-v1.docx word/document.xml | xmllint --format -) \
<(unzip -p document-v2.docx word/document.xml | xmllint --format -)
Step 3: Compare styles if formatting changed
diff -u <(unzip -p document-v1.docx word/styles.xml | xmllint --format -) \
<(unzip -p document-v2.docx word/styles.xml | xmllint --format -)
Extraction Commands
unzip -o -d /tmp/docx-extracted document.docx
unzip -o -d /tmp/docx-extracted document.docx word/document.xml
unzip -p document.docx word/document.xml
unzip -l document.docx
Comparison Commands
diff -u <(unzip -p a.docx word/document.xml | xmllint --format -) \
<(unzip -p b.docx word/document.xml | xmllint --format -)
diff -y <(unzip -p a.docx word/document.xml | xmllint --format -) \
<(unzip -p b.docx word/document.xml | xmllint --format -)
diff -q <(unzip -p a.docx word/document.xml | xmllint --format -) \
<(unzip -p b.docx word/document.xml | xmllint --format -)
diff <(unzip -l a.docx | awk 'NR>3 {print $4}' | sort) \
<(unzip -l b.docx | awk 'NR>3 {print $4}' | sort)
Inspection Commands
unzip -p document.docx docProps/core.xml | xmllint --format -
unzip -p document.docx docProps/app.xml | xmllint --format -
tree /tmp/docx-out
tree /tmp/docx-out -P '*.xml'
Key XML Files
| File | Contains |
|---|
word/document.xml | Main content (paragraphs, text) |
word/styles.xml | Style definitions |
word/numbering.xml | List formatting |
word/_rels/document.xml.rels | Links/images references |
docProps/core.xml | Author, dates, title |
docProps/app.xml | Word count, application info |
[Content_Types].xml | MIME type mappings |
Troubleshooting
Large diff output: Pipe to head -100 to limit lines.
Namespace noise: Focus on <w:t> tags for actual text content.
Binary comparison errors: Skip word/media/ directory - compare XML only.
Empty xmllint output: Check file path inside archive with unzip -l.