Visual Studio XML formatting - first attribute in same line issue

1k Views Asked by At

I want to format a xml (minimized to remove formatting)

<?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:local="clr-namespace:TipCalculator" x:Class="TipCalculator.MainPage" Padding="40"/>

I want it to format it like Visual Studio Windows(below) with first attribute being on first line of the element, remaining being aligned to the first attribute.

<?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:local="clr-namespace:TipCalculator" 
             x:Class="TipCalculator.MainPage" 
             Padding="40"/>

Unfortunately Visual Studio Mac does not have same settings

So I tried multiple ways to edit formatting rules like below marking and marking align and next line options but the best it looks like below

<?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:local="clr-namespace:TipCalculator"
    x:Class="TipCalculator.MainPage"
    Padding="40" />

Additionally I tried formatting in Visual Studio Code, I found it hard to achieve the same behavior with the offered settings.

Screenshot

I found that Visual Studio for mac does support Sublime and Textmate packages. I tried to find one but could not.

Is there a way I can achieve same formatting like I do in Visual Studio on windows?

1

There are 1 best solutions below

2
Michael Kay On

No XML serializer is ever going to give you exactly what you want, and few are going to give you the detailed level of control that VS apparently gives you, but on this occasion, the default Saxon serialization (with indent=yes) seems to give you what you are looking for:

<?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:local="clr-namespace:TipCalculator"
             x:Class="TipCalculator.MainPage"
             Padding="40"/>

Of course, that might not always be true.