simple command to strip header and footer from a file

Using sed:

 sed -n '/<Document>/,/<\/Document>/ p' yourfile.xml

Explanation:

  • -n makes sed silent, meaning it does not output the whole file contents,
  • /pattern/ searches for lines including specified pattern,
  • a,b (the comma) tells sed to perform an action on the lines from a to b (where a and b get defined by matching the above patterns),
  • p stands for print and is the action performed on the lines that matched the above.

Edit: If you'd like to additionally strip the whitespace before <Document>, it can be done this way:

 sed -ne '/ <Document>/s/^ *//' -e '/<Document>/,/<\/Document>/ p' yourfile.xml