Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML formatting Indentation Tags Matching - Linux

I have an XML file whose format is quite compressed and all tags are stick together like

<PersonalData><IndividualDetails><Title>Mr</Title><Gender>Male</Gender><FirstName>Hae</FirstName><Surname>JONES</Surname><Occupation>Banker</Occupation><DateofBirth>4/6/76</DateofBirth><LastKnownAddress></LastKnownAddress><LastKnownPostCode>00145</LastKnownPostCode><OtherNames></OtherNames></IndividualDetails><OccupationDetails><Company>SD Bank</Company><CompanyAddress>Sunset Boulevard NY</CompanyAddress><ContactNo>335698457</ContactNo></OccupationDetails></PersonalData>

Is there any command in shell that can properly format the tags. If not indentation only adding the tags to their own lines can also solve my problem.

like image 897
HardCode Avatar asked Aug 15 '12 07:08

HardCode


1 Answers

xmllint --format <your-xml-file>

example

$ cat test.xml
<a><b>c</b></a>
$ xmllint --format test.xml
<a>
  <b>c</b>
</a>
$ xmllint --format test.xml > test.formatted.xml
$ cat test.formatted.xml
<a>
  <b>c</b>
</a>
$
like image 75
Jin Kwon Avatar answered Nov 15 '22 11:11

Jin Kwon