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

If I write multiline documentation in an XML schema using a property view, it creates the <xsd:documentation> tags to contain it.

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

This indentation and packaging effectively destroy all efforts to create beautiful documentation from a file. Especially if I want to document a table of valid values.

Before formatting:

 <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 option "Comment format" in the settings → XML → XML files → Editor does not help with indentation. Increasing the "Line Width" on one settings page fixes the transfer, but I really want the editor to NOT format my documentation items.

+7
source share
4 answers

You can add the xml attribute xml xml:space="preserve" to xsd:documentation to indicate that spaces should be kept. 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> 
+4
source

The option "Format comments" is intended for XML comments:

 <!-- comment --> 

That is why it does not work as you wish.

I do not understand what problems you encounter when setting the "line width" parameter to max (in version 3.7 it is 999).

If your 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 set the "line width" to 999, and formatting does not change your content. Unfortunately, there is no option to disable width checking (for example, to set the line width to 0).

change it seems that when you use <! [CDATA [, Eclipse does not generate content (at least indentation and line wrapping), for 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> 
+1
source

Try using it as follows:

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

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

in your file if you are not using it yet. Newlines in xml can be problematic between ASCII and UTF-16

+1
source

Set the "Save spaces in tags with PCDATA content" option.

0
source

All Articles