xml-formatter
xml-formatter copied to clipboard
Is there support for Visual Studio like formatting each attribute in new line with indentation?
Expected:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="App9.MainPage">
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
Default
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="App9.MainPage">
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
Thanks for your message.
According to you, what should be the rule to wrap the attributes into the next line ?
I am just wondering if we can format XML as above, see the first attribute is on same line as of start tag and remaining attributes aligned with first attribute?
I will look into it if that can be done easily but I can't give you a time estimate.
@chrisbottin I think it can be done by having a parameter on line length. E.g. above 120 character length if there are at least 2 attributes, the 2nd, 3rd, etc gets the padding of (tag's padding + tags length + 1 (opening '<') + 1 (space)) or simply just an extra padding as it would be a child element. These are just ideas, I am not sure what other issues might be here.
Thanks for your comment @dgergely, I agree it's a good approach. I might take a look this week.
I couldnt find this feature in any npm packages or even standard C# XMLWriter
unfortunately. I ended up writing it down through C# and using electron-edge-js to call dll for my extension PrettyXML
Yes the approach is to track element space length and attribute space length separately.