Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

XML Pretty Formatter

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I'm looking for a simple XML pretty formatter, or parser who can remove all superfluous characters from XML files.

My application receives an XML file from an external app. containing many spaces and CRLFs after closing tags, this doesn't affect my parser, but I need to add the XML to a log file and those spaces make very difficult to read the logs.

Thanks in advance.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Graeme Geldenhuys
to Leonardo M. Ramé
Leonardo M. Ramé wrote
Hi, I'm looking for a simple XML pretty formatter, or parser who can remove all superfluous characters from XML files.

I have created just the thing for you. :-)
I created to XSL files that cleans up XML files. I used it for the FPDoc xml which when created by makeskel is really ugly. ;-)

usage is as follows:

   $ xsltproc -o new.xml pretty_print.xsl ugly.xml

Hope that's useful.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Seth Grover

I don't know what your requirements are for platform/language, but this works nicely for me:

------------------------------
#!/usr/bin/perl

use XML::Tidy;
my $xmlFile = '/path/to/filename';
my $tidy_obj = XML::Tidy->new('filename' => $xmlFile);
$tidy_obj->tidy();
$tidy_obj->write();
------------------------------
Show quoted text 8 lines
Hi, I'm looking for a simple XML pretty formatter, or parser who can remove all superfluous characters from XML files. My application receives an XML file from an external app. containing many spaces and CRLFs after closing tags, this doesn't affect my parser, but I need to add the XML to a log file and those spaces make very difficult to read the logs. Thanks in advance. Leonardo M. Ramé
This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com

Reply by email

Leonardo M. Ramé

Thanks Seth and Graeme, the problem is the program must run on a remote server that hasn't installed Tidy.pm, but fortunately it has xsltproc, so I'll try Graeme's solution.

BTW, is there any Pascal source code out there to do this?.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Seth Grover wrote 46 lines
From: Seth Grover Subject: [fpc-pascal] Re: XML pretty formatter To: Date: Thursday, May 14, 2009, 2:06 PM I don't know what your requirements are for platform/language, but this works nicely for me: ------------------------------ #!/usr/bin/perl use XML::Tidy; my $xmlFile = '/path/to/filename'; my $tidy_obj = XML::Tidy->new('filename' => $xmlFile); $tidy_obj->tidy(); $tidy_obj->write(); ------------------------------ > > Hi, I'm looking for a simple XML pretty formatter, or parser who can remove all superfluous characters from XML files. > > My application receives an XML file from an external app. containing many spaces and CRLFs after closing tags, this doesn't affect my parser, but I need to add the XML to a log file and those spaces make very difficult to read the logs. > > Thanks in advance. > > Leonardo M. Ramé -- This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com _______________________________________________ fpc-pascal maillist  -  http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Leonardo M. Ramé

Thanks Graeme!, pretty_print.xsl solved the issue.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Graeme Geldenhuys wrote 39 lines
From: Graeme Geldenhuys Subject: Re: [fpc-pascal] XML Pretty Formatter To: "FPC-Pascal users discussions" Date: Thursday, May 14, 2009, 12:05 PM On Thu, May 14, 2009 at 1:57 PM, Leonardo M. Ramé wrote: > > Hi, I'm looking for a simple XML pretty formatter, or parser who can remove > all superfluous characters from XML files. I have created just the thing for you. :-) I created to XSL files that cleans up XML files. I used it for the FPDoc xml which when created by makeskel is really ugly. ;-) usage is as follows:    $ xsltproc -o new.xml pretty_print.xsl ugly.xml Hope that's useful. Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ -----Inline Attachment Follows----- _______________________________________________ fpc-pascal maillist  -  http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 6 lines
On Thu, May 14, 2009 at 8:15 PM, Leonardo M. Ramé wrote: > > BTW, is there any Pascal source code out there to do this?. I'm sure you can convert the .xsl file to pascal source, but that might just be more effort than it's worth.

I think he meant a pascal version of the xsltproc program.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
I think he meant a pascal version of the xsltproc program.

Oh, my mistake.. xsltproc is just a frontend for the libxslt library. So you should be able to write a object pascal program that talks to the libxslt library directly (like is done for many other libraries - just convert the header files). Or do you want a object pascal version of the library as well? That would be even more work. :-(

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 10 lines
On Fri, May 15, 2009 at 8:43 AM, Michael Van Canneyt wrote: > > I think he meant a pascal version of the xsltproc program. Oh, my mistake.. xsltproc is just a frontend for the libxslt library. So you should be able to write a object pascal program that talks to the libxslt library directly (like is done for many other libraries - just convert the header files). Or do you want a object pascal version of the library as well? That would be even more work. :-(

IMHO we should have the latter. We have a near-complete DOM implementation in native object pascal, we have XPath in native pascal. It seems only natural to have XSLT native as well...

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt

On Fri, May 15, 2009 at 11:01 AM, Michael Van Canneyt >

IMHO we should have the latter. We have a near-complete DOM implementation in native object pascal, we have XPath in native pascal. It seems only natural to have XSLT native as well...

That would be nice obviously, but it's not something I think can be done quickly. A project for a rainy day (oh boy, I'm screwed - it's winter here). :-)

I'll make a note in my todo list, but realistically I will not be able to touch it for the next 12 months. My clones are on strike!

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Leonardo M. Ramé

People, my problem was solved with the help of xsltproc in a Linux box where one our services is running, and it works really good.

But it could be nice to have an Object Pascal version of the library, to be able to do the same without needing to use an external program.

Leonardo M. Ramé
http://leonardorame.blogspot.com

Graeme Geldenhuys wrote 34 lines
From: Graeme Geldenhuys Subject: Re: [fpc-pascal] Re: XML pretty formatter To: "FPC-Pascal users discussions" Date: Friday, May 15, 2009, 6:09 AM On Fri, May 15, 2009 at 11:01 AM, Michael Van Canneyt > > IMHO we should have the latter. We have a near-complete DOM implementation > in native object pascal, we have XPath in native pascal. It seems only natural > to have XSLT native as well... That would be nice obviously, but it's not something I think can be done quickly. A project for a rainy day (oh boy, I'm screwed - it's winter here).  :-) I'll make a note in my todo list, but realistically I will not be able to touch it for the next 12 months. My clones are on strike! Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist  -  http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email