How to parse XML and create a tree structure in Perl

我的未来我决定 提交于 2019-11-30 23:27:08

XML::LibXML creates a tree with no loss of information.

use XML::LibXML qw( );
my $parser = XML::LibXML->new();
my $tree = $parser->parse_file($qfn);

You can generate the output you specified from there. (I don't know why you'd want to, since the Perl code you want for output would lose data if run.)

I used XML::Parser for same file

#!/usr/sbin/perl
use  XML::Parser;
use Data::Dumper;
use strict;

my $Filename = "abc.xml";

my $Parser = new XML::Parser( Style => 'tree' );

my $Tree = $Parser->parsefile( $Filename );

print Dumper( $Tree );

If there is another way to get desired output please suggest.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!