CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
How to get input xml file as XMLout. output.

 



babp
New User

Apr 6, 2010, 12:00 AM

Post #1 of 5 (2667 views)
How to get input xml file as XMLout. output. Can't Post

Hi ,
I am trying to get an reference of a XML formatted data using XML::Simple::XMLin

and again trying to retrive the XML data as it was before using XML::Simple::XMLout.

But finding a deviation in the format can any pls help me out.


Input file sr.xml
===========
<?xml version="1.0" encoding="ISO-8859-1" ?>
<scenario>
<counter>
<counterdef name="HbH-counter" init="1000"> </counterdef>
<counterdef name="EtE-counter" init="2000"> </counterdef>
<counterdef name="session-counter" init="10005"> </counterdef>
</counter>
</scenario>

perl code
=======
my $data='';
$file_to_parse='sr.xml';
my $xml = new XML::Simple;
my $config = eval { XML::Simple::XMLin("$file_to_parse") };
$data = $xml->XML::Simple::XMLin("$file_to_parse",keeproot => 1);
print $xml->XMLout($data,outputfile =>'/var/tmp/Call',keeproot => 1);

outputfile('/var/tmp/Call')
==================
<scenario>
<counter name="counterdef">
<EtE-counter init="2000" />
<HbH-counter init="1000" />
<session-counter init="10005" />
</counter>
</scenario>



My expectation was as it was before :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<scenario>
<counter>
<counterdef name="HbH-counter" init="1000"> </counterdef>
<counterdef name="EtE-counter" init="2000"> </counterdef>
<counterdef name="session-counter" init="10005"> </counterdef>
</counter>
</scenario>


MetalGear
Novice


Apr 6, 2010, 1:44 AM

Post #2 of 5 (2656 views)
Re: [babp] How to get input xml file as XMLout. output. [In reply to] Can't Post

after goin through XML smple documentation...i think u should replace

$data = $xml->XML::Simple::XMLin("$file_to_parse",keeproot => 1);

with

$data = $xml->XMLin("$file_to_parse",keeproot => 1);


babp
New User

Apr 6, 2010, 2:46 AM

Post #3 of 5 (2651 views)
Re: [MetalGear] How to get input xml file as XMLout. output. [In reply to] Can't Post

Even with this option also i am getting same result :

$data = $xml->XMLin("$file_to_parse",keeproot => 1);

<scenario>
<counter name="counterdef">
<EtE-counter init="2000" />
<HbH-counter init="1000" />
<session-counter init="10005" />
</counter>
</scenario>
~


But i need it to print like below:

<scenario>
<counter>
<counterdef name="HbH-counter" init="1000"> </counterdef>
<counterdef name="EtE-counter" init="2000"> </counterdef>
<counterdef name="session-counter" init="10005"> </counterdef>
</counter>
</scenario>


MetalGear
Novice


Apr 6, 2010, 4:09 AM

Post #4 of 5 (2646 views)
Re: [babp] How to get input xml file as XMLout. output. [In reply to] Can't Post

try


Code
  

$data = $xml->XMLin("$file_to_parse",forcearray => 1);





babp
New User

Apr 6, 2010, 9:30 PM

Post #5 of 5 (2600 views)
Re: [MetalGear] How to get input xml file as XMLout. output. [In reply to] Can't Post

Hi ,
Thanks for the reply ,it's working fine now.

But the same solution is not working for a large XML file (attched).

Can you please help me to get the solution.

my objective is to
1. parse this xml file with XMLIn.
2.Create a hash with Data Dumper
3.Then make some values dynamic in the hash.
4.Again convert the hash to same XML file format.

I am able to do first 3 steps but iam not getting the same XML file format as it was before(step 4).


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives