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.

Bug 170343 - xml:space should be respected when formatting XML.
Summary: xml:space should be respected when formatting XML.
Status: RESOLVED FIXED
Alias: None
Product: xml
Classification: Unclassified
Component: Text-Edit (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Vladimir Yaroslavskiy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-13 19:39 UTC by boen_robot
Modified: 2010-02-04 05:57 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description boen_robot 2009-08-13 19:39:36 UTC
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.
Comment 1 Sergey Lunegov 2009-08-14 10:21:02 UTC
Vladimir, please evaluate.
Comment 2 Vladimir Yaroslavskiy 2009-08-14 12:04:30 UTC
More likely, in module xml.text in class XMLLexerFormatter method isUnformattableToken(...) should be changed to skip
tag with xml:space="preserve".
Comment 3 Sergey Lunegov 2009-08-14 12:55:31 UTC
If fix easy then apply it.
Comment 4 boen_robot 2009-08-14 17:40:27 UTC
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>
===
Comment 5 Vladimir Yaroslavskiy 2009-10-20 08:08:53 UTC
fixed in main: 214835ffedfa
note: I switched format feature to implementation used by default in NetBeans
Comment 6 Quality Engineering 2009-10-22 23:37:01 UTC
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
Comment 7 Vladimir Yaroslavskiy 2010-02-04 05:57:10 UTC
related: #177192