Finding best way to pretty print XML files

Havn't found best soultion to pretty print XML:

REXML: It has pp functionality, but it wrap elements like <a>content</a>
to
<a>
content
</a>

Nokogiri: there is a approch to pp, see ex:

# Pretty print XML
require "nokogiri"

def write(buffer)

  xsl =<<XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<xsl:strip-space elements="*"/>
<xsl:template match="/">
  <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>
XSL

    doc = Nokogiri::XML(buffer)
    xslt = Nokogiri::XSLT(xsl)
    out =  xslt.transform(doc)
    out.to_xml
end

But nokogiri has another problem, which unwrap CDATA.

Any better solution? Thanks. And apologize for my poor english.

-- 
Posted via http://www.ruby-forum.com/.

0
Pk
1/11/2011 7:35:56 AM
comp.lang.ruby 48887 articles. 0 followers. Post Follow

3 Replies
535 Views

Similar Articles

[PageSpeed] 12
0 resp.  ToT

-- 
Posted via http://www.ruby-forum.com/.

0
Pk
1/12/2011 12:53:30 AM
Sorry if you haven't got any help,

could you provide more informations to the output you want ?

There are many ways to indent XML code. Maybe you don't want to wrap lines
with <a>content</a>, but what if the content is longer ? Do you have a
column limit ?

In your place, I would take the pp code of nokogiri and tweak it until it
gives me what I want.

Hope that help,
   zimbatm




2011/1/12 Pk Z. <k@z-pk.com>:
> 0 resp. =C2=A0ToT
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

0
Jonas
1/12/2011 11:18:50 PM
[Note:  parts of this message were removed to make it a legal post.]

In my experience, everyone has a different definition of "pretty printing".
If you want to get more specific about what you'd like to see, perhaps
people can give you a more specific answer.

On Tue, Jan 11, 2011 at 7:53 PM, Pk Z. <k@z-pk.com> wrote:

> 0 resp.  ToT
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

0
Mike
1/13/2011 12:05:12 AM
Reply:
Similar Artilces:

Find and Grep together
Hi All, I am sorry if this is not the right group for this question. I am using find and grep together to find a string in a file from the top level directories. find . -name "*.c" -exec grep "string" {} \; -print | more. | \/ top level directorie I am sure that the string I am searching is in the lower directories where I am searching but this command is unable to find the string which I am looking. Can anyone please help me. My version control tool is clear case and my config spec also supports all the files....

Compiling fortran lib with mex file
Hi, I am trying to compile a library written in fortran90 with mexfile. The library comes along with a short makefile which looks like as follow fortran=/usr/bin/gfortran-4.4 -fexceptions -fbackslash -I/matlab/extern/include -I/matlab/simulink/include gcc-4.4 -dynamiclib -o libie2mv2.dylib ie2mcom.o ie2mmex.o 2dmlbib.o -L/usr/lib/gcc/x86_64-linux-gnu/4.4/ -lgfortran -L/home/andrea/matlab/bin/glnxa64 -lmx -lmex -lmat ie2mcom.o : ie2mcom.f90 $(fortran) -c -fpic ie2mcom.f90 ie2mmex.o : ie2mcom.o ie2mmex.f90 $(fortran) -c -fpic ie2mmex.f90 2dmlbib.o : 2dmlbib.f90 ...

How to find out the current version of the MySQL installation ?
How to find out (from the command line under Linux) the current version of the MySQL installation ? Or is there a config file which contains the version number ? Werner Werner Sammer <wersam@yahoo.de> wrote: > How to find out (from the command line under Linux) > the current version of the MySQL installation ? > Or is there a config file which contains the version number ? > Werner Command line: mysql --version Regards, Johan -- _____________________________________ Ing. Johan van Oostrum chaos geordend - www.chaosgeordend.nl _____________________________________ >...

PDF File -- Security lock
I was looking at a PDF file that was just a companies reproduction of a product label -- a herbcide, for what its worth. These labels are mostly long strings of boilerplate language with safety precautions for use, etc. that can go on for pages upon pages and are pretty much the same for each herbcide. There are usually then one or two pages that deal specifically with the herbicide itself. So, rather than print off all the pages, I went to copy and paste the relevant page and found that while I was allowed to print the relevant document, copy function was disabled. There was a little gold...

Canon MP 730 (Help Removing Print head)
Hi - I think my yellow ink jet is clogged, and I'd like to try unclogging it. I need help removing the printhead. I recall that when I installed it, it snapped into place. I' can't seem to find any latches or other devices to reverse the process. Any help would be greatly appreciated. ...

finding max
Hello all I have a matrix a = 1 2 3 4 5 6 7 8 9 10 11 12 now I call max(a) ans = 9 10 11 12 to find the max, I have to call max(max(a)) Is there any way I can get the max of a matrix in one command? Thanks sore wrote: > > Hello all > > I have a matrix > > a = > > 1 2 3 4 > 5 6 7 8 > 9 10 11 12 > > now I call > > max(a) > > ans = > > 9 10 11 12 > > to find the max, I have to call max(max(a)) > > Is there any way I can get the max of a matrix > in one command? >...

printing to word document
Hello all. I am writing some stuff out to a word document using standard printing commands (fprintf) to a file ___.doc. When I open the file in Word, it asks me for the encoding to use. Is there anyway that when I use fopen I can specify the encoding so that microsoft word doesn't prompt me for which encoding to use every time I write a new file? I need nothing fancy, just plain text to open in a word file. Thanks alot for any suggestions. I could change it to a ..txt file and open it with notepad but I was hoping that i could pull it off in word. Chris "Chris " <chrisne...

Narrowed down bottlneck to disk, how can I find out which FS is being hammered? 100% utilization
In my process of drilling down to get to the bottom of our performance issues, I am seeing huge I/O wait on a particular disk. What tools are available to dig deeper, find out which file system is hammering the disk and/or which processes are hogging the CPUS? We are talking 100% utilization here: mpstat output: CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 199 0 259 12 2 176 9 22 30 0 1882 11 6 83 0 1 205 0 259 204 194 176 8 23 34 0 1801 11 5 84 0 2 203 0 289 34 23 176 7 23 31 ...

Re: Invisible retain statement when appending files with set stat ement?
z- I think this is what you want: data bothfiles; set onecol (in=in1) twocols (in=in2); if in1 then do; m = 9; col1=9; end; Paul Choate DDS Data Extraction (916) 654-2160 -----Original Message----- From: z [mailto:gzuckier@YAHOO.COM] Sent: Wednesday, October 01, 2003 12:33 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Invisible retain statement when appending files with set statement? Can anyone explain the behavior of the following code? /*make a couple of datasets*/ /*first has one variable, 3 records*/ data onecol; m=0; output; output; output; /*second has two variables, 1 record*/...

XP iSeries NetServer IFS Problem with Copy Files
Hello, I am having here a strange problem. I have installed several PCs with Windows XP Professional. To connect the AS400 IFS (NetServer) I also installed the Windows Client. I can login to the iSeries IFS and browse the directories. I can also copy small Files (600 KB) into the IFS. When trying to copy larger Files ( > 1 MB) I got a message "Cannot copy File xyz: The request is not supproted" When doing the same thing on a Windows 2000 PC with the same user it works. I have searched the IBM Sites but found only a hint regarding a Win XP Session Timeout parameter, but it had ...

Find it all
Find it all http://asb-comm-logicx.net/ ...

Complicated Find Expression
Hi, I am having problems with my find expression. Basically I want to find to find all files that are _not_ in a test directory and then execute a grep statement on them. The result of that grep statement is further refined by another grep. Finally I would like to echo the result. My grep expression on works fine by itself. The problem is with the find integration. Here is my expression, followed by the output. Thanks for any suggestions/pointers, Mike find ./ -path '*test*' -prune -o -print -exec "grep -PRi 'out.print.*?[^/][^/].*?the' {} | grep -Pi 'out...

best way to perform multiplies in vhdl
i am trying to implement an image convolution filter that has negative values in it on a spartan IIe fpga. So i need to perform (for instance) A*B + C*D where A,B,C,D are all signed numbers in the ieee std logic int range. what is the best way to implement this? It seems that the way i am doing it now (using std_logic_vector) fails for negative values of the filter coeffs. can anyone give a suggestion how to fix this (the best way to code it in vhdl). What is the best way to do a numerical comparison (ie. A < B in vhdl (that is also synthesizeable), where A,B are signed integers) t...

[ace-users] Can't find ACEd.dll
This is a multi-part message in MIME format. ------_=_NextPart_001_01C7A8F9.1452B078 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi=20 =20 ACE VERSION: 5.5.8 =20 HOST MACHINE and OPERATING SYSTEM: Win XP=20 If on Windows based OS's, which version of WINSOCK do you use?: don't know =20 TARGET MACHINE and OPERATING SYSTEM, if different from HOST: COMPILER NAME AND VERSION (AND PATCHLEVEL): =20 THE $ACE_ROOT/ace/config.h FILE [if you use a link to a platform- specific f...

ow-find without sun 'find' key
I've just moved over to a windows platform from solaris and have installed the windows version of xemacs 21.4. I'm having severe withdrawal symptoms from the loss of the sun 'find' key. So to correct this I would like to bind the M-s key combo to the ow-find function and M-S-s to the ow-find-backward function. I have 2 problems trying to achieve this. 1. I have sucessfully bound the M-s keys to the 'ow-find function using the following code in the init.el file. (define-key global-map [(meta ?s)] 'ow-find) However when I execute the function it returns the follo...

Literal text in .bib files
Hi all, I an referencing a URL in one of my papers, so I have the following entry in my bibtex file @UNPUBLISHED(Watton:1997:CCF, author = "John D. Watton", title = "Comparing C, Fortran, LISP, Java, blah blah", note = "http://openmap.bbn.com/\~kanderso/in-poly.ps", month = "May", year = "1997" ) The problem that I run into is that the bibliography in the generated PDF file is missing the tilde (~) character in the noted URL. I get no errors or warnings from bibtex or pdflatex. Is there some other way to force a literal character for b...

The best way to bin data to a grid? (may not be an IDL-specific question)
Hi all, I have some satellite data I'd like to bin to a high-resolution 2D grid for plotting and/or other analytical purposes. Each data point that I have has a corresponding latitude and longitude of the centre of the original pixel that the data was originally recorded from. The grid I'm trying to assign this data to is of a much finer resolution than what the data was taken from, so several data points may be assigned to the same pixel, in which case I guess an average data value will need to be assigned instead. To further complicate matters, the data I want to bin is a global dat...

Latest XML Parsing/Memory benchmark
The latest benchmark results are now available using the latest Intel Core2 Duo processor. In summary, VTD-XML using JDK 1.6's server JVM achieved an astonishing 120MB/sec sustained throughput per core on a Core2 Duo 2.5 GHz processor. * Parsing Only: http://www.ximpleware.com/2.3/benchmark_2.3_parsing_only.html * XPath Only: http://www.ximpleware.com/2.3/benchmark_2.3_xpath.html * Parsing/XPath/Update: http://www.ximpleware.com/2.3/benchmark_2.3_update.html * Indexing/XPath/Update: http://www.ximpleware.com/2.3/benchmark_2.3_indexing.html ...

PC Gamers 25 Best Adventure Games list
worth a look! http://www.pcgamer.com/the-25-best-adventure-games/ rms On Saturday, October 25, 2014 9:35:54 PM UTC-7, rms wrote: > worth a look! http://www.pcgamer.com/the-25-best-adventure-games/ > > rms I've played all but 4. You? :) ...

Printing xlated output of Filter::Simple ?
Can't find anything obvious, hope someone here can help... I'm writing a Filter::Simple module for embedded SQL (SQL::Preproc), and would like to dump out the xlated source outside of the debugger (ala a preprocessor). The only reference I can find to such a feature is Acme::Pythonic's debug flag. Do I have to implement my own emitter, or is there some perl or Filter::Simple switch I'm overlooking ? TIA, Dean Arnold Presicient Corp. Dean Arnold <dean.arnold@sbcglobal.net> wrote in message news:<Yirld.8564$zx1.3640@newssvr13.news.prodigy.com>... > I'm wri...

Find File Attributes
Hello, As a part of my application,I need to compare files generated everyday.I need not need to compare the file contents.I just need to compare the file size,the line count.The files are named in the format,Hyyyymmdd,H denoting History. At present,I use the Dir function to search for the physical existence of the file and I use the debug.print for functions such as filelen(path),GetAttr() etc. My question is how would I put this as a module so that I can use a date function to compare files generated today with that of yesterday (mondays files to be compared against fridays). Also is it pos...

Re: Best books for intro into SAS
This has been discussed here, and you can search the archives. If you want current opinion, you have to let us know what you want to do using SAS. It's a big program, that does lots of different stuff. Me, I mostly use it to do some simple data manipulation and a lot of statistics. But if you look at the postings here for a day or two, you will see that that is not representative Peter >>> John Halpin <john_halpin@BLUEYONDER.CO.UK> 5/21/2004 8:16:16 AM >>> Hi , I not a SAS guru (but would like to be!). Can anyone recommend a really good book (or white paper ...

ZX80 files > WAV
Just a heads up. There are now two or more utilities for those who want to try converting .O (ZX80) files to WAV. Details here: http://www.rwapservices.co.uk/ZX80_ZX81/forums/viewtopic.php?f=6&t=425 ...

I need to find the rows that exist in one table but not in the other with condition
I need to find the rows that exist in one table but not in the other with this condition: (prod_name exist in table1 and not in table2.prod_name ) AND (prod_name exist in table1 and not in table2.'S'+prod_name ) explanation: i want to know if the product not exit and if the combination of the charachter "S" with the product Name also not exist at the other table B.R yuvi SELECT prod_name FROM table1 as A WHERE NOT EXISTS (select * from table2 as B where A.prod_name = B.prod_name) AND NOT EXISTS (select * from table2 as C where A....

find breakpoint programmatically
Hi All, &nbsp; I accidentally posted this question in the special interest forum by mistake so sorry for the duplicate post but i thought it might never get read over there. <a href="http://forums.ni.com/ni/board/message?board.id=BreakPoint&amp;message.id=4162" target="_blank">http://forums.ni.com/ni/board/message?board.id=BreakPoint&amp;message.id=4162</a> &nbsp; Hi all, &nbsp; I was wondering if there is a way to search the vi hierachy for breakpoints programmatically?&nbsp; Why you may ask? &nbsp; I have a piece of code that take...