XML beautify using perl XML::Writer

There are code that we generate somehow having the whole data
merged into just ONE long line.

And end-user complained can’t be processed.
Which is not so easy to read.

unless you did some magic before viewing as follows :

xmllint --format IDM26004.xml |more

which did reformatting it.. into a human readable tab/indent.

However, later I found out the fix for generating script is quite easy.
Just need to add the following item.

 
  my $writer = new XML::Writer (
    OUTPUT => \$xml, DATA_MODE => 1,DATA_INDENT => 2
  );

which is decribed here :

DATA_MODE
 
    A true or false value; if this parameter is present and its value is true, then the module will enter a special data mode, inserting newlines automatically around elements and (unless UNSAFE is also specified) reporting an error if any element has both characters and elements as content.
DATA_INDENT
 
    A numeric value or white space; if this parameter is present, it represents the indent step for elements in data mode (it will be ignored when not in data mode). If it is white space it will be repeated for each level of indentation.

so the full look like follows..

# =====================================================================
# gen_xml () 
# ---------------------------------------------------------------------
 
sub gen_xml {
 
  my ($next_time) = @_;
  my @nowtime = localtime (time());
 
  syslog ("info", "Generating Tide XML");
 
  my $xml;
 
  my $writer = new XML::Writer (
    OUTPUT => \$xml, DATA_MODE => 1,DATA_INDENT => 2
  );
  $writer->xmlDecl();
  $writer->startTag ("tides");
  $writer->emptyTag ("timezone",
    'name' => 'MST', value=>'8.0'
  );
 
..

so result would as :

[namran@nb-namran tmp]$ head IDM26004.xml 



  
  Saturday 22/01/11
  
    
      
      
      

References :

http://search.cpan.org/~josephw/XML-Writer-0.612/Writer.pm

Related Post

2 Responses

  1. HawkEYE says:

    the step to remove old plesk before can start install a new
    but it is preferable to have a complete system restore..
    *** somehow . to wait for sys-admin to do thing to you.. ah.. a lil’ bit fu*ked thing.. why not ***..

    as root..
    1. yum remove psa-*
    2. yum remove httpd
    3. rm -rf /var/httpd -R
    4. rm -rf /usr/local/psa -R
    5. rm -rf /var/www/vhosts -R
    6. service mysqld stop
    7. If don’t know the root pass for myql .try this as root :
    mysqld_safe –skip-grant-table

    6. mysql -uroot
    i. drop database psa
    ii. drop database phpmyadmin_14813SHFF <-- some serial here can see using show databases; iii. drop database horde; iv. drop database sitebuilder; v. and any other thing .. except test and mysql; vi. may have to reset pass for root to blank ... if u want to delete other user than root in mysql use mysql; delete * from user where User!='root'; update user set Password=PASSWORD('') where User='root'; may be need to add the admin user with pass setup. and with all priv here. insert into user (Host,User,Password) values ('localhost',admin,PASSWORD('something-default-here')); then have to grant.. all the privilege. to the admin then remove mysqld. yum remove mysql. ***.. after that may proceed with re-installation process. note i did'nt remove any other user created before.. such as qmail.. bla..bla.. because we are going to re-install .. then.. ./psa_installer_v3.1.2_build070321.17_os_CentOS_4_i386 answer all question.. wait.. till finished.. hopefully no problem.. may be need to flush the firewall services iptables restart.. then can access to https://server.name.com:8443/

    you should see the login screen..
    wahaha..

    Reply
  2. HawkEYE says:

    the step to remove old plesk before can start install a new
    but it is preferable to have a complete system restore..
    *** somehow . to wait for sys-admin to do thing to you.. ah.. a lil’ bit fu*ked thing.. why not ***..

    as root..
    1. yum remove psa-*
    2. yum remove httpd
    3. rm -rf /var/httpd -R
    4. rm -rf /usr/local/psa -R
    5. rm -rf /var/www/vhosts -R
    6. service mysqld stop
    7. If don’t know the root pass for myql .try this as root :
    mysqld_safe –skip-grant-table

    6. mysql -uroot
    i. drop database psa
    ii. drop database phpmyadmin_14813SHFF <-- some serial here can see using show databases; iii. drop database horde; iv. drop database sitebuilder; v. and any other thing .. except test and mysql; vi. may have to reset pass for root to blank ... if u want to delete other user than root in mysql use mysql; delete * from user where User!='root'; update user set Password=PASSWORD('') where User='root'; may be need to add the admin user with pass setup. and with all priv here. insert into user (Host,User,Password) values ('localhost',admin,PASSWORD('something-default-here')); then have to grant.. all the privilege. to the admin then remove mysqld. yum remove mysql. ***.. after that may proceed with re-installation process. note i did'nt remove any other user created before.. such as qmail.. bla..bla.. because we are going to re-install .. then.. ./psa_installer_v3.1.2_build070321.17_os_CentOS_4_i386 answer all question.. wait.. till finished.. hopefully no problem.. may be need to flush the firewall services iptables restart.. then can access to https://server.name.com:8443/

    you should see the login screen..
    wahaha..

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *