Re: How to create an xml file with XMLWriter that has 0A newlines in strings
Tod Harter <[email protected]> Wed, 3 Jun 2015 09:25:43 -0500
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <CAC0h5Yz5iTGhgARbzAK-FSM5cajfQhLK7Htm7cPkOd=QHVXw-A@mail.gmail.com> |
--===============0829860244== Content-Type: multipart/alternative; boundary=047d7bfd0b1287901805179dd5e4 --047d7bfd0b1287901805179dd5e4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable "The Unicode Standard neither requires nor recommends the use of the BOM for UTF-8, but does allow the character to be at the start of a file." I guess the answer is that BOM doesn't do anything for you in UTF-8, there's no byte-reversed version of the encoding as there is in say UTF-16. That being said its acceptable to have a BOM, and I'm assuming you have some software somewhere that requires one. 2 options. Add it on with some shell one-liner afterwards (I believe you can for instance use 'echo' on most unix boxes to output a few hex characters and just prepend that to your output after the fact). Beyond that the example you give probably should work, but maybe your binmode()/write() should come BEFORE you set up XML::Writer? I'm also not really sure the ':utf8' is a good idea there, you should probably not be telling it there's an encoding at all, let perl just write binary bytes to the file. I'm sure I'd have to experiment a bit to get it right, but you should be on the right track there. I just don't have time to work through it right now, sorry. *=E2=80=9CMen occasionally stumble over the truth, but most of them pick th= emselves up and hurry off as if nothing had happened.=E2=80=9D -*Winston Churchill On Wed, Jun 3, 2015 at 3:16 AM, Nagy Tamas (TVI-GmbH) < [email protected]> wrote: > Hi, > > > > Ok, but how to write the =E2=80=9EEF BB BF=E2=80=9C BOM code to the begi= nning? > > With XML::Writer the print OUTPUT chr(65279) does not do anything. > > > > my $output; > > my $writer; > > > > $output =3D IO::File->new(">default.xml"); > > > > $writer =3D XML::Writer->new(OUTPUT =3D> $output, DATA_MODE =3D> 1, DATA_= INDENT > =3D> " ", ENCODING =3D> "utf-8", NEWLINES =3D> 0 ); > > > > binmode(OUTPUT, ":utf8"); > > print OUTPUT chr(65279); #BOM > > > > Tamas Nagy > > > > > > > > *Von:* [email protected] [mailto:[email protected]] *Im Auftrag von *Tod > Harter > *Gesendet:* Dienstag, 2. Juni 2015 20:02 > *An:* Nagy Tamas (TVI-GmbH) > *Cc:* [email protected] > *Betreff:* Re: How to create an xml file with XMLWriter that has 0A > newlines in strings > > > > UTF-8 and the containing of OD 0A (CRLF) are two separate issues, as thes= e > characters exist as code points in UTF-8 (which is a superset of > US-ASCII/ISO-8860). So, handling the existence of CRLF is really your > business, you can pass ENCODING =3D> 'utf-8', NEWLINES =3D> 0 to > XML::Writer->new() to suppress any 'gratis' newlines, and tell the module > you want output to be utf-8 encoded. Beyond that the content is totally u= p > to you. I'd advise completely staying away from things like Notepad, it h= as > very little notion of how things are encoded or what sort of characters a= re > used, its really a terrible little program. If you STILL need to get rid = of > some characters after you output the data from perl, then perhaps a 'one > liner' that simply strips away the offending characters would be the best > idea. Alternately if you insist on using a text editor use something like > TextPad++ that allows you to control line endings and encoding properly. > > > *=E2=80=9CMen occasionally stumble over the truth, but most of them pi= ck > themselves up and hurry off as if nothing had happened.=E2=80=9D -*Winsto= n > Churchill > > > > On Tue, Jun 2, 2015 at 9:14 AM, Nagy Tamas (TVI-GmbH) < > [email protected]> wrote: > > Hi, > > > > I have to create a special binary format that uses XML. > > > > I create an XML file with XMLWriter. After that I use Notepad++ to conver= t > it to UTF-8 file. > > The problem is, that also 0D 0A is written into the strings by Notepad++. > > > > How to delete the 0D-s from the strings after conversion? Many hex editor= s > support > > only overwriting. Which hex editor can delete it? > > > > Or how to create UTF-8 XML files with XMLWriter so that strings never > contain 0D 0A, > > just 0A. > > > > It seems to be impossible with perl XMLWriter. > > > > Visual Studio has a special XML format when a plugin is used. In this XML > format > > 0D 0A is everywhere in the XML except the strings, where there is only 0A= . > > > > How is it possible to generate this file? > > > > Tamas Nagy > > > > > _______________________________________________ > Perl-XML mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > --047d7bfd0b1287901805179dd5e4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div><div>"The Unicode Standard neither requires nor = recommends the use of the BOM=20 for UTF-8, but does allow the character to be at the start of a file.<span>= </span>"<br><br></div>I guess the answer is that BOM doesn't do an= ything for you in UTF-8, there's no byte-reversed version of the encodi= ng as there is in say UTF-16. That being said its acceptable to have a BOM,= and I'm assuming you have some software somewhere that requires one. <= br><br></div>2 options. Add it on with some shell one-liner afterwards (I b= elieve you can for instance use 'echo' on most unix boxes to output= a few hex characters and just prepend that to your output after the fact).= Beyond that the example you give probably should work, but maybe your binm= ode()/write() should come BEFORE you set up XML::Writer? I'm also not r= eally sure the ':utf8' is a good idea there, you should probably no= t be telling it there's an encoding at all, let perl just write binary = bytes to the file. I'm sure I'd have to experiment a bit to get it = right, but you should be on the right track there. I just don't have ti= me to work through it right now, sorry. <br></div><div class=3D"gmail_extra= "><br clear=3D"all"><div><div class=3D"gmail_signature"><div dir=3D"ltr"><d= iv><div dir=3D"ltr"><em>=E2=80=9CMen occasionally stumble over the truth, b= ut most of them pick themselves up and hurry off as if nothing had happened= .=E2=80=9D -</em>Winston Churchill</div></div></div></div></div> <br><div class=3D"gmail_quote">On Wed, Jun 3, 2015 at 3:16 AM, Nagy Tamas (= TVI-GmbH) <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" t= arget=3D"_blank">[email protected]</a>></span> wrote:<br><blockquot= e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol= id;padding-left:1ex"> <div link=3D"blue" vlink=3D"purple" lang=3D"DE"> <div> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">Hi,<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">Ok, but how to write the =E2=80=9EEF = BB BF=E2=80=9C BOM code to=C2=A0 the beginning?<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">With XML::Writer the print OUTPUT chr= (65279) does not do anything.<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">my $output;<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">my $writer;<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">$output =3D IO::File->new("&g= t;default.xml");<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">$writer =3D XML::Writer->new(OUTPU= T =3D> $output, DATA_MODE =3D> 1, DATA_INDENT =3D> "=C2=A0 &q= uot;, ENCODING =3D> "utf-8", NEWLINES =3D> 0 );<u></u><u></= u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">binmode(OUTPUT, ":utf8");<u= ></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d">print OUTPUT chr(65279); #BOM<u></u><= u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:8.0pt;font-family:"Ver= dana",sans-serif;color:#1f497d">Tamas Nagy<u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:8.0pt;font-family:"Ver= dana",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:8.0pt;font-family:"Ver= dana",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca= libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><b><span style=3D"font-size:11.0pt;font-family:"= ;Calibri",sans-serif">Von:</span></b><span style=3D"font-size:11.0pt;f= ont-family:"Calibri",sans-serif"> <a href=3D"mailto:tharter@gmail= .com" target=3D"_blank">[email protected]</a> [mailto:<a href=3D"mailto:tha= [email protected]" target=3D"_blank">[email protected]</a>] <b>Im Auftrag von </b>Tod Harter<br> <b>Gesendet:</b> Dienstag, 2. Juni 2015 20:02<br> <b>An:</b> Nagy Tamas (TVI-GmbH)<br> <b>Cc:</b> <a href=3D"mailto:[email protected]" target=3D"_= blank">[email protected]</a><br> <b>Betreff:</b> Re: How to create an xml file with XMLWriter that has 0A ne= wlines in strings<u></u><u></u></span></p><div><div class=3D"h5"> <p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p> <div> <p class=3D"MsoNormal">UTF-8 and the containing of OD 0A (CRLF) are two sep= arate issues, as these characters exist as code points in UTF-8 (which is a= superset of US-ASCII/ISO-8860). So, handling the existence of CRLF is real= ly your business, you can pass ENCODING =3D> 'utf-8', NEWLINES =3D> 0 to XML::Writer->new() to su= ppress any 'gratis' newlines, and tell the module you want output t= o be utf-8 encoded. Beyond that the content is totally up to you. I'd a= dvise completely staying away from things like Notepad, it has very little notion of how things are encoded or what sort of characters are use= d, its really a terrible little program. If you STILL need to get rid of so= me characters after you output the data from perl, then perhaps a 'one = liner' that simply strips away the offending characters would be the best idea. Alternately if you insist on using a te= xt editor use something like TextPad++ that allows you to control line endi= ngs and encoding properly. <u></u><u></u></p> </div> <div> <p class=3D"MsoNormal"><br clear=3D"all"> <u></u><u></u></p> <div> <div> <div> <div> <div> <p class=3D"MsoNormal"><em>=E2=80=9CMen occasionally stumble over the truth= , but most of them pick themselves up and hurry off as if nothing had happe= ned.=E2=80=9D -</em>Winston Churchill<u></u><u></u></p> </div> </div> </div> </div> </div> <p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p> <div> <p class=3D"MsoNormal">On Tue, Jun 2, 2015 at 9:14 AM, Nagy Tamas (TVI-GmbH= ) <<a href=3D"mailto:[email protected]" target=3D"_blank">tamas.nag= [email protected]</a>> wrote:<u></u><u></u></p> <blockquote style=3D"border:none;border-left:solid #cccccc 1.0pt;padding:0c= m 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-= bottom:5.0pt"> <div> <div> <p class=3D"MsoNormal">Hi,<u></u><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">I have to create a special binary format that uses X= ML.<u></u><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">I create an XML file with XMLWriter. After that I us= e Notepad++ to convert it to UTF-8 file.<u></u><u></u></p> <p class=3D"MsoNormal">The problem is, that also 0D 0A is written into the = strings by Notepad++.<u></u><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">How to delete the 0D-s from the strings after conver= sion? Many hex editors support<u></u><u></u></p> <p class=3D"MsoNormal">only overwriting. Which hex editor can delete it?<u>= </u><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">Or how to create UTF-8 XML files with XMLWriter so t= hat strings never contain 0D 0A,<u></u><u></u></p> <p class=3D"MsoNormal">just 0A.<u></u><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">It seems to be impossible with perl XMLWriter.<u></u= ><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">Visual Studio has a special XML format when a plugin= is used. In this XML format<u></u><u></u></p> <p class=3D"MsoNormal">0D 0A is everywhere in the XML except the strings, w= here there is only 0A.<u></u><u></u></p> <p class=3D"MsoNormal">=C2=A0<u></u><u></u></p> <p class=3D"MsoNormal">How is it possible to generate this file?<u></u><u><= /u></p> <p class=3D"MsoNormal"><span style=3D"color:#888888">=C2=A0<u></u><u></u></= span></p> <p class=3D"MsoNormal"><span style=3D"font-size:8.0pt;font-family:"Ver= dana",sans-serif;color:#1f497d">Tamas Nagy</span><span style=3D"color:= #888888"><u></u><u></u></span></p> <p class=3D"MsoNormal"><span style=3D"color:#888888">=C2=A0<u></u><u></u></= span></p> </div> </div> <p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br> _______________________________________________<br> Perl-XML mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Perl= [email protected]</a><br> To unsubscribe: <a href=3D"http://listserv.ActiveState.com/mailman/mysubs" = target=3D"_blank"> http://listserv.ActiveState.com/mailman/mysubs</a><u></u><u></u></p> </blockquote> </div> <p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p> </div> </div></div></div> </div> </blockquote></div><br></div> --047d7bfd0b1287901805179dd5e4-- --===============0829860244== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs --===============0829860244==--