Re: Minify an xml into one line

Klaus Johannes Rusch <[email protected]> Sat, 27 Aug 2011 12:24:28 +0200
Newsgroups gmane.comp.web.html-tidy.devel
Organization atmedia.net
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============3920518086667481884==
Content-Type: multipart/alternative;
	boundary="------------090709010604080507020707"

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

On 27.08.2011 12:14, J=E9r=F4me DESPATIS wrote:
> 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=20
> config file somewhere ?
> Because I only see it in=20
> http://tidy.sourceforge.net/docs/api/tidyenum_8h-source.html, and I=20
> would need to recompile tidy in order to change this value I'm afraid,=20
> no ?
>
> If it's impossible without recompiling tidy, yes the only solution is=20
> to use a minifier as post process, I'm using some of them, gonna look=20
> deeper on xml support...
A simple XSLT stylesheet should work for post-processing, e.g.

<?xml version=3D"1.0" encoding=3D"utf-8"?>

<!--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
     Condense.xsl

     Removes comments and extraneous whitespace from a source file.
     Good for optimizing an XSL document. Only pitfalls are that it might
     rearrange attributes, depending on the processor implementation.
     (I haven't actually seen that happen, though), and it will definitel=
y
     not copy DTD information or entity references into the new tree.

     Written by: Mike J. Brown <[email protected]>
     License: none; use and distribute freely.

     Version 1.0 - 05 Jan 2000: First public version. XSLT 1.0 conformant=
.
    =20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-->

<!-- beginning of the stylesheet -->
<xsl:stylesheet    xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"=20
version=3D"1.0">

<!-- desired output method -->
<xsl:output method=3D"xml" version=3D"1.0" indent=3D"no"/>

<!-- source document whitespace handling -->
<xsl:strip-space elements=3D"*"/>
<xsl:preserve-space elements=3D"xsl:text"/>

<!--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-->
<!-- when processing root, element, attribute, or processing-instruction=20
node -->
<xsl:template match=3D"/|*|@*|processing-instruction()">
<!-- create a copy of the current node in the result tree -->
<xsl:copy>
<!-- its attributes and children will be the result of the following=20
instruction -->
<!-- go process attributes and any non-comment children of current node -=
->
<xsl:apply-templates select=3D"@*|node()[not(self::comment())]"/>
</xsl:copy>
</xsl:template>

<!-- end of the stylesheet -->
</xsl:stylesheet>


--=20
Klaus Johannes Rusch
[email protected]
http://www.atmedia.net/KlausRusch/


--------------090709010604080507020707
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 text="#000000" bgcolor="#ffffff">
    On 27.08.2011 12:14, J&eacute;r&ocirc;me DESPATIS wrote:
    <blockquote cite="mid:[email protected]" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      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 moz-do-not-send="true"
        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>
    </blockquote>
    A simple XSLT stylesheet should work for post-processing, e.g.<br>
    <br>
    &lt;?xml version="1.0" encoding="utf-8"?&gt;<br>
    <br>
&lt;!--=======================================================================<br>
    &nbsp;&nbsp;&nbsp; Condense.xsl<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; Removes comments and extraneous whitespace from a source file.<br>
    &nbsp;&nbsp;&nbsp; Good for optimizing an XSL document. Only pitfalls are that it
    might<br>
    &nbsp;&nbsp;&nbsp; rearrange attributes, depending on the processor implementation.<br>
    &nbsp;&nbsp;&nbsp; (I haven't actually seen that happen, though), and it will
    definitely<br>
    &nbsp;&nbsp;&nbsp; not copy DTD information or entity references into the new tree.<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; Written by: Mike J. Brown <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a><br>
    &nbsp;&nbsp;&nbsp; License: none; use and distribute freely.<br>
    <br>
    &nbsp;&nbsp;&nbsp; Version 1.0 - 05 Jan 2000: First public version. XSLT 1.0
    conformant.<br>
    &nbsp;&nbsp;&nbsp;
=======================================================================--&gt;<br>
    <br>
    &lt;!-- beginning of the stylesheet --&gt;<br>
    &lt;xsl:stylesheet&nbsp;&nbsp;&nbsp;
    xmlns:xsl=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/1999/XSL/Transform">"http://www.w3.org/1999/XSL/Transform"</a> version="1.0"&gt;<br>
    <br>
    &nbsp;&nbsp;&nbsp; &lt;!-- desired output method --&gt;<br>
    &nbsp;&nbsp;&nbsp; &lt;xsl:output method="xml" version="1.0" indent="no"/&gt;<br>
    <br>
    &nbsp;&nbsp;&nbsp; &lt;!-- source document whitespace handling --&gt;<br>
    &nbsp;&nbsp;&nbsp; &lt;xsl:strip-space elements="*"/&gt;<br>
    &nbsp;&nbsp;&nbsp; &lt;xsl:preserve-space elements="xsl:text"/&gt;<br>
    <br>
&lt;!--=======================================================================--&gt;<br>
    &nbsp;&nbsp;&nbsp; &lt;!-- when processing root, element, attribute, or
    processing-instruction node --&gt;<br>
    &nbsp;&nbsp;&nbsp; &lt;xsl:template match="/|*|@*|processing-instruction()"&gt;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;!-- create a copy of the current node in the result tree
    --&gt;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;!-- its attributes and children will be the result
    of the following instruction --&gt;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;!-- go process attributes and any non-comment
    children of current node --&gt;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates
    select="@*|node()[not(self::comment())]"/&gt;<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;<br>
    &nbsp;&nbsp;&nbsp; &lt;/xsl:template&gt;<br>
    <br>
    &lt;!-- end of the stylesheet --&gt;<br>
    &lt;/xsl:stylesheet&gt;<br>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Klaus Johannes Rusch
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.atmedia.net/KlausRusch/">http://www.atmedia.net/KlausRusch/</a></pre>
  </body>
</html>

--------------090709010604080507020707--


--===============3920518086667481884==
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
--===============3920518086667481884==
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

--===============3920518086667481884==--