Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Indenting XML

by uzzikie (Sexton)
on Feb 21, 2003 at 06:07 UTC ( [id://237361]=note: print w/replies, xml ) Need Help??


in reply to Indenting XML

thanks everyone for their input....
after trying a few solutions, i guess I shall adopt the below approach....
use XML::Parser::PerlSAX; use XML::Handler::YAWriter; my $xmlquery = qq(<AIRAVAALABILTY> <AIRAVL> <AIRAVL012U>01MAY</AIRAVL0 +12U> <AIRAVL0145>SIN</AIRAVL0145> <AIRAVL018B>HKG</AIRAVL018B> <AIRAV +L007V>Y</AIRAVL007V> <AIRAVL012G></AIRAVL012G> </AIRAVL> </AIRAVAALAB +ILTY>); my $ya = new XML::Handler::YAWriter( 'Output' => new IO::File ( ">-" ), 'Pretty' => { 'NoComments'=>1, 'PrettyWhiteIndent'=>1, 'NoWhiteSpace'=>1, 'PrettyWhiteNewline'=>1, } ); my $perlsax = new XML::Parser::PerlSAX( 'Handler' => $ya); my $result = $perlsax->parse(Source => { Encoding => 'ISO-8859-1', Str +ing => "$xmlquery" }); print qq($result);
which in turn prints out
<AIRAVAALABILTY> <AIRAVL> <AIRAVL012U>01MAY </AIRAVL012U> <AIRAVL0145>SIN </AIRAVL0145> <AIRAVL018B>HKG </AIRAVL018B> <AIRAVL007V>Y </AIRAVL007V> <AIRAVL012G> </AIRAVL012G> </AIRAVL> </AIRAVAALABILTY>

Replies are listed 'Best First'.
Re: Re: Indenting XML
by extremely (Priest) on Feb 21, 2003 at 06:40 UTC
    Some XML apps will be seriously annoyed by your adding whitespace within the leaf level tags. Just a thought but I'd test that carefully before you transform it for more than just debugging by eye.

    --
    $you = new YOU;
    honk() if $you->love(perl)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://237361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-28 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found