Search code examples
bashxmllint

xmllint: Formating without adding header


Is there a way to use $xmllint --format file without the header section?

<?xml version="1.0"?>
<Tag>
  <Sub>A</Sub>
</Tag>

I know you can use --c14n but that does not seem to mix well with --format. As $xmllint --format --c14n file will just produce:

<Tag><Sub>A</Sub></Tag>

Desired Result

<Tag>
  <Sub>A</Sub>
</Tag>

Solution

  • You can use sed to remove the first line. Not saying it's the best but it would get you going:

    xmllint --format <file> | sed 1d
    

    You would preferrable try to avoid one million calls to xmllint. And sed or tail.

    I'm not sure if xmllint supports inplace edit. But if it does then something like this might be possible:

    xargs < list_of_files_to_change.txt xmllint --inplace --format
    xargs < list_of_files_to_change.txt sed -i 1d