This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
There are many instances in XML where whitespace is important to be kept as is. That's why XML has a built in facility for that - the xml:space attribute. When set as xml:space="preserve", it denotes that the whitespace in this node and its descendants should be parsed as is. The "Source > Format" option in NetBeans does't respect that when doing formatting, which can cause various "anomalies" if the user doesn't manually put the XML back in order. To illustrate where this creates problems, consider for example an XSLT document with this in it: ===== <xsl:attribute name="x" xml:space="preserve"><xsl:value-of select="$a"/>/<xsl:value-of select="$b" /></xsl:attribute> ===== And suppose that $a is 1, while $b is 2. The result of this would be ===== x="1/2" ===== However, after source formatting, the XSLT is ===== <xsl:attribute name="x" xml:space="preserve"> <xsl:value-of select="$a"/>/ <xsl:value-of select="$b" /> </xsl:attribute> ===== And the result becomes ===== x=" 1/ 2 " ===== because the XSLT processor respects whitespace in the xsl:attribute element (with or without xml:space btw). If NetBeans respects xml:space, developers could use it to mark areas they don't want formatted exactly because they know formatting would create such kind of issues. I'm using NetBeans v6.7.1 with all plug-ins updated to the latest on Windows Vista x64 SP2 with all required updates installed and JDK6u15, though I suppose this info is irrelevant for this issue.
Vladimir, please evaluate.
More likely, in module xml.text in class XMLLexerFormatter method isUnformattableToken(...) should be changed to skip tag with xml:space="preserve".
If fix easy then apply it.
Before you start ignoring everything in nodes with xml:space="preserve", let me also add that xml:space has a possible value of "default", in which case whitespace is treated normally, and is therefore formattable. This is important to note in cases where xml:space="default" is a child of a node with xml:space="preserve", like for example: === <xsl:element name="a" xml:space="preserve"> Keep this as is<xsl:attribute name="x" xml:space="default"><xsl:value-of select="$a"/>Do format<xsl:value-of select="$b"/>.</xsl:attribute>, and this too </xsl:element> === Which after formatting should be === <xsl:element name="a" xml:space="preserve"> Keep this as is<xsl:attribute name="x" xml:space="default"> <xsl:value-of select="$a"/>Do format <xsl:value-of select="$b"/>. </xsl:attribute>, and this too </xsl:element> ===
fixed in main: 214835ffedfa note: I switched format feature to implementation used by default in NetBeans
Integrated into 'main-golden', will be available in build *200910221401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/214835ffedfa User: Vladimir Yaroslavskiy <yaroslavskiy@netbeans.org> Log: [Issue #170343] xml:space should be respected when formatting XML
related: #177192