Re: Minify an xml into one line

Jérôme DESPATIS <[email protected]> Sat, 27 Aug 2011 12:14:57 +0200
Newsgroups gmane.comp.web.html-tidy.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============5761631061801913808==
Content-Type: multipart/alternative;
	boundary="------------000507010201030407040407"

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

Hello,

Thanks for your quick answer!
Ok so tidy doesn't support that natively

You're talking about the TidyNewline, but can I change this value in a 
config file somewhere ?
Because I only see it in 
http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html, and I 
would need to recompile tidy in order to change this value I'm afraid, no ?

If it's impossible without recompiling tidy, yes the only solution is to 
use a minifier as post process, I'm using some of them, gonna look 
deeper on xml support...

Thanks again

Le 27/08/2011 11:49, Ger Hobbelt a écrit :
> Hm, not exactly a task I'd imagine to apply tidy to (though I do use 
> it to 'pretty format' (X)HTML.
> AFAICT, your tidy config is about as 'tight' as it would get in terms 
> of produced output.
>
> Tidy doesn't come with a 'ditch all newlines' option, so you might 
> want to try & add the TidyNewline=NL (or TidyNewline=CR iff you know 
> the cdata will never carry lone CR's so you can safely postprocess by 
> removing all CRs, but I never tested this, so not sure if the cdata 
> will be binary intact -- test to see what happens in reality).
>
>
> Two roads from there:
>
> 1) either tweak the tidy code to allow for even more compact form 
> (which would give tidy more complete 'minifier' abilities by having it 
> strip out all the unnecessary newlines as well) and that leads to...
>
> 2) (since this task smells a lot like the same task for JavaScript and 
> CSS where the tools for that are called minifiers, e.g. jsmin) did you 
> check the net for availability of (X)HTML minifier tools? Because that 
> would be the path I'd take here: when XML minifiers per se are lacking 
> in google hits, find a HTML minifier which supports XHTML (which, in a 
> sense, is XML) and then apply that one in XHTML mode.
>
> Unless, of course, you're all for road #3, which I didn't think of. :-)
>
>
>
> On Sat, Aug 27, 2011 at 10:41 AM, Jérôme DESPATIS <[email protected] 
> <mailto:[email protected]>> wrote:
>
>     Hello,
>
>     I've had no answer from [email protected]
>     <mailto:[email protected]>, as a result I switch on this mailing
>     list, last try :)
>
>     So I have an xml file
>     I'd like to create the smallest file as I can.
>     So as a result I'd like that my xml holds on a single line (or 2
>     lines, the <?xml...> being the first line)
>
>     Any idea how to do this with tidy ? I haven't found the parameter
>     to perform that in tidy.
>     And another thing, I'd like to avoid post process that removes the
>     \n, as my xml may contain CDATA with \n in it, that I have to
>     leave untouched
>
>     My config for tidy is:
>     --------------------------
>     $config = array('input-xml'  => true,
>                     'output-xml' => true,
>                     'indent'     => false,
>                     'wrap'       => 0);
>
>     A minimalistic xml could be:
>     -----------------------------------
>     <?xml version="1.0" encoding="utf-8" standalone="yes"?>
>     <feed>
>     <title>Title</title>
>     <id>geofeed-contacts</id>
>     <entry>
>     <title>Title</title>
>     </entry>
>     </feed>
>
>     What I would like to have is the 2 lines (or even 1 line):
>     ----------------------------------------------------------------------
>
>     <?xml version="1.0" encoding="utf-8" standalone="yes"?>
>     <feed><title>Title</title><id>geofeed-contacts</id><entry><title>Title</title></entry></feed>
>
>
>     Any idea is welcome
>
>     Thanks!
>
>     -- 
>     Jérôme Despatis
>     [email protected]  <mailto:[email protected]>
>
>
>
>
> -- 
> Met vriendelijke groeten / Best regards,
>
> Ger Hobbelt
>
> --------------------------------------------------
> web: http://www.hobbelt.com/
> http://www.hebbut.net/
> mail: [email protected] <mailto:[email protected]>
> mobile: +31-6-11 120 978
> --------------------------------------------------
>


-- 
Jérôme Despatis
[email protected]


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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hello,<br>
    <br>
    Thanks for your quick answer!<br>
    Ok so tidy doesn't support that natively<br>
    <br>
    You're talking about the TidyNewline, but can I change this value in
    a config file somewhere ?<br>
    Because I only see it in
    <a class="moz-txt-link-freetext" href="http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html">http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html</a>, and I
    would need to recompile tidy in order to change this value I'm
    afraid, no ?<br>
    <br>
    If it's impossible without recompiling tidy, yes the only solution
    is to use a minifier as post process, I'm using some of them, gonna
    look deeper on xml support...<br>
    <br>
    Thanks again<br>
    <br>
    Le 27/08/2011 11:49, Ger Hobbelt a &eacute;crit&nbsp;:
    <blockquote
cite="mid:CAFP60fpdauXHdpSVcaC647xqMR4D_uusnd97ibL-GAXg-Q-CrQ@mail.gmail.com"
      type="cite">
      <div>Hm, not exactly a task I'd imagine to apply tidy to (though I
        do use it to 'pretty format' (X)HTML. </div>
      <div>AFAICT, your tidy config is about as 'tight' as it would get
        in terms of produced output.</div>
      <div><br>
      </div>
      <div>Tidy doesn't come with a 'ditch all newlines' option, so you
        might want to try &amp; add the TidyNewline=NL (or
        TidyNewline=CR iff you know the cdata will never carry lone CR's
        so you can safely postprocess by removing all CRs, but I never
        tested this, so not sure if the cdata will be binary intact --
        test to see what happens in reality).</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>Two roads from there:</div>
      <div><br>
      </div>
      <div>1) either tweak the tidy code to allow for even more compact
        form (which would give tidy more complete 'minifier' abilities
        by having it strip out all the unnecessary newlines as well) and
        that leads to...</div>
      <div><br>
      </div>
      <div>2) (since this task smells a lot like the same task for
        JavaScript and CSS where the tools for that are called
        minifiers, e.g. jsmin) did you check the net for availability of
        (X)HTML minifier tools? Because that would be the path I'd take
        here: when XML minifiers per se are lacking in google hits, find
        a HTML minifier which supports XHTML (which, in a sense, is XML)
        and then apply that one in XHTML mode.</div>
      <div><br>
      </div>
      <div>Unless, of course, you're all for road #3, which I didn't
        think of. :-)</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <br>
      <div class="gmail_quote">On Sat, Aug 27, 2011 at 10:41 AM, J&eacute;r&ocirc;me
        DESPATIS <span dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:[email protected]">[email protected]</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div bgcolor="#ffffff" text="#000000">
            <div style="font-family: -moz-fixed; font-size: 12px;"
              lang="x-western">Hello,<br>
              <br>
              I've had no answer from <a moz-do-not-send="true"
                href="mailto:[email protected]" target="_blank">[email protected]</a>,
              as a result I switch on this mailing list, last try :)<br>
              <br>
              So I have an xml file <br>
              I'd like to create the smallest file as I can. <br>
              So as a result I'd like that my xml holds on a single line
              (or 2 lines, the &lt;?xml...&gt; being the first line) <br>
              <br>
              Any idea how to do this with tidy ? I haven't found the
              parameter to perform that in tidy. <br>
              And another thing, I'd like to avoid post process that
              removes the \n, as my xml may contain CDATA with \n in it,
              that I have to leave untouched <br>
              <br>
              My config for tidy is: <br>
              -------------------------- <br>
              $config = array('input-xml'&nbsp; =&gt; true, <br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'output-xml' =&gt; true, <br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'indent'&nbsp;&nbsp;&nbsp;&nbsp; =&gt; false, <br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'wrap'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; 0); <br>
              <br>
              A minimalistic xml could be: <br>
              ----------------------------------- <br>
              &lt;?xml version="1.0" encoding="utf-8"
              standalone="yes"?&gt; <br>
              &lt;feed&gt; <br>
              &lt;title&gt;Title&lt;/title&gt; <br>
              &lt;id&gt;geofeed-contacts&lt;/id&gt; <br>
              &lt;entry&gt; <br>
              &lt;title&gt;Title&lt;/title&gt; <br>
              &lt;/entry&gt; <br>
              &lt;/feed&gt; <br>
              <br>
              What I would like to have is the 2 lines (or even 1 line):
              <br>
              ----------------------------------------------------------------------

              <br>
              &lt;?xml version="1.0" encoding="utf-8"
              standalone="yes"?&gt; <br>
              &lt;feed&gt;&lt;title&gt;Title&lt;/title&gt;&lt;id&gt;geofeed-contacts&lt;/id&gt;&lt;entry&gt;&lt;title&gt;Title&lt;/title&gt;&lt;/entry&gt;&lt;/feed&gt;

              <br>
              <br>
              Any idea is welcome <br>
              <br>
              Thanks! <br>
              <br>
            </div>
            <font color="#888888">
              <pre cols="72">-- 
J&eacute;r&ocirc;me Despatis
<a moz-do-not-send="true" href="mailto:[email protected]" target="_blank">[email protected]</a>
</pre>
            </font></div>
        </blockquote>
      </div>
      <br>
      <br clear="all">
      <br>
      -- <br>
      Met vriendelijke groeten / Best regards,<br>
      <br>
      Ger Hobbelt<br>
      <br>
      --------------------------------------------------<br>
      web:&nbsp; &nbsp; <a moz-do-not-send="true" href="http://www.hobbelt.com/">http://www.hobbelt.com/</a><br>
      &nbsp; &nbsp; &nbsp; &nbsp; <a moz-do-not-send="true" href="http://www.hebbut.net/">http://www.hebbut.net/</a><br>
      mail:&nbsp;&nbsp; <a moz-do-not-send="true" href="mailto:[email protected]">[email protected]</a><br>
      mobile: +31-6-11 120 978<br>
      --------------------------------------------------<br>
      <br>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
J&eacute;r&ocirc;me Despatis
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
</pre>
  </body>
</html>

--------------000507010201030407040407--


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

------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
--===============5761631061801913808==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tidy-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tidy-develop

--===============5761631061801913808==--