开发者

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

开发者 https://www.devze.com 2023-04-11 22:21 出处:网络
If I write multi-line documentation in an XML schema using the properties view it creates <xsd:documentation> tags to contain it.

If I write multi-line documentation in an XML schema using the properties view it creates <xsd:documentation> tags to contain it.

Whenever I format the file (CTRL+SHIFT+F) all lines but the first are indented and sometimes wrapped due to this indentation.

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 Preferenc开发者_开发百科es -> XML -> XML files -> Editor does not help with the indentation. 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. 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>


"Format comments" option is for XML comments:

<!-- 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).

If your XML is:

<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. Unfortunately there is no option to turn width checking off (for example to set "line width" to 0).

edit: it seems that when you use <![CDATA[, Eclipse is not formating the content (at least indentation and line wrapping), example:

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


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


Set the option "Preserve whitespace in tags with PCDATA content".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号