有没有办法阻止Eclipse(3.7)弄乱<xsd:documentation>标签的内容?</xsd:documentation>

时间:2011-10-07 08:30:58

标签: xml eclipse xsd

如果我使用属性视图在XML架构中编写多行文档,则会创建<xsd:documentation>标记以包含它。

每当我格式化文件(CTRL + SHIFT + F)时,除了第一行之外的所有行都是缩进的,有时由于这种缩进而被包装。

这种缩进和包装有效地破坏了从文件生成漂亮文档的所有努力。特别是如果我想记录一个允许值的表格。

格式化之前:

<xsd:documentation>1st line of comment
2nd line is indented and also wrapped as it exceeds the max line length setting.
3rd line is just indented.
</xsd:documentation>

格式化后:

<xsd:documentation>1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line 
    length setting.
    3rd line is just indented.
</xsd:documentation>

“偏好设置”中的“格式化评论”选项 - &gt; XML - &gt; XML文件 - &gt;编辑对缩进没有帮助。在相同的首选项页面上增加“行宽”可以修复包装,但我真的希望编辑器不要格式化我的文档元素的内容。

4 个答案:

答案 0 :(得分:4)

您可以向xml:space="preserve"添加xml属性xsd:documentation,以告知必须保留空格。例如:

<xsd:documentation xml:space="preserve" >1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line length setting.
    3rd line is just indented.
</xsd:documentation>

答案 1 :(得分:1)

“格式注释”选项适用于XML注释:

<!-- comment -->

这就是为什么它没有按你的意愿工作。

我不明白将“线宽”选项设置为最大值时遇到的问题(在版本3.7中为999)。

如果你的XML是:

<xsd:documentation>1st line of comment
    2nd line is indented and also wrapped as it exceeds the max line length setting.
    3rd line is just indented.
</xsd:documentation>

然后将“线宽”设置为999,格式化不会更改您的内容。不幸的是,有没有选项可以关闭宽度检查(例如将“线宽”设置为0)。

修改 似乎当你使用&lt;![CDATA [,Eclipse没有形成内容(至少是缩进和换行)时,例如:

<root>
    <documentation><![CDATA[
                1st line of comment

                2nd line is indented and also wrapped as it exceeds the max line length setting.

                3rd line is just indented.
        ]]></documentation>
</root>

答案 2 :(得分:1)

尝试使用它:

<xsd:documentation><![CDATA[ 1st line of comment
2nd line is indented and also wrapped as it exceeds the max line 
length setting.
3rd line is just indented.]]></xsd:documentation>

但是也要尝试设置

<?xml version="1.0" encoding="UTF-16"?>

在您的文件中,如果您尚未使用它。 xml中的新行在ASCII和UTF-16之间可能存在问题

答案 3 :(得分:0)

设置选项“使用PCDATA内容保留标签中的空白”。