So here's my XML output:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
android:compileSdkVersion="23"
android:compileSdkVersionCodename="6.0-2438415"
package="com.mycompany.myapp"
platformBuildVersionCode="23"
platformBuildVersionName="6.0-2438415"
>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="28"
>
</uses-sdk>
<!-- Read the contents of your shared storage -->
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
>
</uses-permission>
<!-- Modify or delete the contents of your shared storage -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
>
</uses-permission>
<application
android:theme="@7F1001D3"
android:label="@7F0F001B"
android:icon="@7F0D0000"
android:allowBackup="false"
android:supportsRtl="true"
android:roundIcon="@7F0D0001"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
>
<activity
android:name="com.mycompany.myapp.MainActivity"
android:configChanges="screenSize|orientation"
>
<intent-filter
>
<action
android:name="android.intent.action.MAIN"
>
</action>
<category
android:name="android.intent.category.LAUNCHER"
>
</category>
</intent-filter>
</activity>
</application>
</manifest>
As you can see, it's already indented, and each attribute inside tag starting in a newline, but it has weird end tags, such as:
<tag
prefix:name="str"
>
</tag>
or:
<tag
prefix:name="str1"
prefix:name2="str2"
>
</tag>
instead of:
<tag prefix:name="str" />
or:
<tag
prefix:name="str1"
prefix:name2="str2" />
My question is, how to prettify XML, with each attribute inside tag starting in a newline (except when there's only one attribute in tag), end tags correction and without comments omitting? Here you can see my desired output:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
android:compileSdkVersion="23"
android:compileSdkVersionCodename="6.0-2438415"
package="com.mycompany.myapp"
platformBuildVersionCode="23"
platformBuildVersionName="6.0-2438415">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="28" />
<!-- Read the contents of your shared storage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Modify or delete the contents of your shared storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:theme="@7F1001D3"
android:label="@7F0F001B"
android:icon="@7F0D0000"
android:allowBackup="false"
android:supportsRtl="true"
android:roundIcon="@7F0D0001"
android:appComponentFactory="androidx.core.app.CoreComponentFactory">
<activity
android:name="com.mycompany.myapp.MainActivity"
android:configChanges="screenSize|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Tried to use various prettifiers, such as Java's transformer, Apache Xerces's XML Serializer and etc.
Java's transformer doesn't correct end tags. However, Apache Xerces corrects end tags, comments don't omit, but each attribute inside tag don't start in a newline.
Or maybe I could try to correct end tags in string level if the output is already indented?
XML is always outputted in the same format.