[ 
https://issues.apache.org/jira/browse/XMLBEANS-22?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12896790#action_12896790
 ] 

Martin Heitz commented on XMLBEANS-22:
--------------------------------------

Because there is no support here I patched locally the method next of the class 
Saver.PrettySaveCur to

        boolean next ( )
        {
            int k;

            if (_txt != null)
            {
                assert _txt.length() > 0;
                assert !_cur.isText();
                _txt = null;
                _isTextCData = false;
                k = _cur.kind();
            }
            else
            {
                int prevKind = k = _cur.kind();

                if (!_cur.next())
                    return false;

                _sb.delete( 0, _sb.length() );

                assert _txt == null;

                // place any text encountered in the buffer
                if (_cur.isText())
                {
                    // _cur.isTextCData() is expensive do it only if 
useCDataBookmarks option is enabled
                    _isTextCData = _useCDataBookmarks && _cur.isTextCData();
                    CharUtil.getString( _sb, _cur.getChars(), _cur._offSrc, 
_cur._cchSrc );
                    _cur.next();
                    // vvvvv fix: do not trim unconditionally  vvvvv 
//                      trim( _sb );
                    k = _cur.kind();
                    if (prevKind == ELEM && k == -ELEM) {
//                              System.out.println("not trimming '" + _sb + "' 
-- prevKind==" + prevKind+ ", k=" + k);
                    } else {
//                              System.out.println("trimming '" + _sb + "' -- 
prevKind==" + prevKind + ", k=" + k);
                        trim( _sb );
//                      System.out.println("... to   '" + _sb + "'");
                    }
                    // ^^^^^ fix: do not trim unconditionally  ^^^^^ 
                }

                k = _cur.kind();

                // Check for non leaf, _prettyIndent < 0 means that the save is 
all on one line

                if (_prettyIndent >= 0 &&
                      prevKind != COMMENT && prevKind != PROCINST && (prevKind 
!= ELEM || k != -ELEM))
//                if (prevKind != COMMENT && prevKind != PROCINST && (prevKind 
!= ELEM || k != -ELEM))
                {
                    if (_sb.length() > 0)
                    {
                        _sb.insert( 0, _newLine );
                        spaces( _sb, _newLine.length(), _prettyOffset + 
_prettyIndent * _depth );
                    }

                    if (k != -ROOT)
                    {
                        if (prevKind != ROOT)
                            _sb.append( _newLine );

                        int d = k < 0 ? _depth - 1 : _depth;
                        spaces( _sb, _sb.length(), _prettyOffset + 
_prettyIndent * d );
                    }
                }

                if (_sb.length() > 0)
                {
                    _txt = _sb.toString();
                    k = TEXT;
                }
            }

            if (k == ELEM)
                _depth++;
            else if (k == -ELEM)
                _depth--;

            return true;
        }

Good luck, Mattin 

P.S. Of course no guarantees that this does not have any side effects. I'm 
using this code now for more than a month and have not not notified any problem.


> xmlText trims whitespace within elements if prettyprint is on
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-22
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-22
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 1
>         Environment: Java 1.4.2_03, Win 2K
>            Reporter: Aaron Dunlop
>             Fix For: TBD
>
>         Attachments: whitespace-patch
>
>
> When called with XmlOptions.SAVE_PRETTY_PRINT, xmlText trims whitespace 
> within an element - e.g., ' a ' is converted to 'a'.
> Unless I'm completely missing something, the formatter shouldn't ever change 
> the contents of an element.
> The following test snippet reveals the problem:
>         XmlObject xdoc = XmlObject.Factory.parse("<test>  </test>");
>         Assert.assertEquals("<test>  </test>", xdoc.xmlText());
>         Assert.assertEquals("<test>  </test>" + newLine, xdoc.toString());
> The current build from CVS returns <test/>[newline] instead of <test>  
> <test>[newline].
> Complete testcase and patch to follow.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: dev-h...@xmlbeans.apache.org

Reply via email to