Re: additional spaces in complex elements using PrettyFormat

Rolf Lear <[email protected]> Tue, 15 Jan 2013 06:36:22 -0500
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============0054026423==
Content-Type: multipart/alternative;
 boundary="------------050901010708040205010603"

This is a multi-part message in MIME format.
--------------050901010708040205010603
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


Hi  S...

If white-space is important to you you can do a number of things....

1. you can use the *raw* Format (which changes nothing) instead of the 
Pretty or Compact format, and then set up your JDOM content to have the 
right whitespace in the right places, then the Outputter with Raw 
formatter will not modify the whitespace (which both Pretty and Compact do).
2. if only *part* of the XML document has significant whitespace (which 
I think is your case), then you can use the xml:space="preserve" 
attribute and JDOM will not modify any whitespace in that content.

     <paragraph align="justified" xml:space="preserve">
       According to the normalized curve A (LA<sub>eq inter</sub>) the 
values...
     </paragraph >

Rolf

On 15/01/2013 3:56 AM, SoTaNeZ wrote:
> Hello.
>
> I have some complex elements in which their texts are mixed with some 
> HTML markup that I treat as XML elements. For example:
>
> ------------------------------------------------------
>     <paragraph align="justified">
>       According to the normalized curve A (LA
>       <sub>eq inter</sub>
>       ) the values...
>     </paragraph >
> ------------------------------------------------------
>
> The above example is in PrettyFormat.
>
> My intention is to use an XSL to transform this text to HTML, keeping 
> the HTML representation, so using "xsl:copy-of" I can copy the whole 
> paragraph as is.
> The problem is that the XML elements inserted between the text are 
> represented in a new line, so the XLT transformation adds both white 
> spaces before and after these elements in the HTML output:
>
> ------------------------------------------------------
> According to the normalized curve A (LA eq inter ) the values...
> ------------------------------------------------------
>
> when the output I want should be:
>
> ------------------------------------------------------
> According to the normalized curve A (LAeq inter) the values...
> ------------------------------------------------------
>
> I cannot use the CompactFormat, because I need these XMLs to be 
> readable by humans.
>
> The problem is solved if I manually place these inner XML elements in 
> the same line with the rest of the text:
>
> ------------------------------------------------------
>     <paragraph align="justified">
>       According to the normalized curve A (LA<sub>eq inter</sub>) the 
> values...
>     </paragraph >
> ------------------------------------------------------
>
> Is there a way to tell JDOM to format complex XML elements (those 
> having text and other elements) this way, or maybe other workarounds?
>
> I prefer to avoid post-processing of the outputted XMLs files...
>
> Thank you very much.
>
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/[email protected]


--------------050901010708040205010603
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <div class="moz-cite-prefix">Hi&nbsp; S...<br>
      <br>
      If white-space is important to you you can do a number of
      things....<br>
      <br>
      1. you can use the *raw* Format (which changes nothing) instead of
      the Pretty or Compact format, and then set up your JDOM content to
      have the right whitespace in the right places, then the Outputter
      with Raw formatter will not modify the whitespace (which both
      Pretty and Compact do).<br>
      2. if only *part* of the XML document has significant whitespace
      (which I think is your case), then you can use the
      xml:space="preserve" attribute and JDOM will not modify any
      whitespace in that content.<br>
      <br>
      <div>
        <div>&nbsp; &nbsp; &lt;paragraph align="justified"
          xml:space="preserve"&gt;</div>
        <div>&nbsp; &nbsp; &nbsp; According to the normalized curve A (LA&lt;sub&gt;eq
          inter&lt;/sub&gt;) the values...</div>
        <div>&nbsp; &nbsp; &lt;/paragraph&nbsp;&gt;</div>
      </div>
      <br>
      Rolf<br>
      <br>
      On 15/01/2013 3:56 AM, SoTaNeZ wrote:<br>
    </div>
    <blockquote
cite="mid:CAJypjWfh_rRKNR0YHvnRUhysv51EsyCphHMkJf5X+bwmhoTEDg@mail.gmail.com"
      type="cite">Hello.
      <div><br>
        <div>I have some complex elements in which their texts are mixed
          with some HTML markup that I treat as XML elements. For
          example:</div>
        <div><br>
        </div>
        <div>------------------------------------------------------</div>
        <div>
          <div>&nbsp; &nbsp; &lt;paragraph align="justified"&gt;</div>
          <div>&nbsp; &nbsp; &nbsp; According to the normalized curve A (LA</div>
          <div>&nbsp; &nbsp; &nbsp; &lt;sub&gt;eq inter&lt;/sub&gt;</div>
          <div>&nbsp; &nbsp; &nbsp; ) the values...</div>
          <div>&nbsp; &nbsp; &lt;/paragraph&nbsp;&gt;</div>
        </div>
        <div>------------------------------------------------------</div>
        <div><br>
        </div>
        <div>The above example is in PrettyFormat.</div>
        <div><br>
        </div>
        <div>My intention is to use an XSL to transform this text to
          HTML, keeping the HTML representation, so using "xsl:copy-of"
          I can copy the whole paragraph as is.</div>
        <div>The problem is that the XML elements inserted between the
          text are represented in a new line, so the XLT transformation
          adds both white spaces before and after these elements in the
          HTML output:</div>
        <div><br>
        </div>
        <div> ------------------------------------------------------</div>
        <div>
          <div>According to the normalized curve A (LA&nbsp;<font size="1">eq
              inter</font>&nbsp;) the values...</div>
        </div>
        <div>------------------------------------------------------</div>
        <div><br>
        </div>
        <div>when the output I want should be:</div>
        <div><br>
        </div>
        <div>------------------------------------------------------</div>
        <div>According to the normalized curve A (LA<font size="1">eq
            inter</font>) the values...</div>
        <div>------------------------------------------------------</div>
        <div><br>
        </div>
        <div>I cannot use the CompactFormat, because I need these XMLs
          to be readable by humans.</div>
        <div><br>
        </div>
        <div>The problem is solved if I manually place these inner XML
          elements in the same line with the rest of the text:</div>
        <div><br>
        </div>
        <div>------------------------------------------------------</div>
        <div>
          <div>&nbsp; &nbsp; &lt;paragraph align="justified"&gt;</div>
          <div>&nbsp; &nbsp; &nbsp; According to the normalized curve A
            (LA&lt;sub&gt;eq inter&lt;/sub&gt;) the values...</div>
          <div>&nbsp; &nbsp; &lt;/paragraph&nbsp;&gt;</div>
        </div>
        <div>------------------------------------------------------</div>
        <div><br>
        </div>
        <div>Is there a way to tell JDOM to format complex XML elements
          (those having text and other elements) this way, or maybe
          other workarounds?</div>
        <div><br>
        </div>
        <div>I prefer to avoid post-processing of the outputted XMLs
          files...</div>
        <div><br>
        </div>
        <div>Thank you very much.</div>
      </div>
      <div><br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
To control your jdom-interest membership:
<a class="moz-txt-link-freetext" href="http://www.jdom.org/mailman/options/jdom-interest/[email protected]">http://www.jdom.org/mailman/options/jdom-interest/[email protected]</a></pre>
    </blockquote>
    <br>
  </body>
</html>

--------------050901010708040205010603--

--===============0054026423==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
--===============0054026423==--