简体   繁体   English

有没有一种方法可以阻止Eclipse(3.7)弄乱内容 <xsd:documentation> 标签?

[英]Is there a way to stop Eclipse (3.7) from messing up content of <xsd:documentation> tags?

If I write multi-line documentation in an XML schema using the properties view it creates <xsd:documentation> tags to contain it. 如果我使用属性视图在XML模式中编写多行文档,则会创建<xsd:documentation>标记来包含它。

Whenever I format the file (CTRL+SHIFT+F) all lines but the first are indented and sometimes wrapped due to this indentation. 每当我格式化文件(CTRL + SHIFT + F)时,除第一行外,所有行都会缩进,有时由于此缩进而被换行。

This indentation and wrapping effectively ruins every effort of generating a nice looking documentation from the file. 这种缩进和换行有效地破坏了从文件生成美观文档的所有努力。 Especially if I want to document a table of allowed values. 特别是如果我要记录允许值的表格。

Before format: 格式化前:

<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>

After format: 格式后:

<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>

The "Format comments" option in Preferences -> XML -> XML files -> Editor does not help with the indentation. 首选项-> XML-> XML文件->编辑器中的“格式化注释”选项对缩进没有帮助。 Increasing "Line width" on the same preferences page fixes wrapping but I really want the editor to NOT format my the contents of my documentation elements. 在相同的首选项页面上增加“行宽”可以解决换行问题,但我确实希望编辑器不要格式化文档元素的内容。

You could add an xml atribute xml:space="preserve" to xsd:documentation to tell that spaces must be preserved. 您可以在xsd:documentation添加一个xml属性xml:space="preserve"来告知必须保留空格。 For example: 例如:

<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>

Try using it like this: 尝试像这样使用它:

<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>

But ALSO , try to set 但是还请尝试设置

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

in your file, if you are not already using it. 在文件中(如果尚未使用)。 New lines in xml can be problematic between ASCII and UTF-16 xml和utf-16之间的xml中的新行可能会出现问题

"Format comments" option is for XML comments: “格式化注释”选项用于XML注释:

<!-- comment -->

That's why it's not working as you wish. 这就是为什么它无法如您所愿的工作。

I do not understand what problem are you facing with setting "line width" option to max (in version 3.7 it is 999). 我不明白将“ line width”选项设置为max会遇到什么问题(在3.7版中为999)。

If your XML is: 如果您的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>

Then setting "line width" to 999 and formatting does not change your content. 然后将“线宽”设置为999,格式不会更改您的内容。 Unfortunately there is no option to turn width checking off (for example to set "line width" to 0). 不幸的是, 没有选项可以关闭宽度检查(例如,将“线宽”设置为0)。

edit: it seems that when you use <![CDATA[, Eclipse is not formating the content (at least indentation and line wrapping), example: 编辑:似乎当您使用<![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>

设置选项“在带有PCDATA内容的标签中保留空白”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM