Re: Minify an xml into one line
Ger Hobbelt <[email protected]> Sat, 27 Aug 2011 11:49:26 +0200
| Newsgroups | gmane.comp.web.html-tidy.devel |
|---|---|
| Message-ID | <CAFP60fpdauXHdpSVcaC647xqMR4D_uusnd97ibL-GAXg-Q-CrQ@mail.gmail.com> |
--===============4833107053611903477== Content-Type: multipart/alternative; boundary=90e6ba212339d98d9304ab7993c5 --90e6ba212339d98d9304ab7993c5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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=3DNL (or TidyNewline=3DCR iff you know the cdata = will never carry lone CR's so you can safely postprocess by removing all CRs, bu= t 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 th= e 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=E9r=F4me DESPATIS <[email protected]>= wrote: > Hello, > > I've had no answer from [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, t= he > <?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 =3D array('input-xml' =3D> true, > 'output-xml' =3D> true, > 'indent' =3D> false, > 'wrap' =3D> 0); > > A minimalistic xml could be: > ----------------------------------- > <?xml version=3D"1.0" encoding=3D"utf-8" standalone=3D"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=3D"1.0" encoding=3D"utf-8" standalone=3D"yes"?> > <feed><title>Title</title><id>geofeed-contacts</id><entry><title>Title</t= itle></entry></feed> > > > Any idea is welcome > > Thanks! > > -- > J=E9r=F4me [email protected] > > --=20 Met vriendelijke groeten / Best regards, Ger Hobbelt -------------------------------------------------- web: http://www.hobbelt.com/ http://www.hebbut.net/ mail: [email protected] mobile: +31-6-11 120 978 -------------------------------------------------- --90e6ba212339d98d9304ab7993c5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div>Hm, not exactly a task I'd imagine to apply tidy to (though I do u= se it to 'pretty format' (X)HTML. </div><div>AFAICT, your tidy conf= ig 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= 9; option, so you might want to try & add the TidyNewline=3DNL (or Tidy= Newline=3DCR iff you know the cdata will never carry lone CR's so you c= an 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 real= ity).</div> <div><br></div><div><br></div><div>Two roads from there:</div><div><br></di= v><div>1) either tweak the tidy code to allow for even more compact form (w= hich would give tidy more complete 'minifier' abilities by having i= t 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. jsm= in) did you check the net for availability of (X)HTML minifier tools? Becau= se 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, i= n 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= =3D"gmail_quote">On Sat, Aug 27, 2011 at 10:41 AM, J=E9r=F4me DESPATIS <spa= n dir=3D"ltr"><<a href=3D"mailto:[email protected]">[email protected]= m</a>></span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex;"> =20 =20 =20 <div bgcolor=3D"#ffffff" text=3D"#000000"> <div style=3D"font-family:-moz-fixed;font-size:12px" lang=3D"x-western"= >Hello,<br> <br> I've had no answer from <a href=3D"mailto:[email protected]" targe= t=3D"_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 <?xml...> 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 th= e \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 =3D array('input-xml'=A0 =3D> true, <br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'output-xml' = =3D> true, <br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'indent'=A0=A0= =A0=A0 =3D> false, <br> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'wrap'=A0=A0=A0= =A0=A0=A0 =3D> 0); <br> <br> A minimalistic xml could be: <br> ----------------------------------- <br> <?xml version=3D"1.0" encoding=3D"utf-8" stand= alone=3D"yes"?> <br> <feed> <br> <title>Title</title> <br> <id>geofeed-contacts</id> <br> <entry> <br> <title>Title</title> <br> </entry> <br> </feed> <br> <br> What I would like to have is the 2 lines (or even 1 line): <br> ---------------------------------------------------------------------- <br> <?xml version=3D"1.0" encoding=3D"utf-8" stand= alone=3D"yes"?> <br> <feed><title>Title</title><id>geofeed-contacts</= id><entry><title>Title</title></entry></feed&= gt; <br> <br> Any idea is welcome <br> <br> Thanks! <br> <br> </div><font color=3D"#888888"> <pre cols=3D"72">--=20 J=E9r=F4me Despatis <a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]= m</a> </pre> </font></div> </blockquote></div><br><br clear=3D"all"><br>-- <br>Met vriendelijke groete= n / Best regards,<br><br>Ger Hobbelt<br><br>-------------------------------= -------------------<br>web:=A0 =A0 <a href=3D"http://www.hobbelt.com/">http= ://www.hobbelt.com/</a><br> =A0 =A0 =A0 =A0 <a href=3D"http://www.hebbut.net/">http://www.hebbut.net/</= a><br>mail:=A0=A0 <a href=3D"mailto:[email protected]">[email protected]</a><br= >mobile: +31-6-11 120 978<br>----------------------------------------------= ----<br><br> --90e6ba212339d98d9304ab7993c5-- --===============4833107053611903477== 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 --===============4833107053611903477== 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 --===============4833107053611903477==--