【问题标题】:Visual Studio XML formatting - first attribute in same line issueVisual Studio XML 格式 - 同一行问题中的第一个属性
【发布时间】:2020-01-04 18:34:46
【问题描述】:

我想格式化一个 xml(最小化以删除格式)

<?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"/>

我希望它像 Visual Studio Windows(下)一样格式化它,第一个属性位于元素的第一行,保持与第一个属性对齐。

<?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"/>

很遗憾,Visual Studio Mac 没有相同的设置

所以我尝试了多种方法来编辑格式规则,例如下面的标记和标记对齐以及下一行选项,但最好的方法如下所示

<?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" />

此外,我尝试在 Visual Studio Code 中进行格式化,发现使用提供的设置很难实现相同的行为。

我发现 Visual Studio for mac 确实支持 Sublime 和 Textmate 包。我试图找到一个,但找不到。

有没有一种方法可以像在 Windows 上的 Visual Studio 中一样实现相同的格式?

【问题讨论】:

    标签: xml visual-studio xaml visual-studio-mac xml-formatting


    【解决方案1】:

    没有任何 XML 序列化程序能够准确地为您提供所需的内容,而且很少有人会为您提供 VS 显然为您提供的详细控制级别,但在这种情况下,默认的 Saxon 序列化(带有 indent=yes)似乎给了你你想要的东西:

    <?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"/>
    

    当然,这可能并不总是正确的。

    【讨论】:

    • 谢谢。如何在 VS Mac 中实现这种 Saxon 解析和格式化?
    • 我不确定你可以;您可能需要调用不同的环境,例如Java。
    猜你喜欢
    • 1970-01-01
    • 2016-10-06
    • 2011-02-07
    • 2021-08-19
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    相关资源
    最近更新 更多