473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to get input xml file as XMLout. output.

10
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
===========
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2. <scenario>
  3. <counter>
  4.   <counterdef name="HbH-counter" init="1000"> </counterdef>
  5.   <counterdef name="EtE-counter" init="2000"> </counterdef>
  6.   <counterdef name="session-counter" init="10005"> </counterdef>
  7. </counter>
  8. </scenario>
perl code
=======
Expand|Select|Wrap|Line Numbers
  1.  my $data='';
  2.  $file_to_parse='sr.xml';
  3.  my $xml = new XML::Simple;
  4.  my $config = eval { XML::Simple::XMLin("$file_to_parse") };
  5.  $data = $xml->XML::Simple::XMLin("$file_to_parse",keeproot => 1);
  6.  print $xml->XMLout($data,outputfile =>'/var/tmp/Call',keeproot => 1);
  7.  
outputfile('/var/tmp/Call')
==================
Expand|Select|Wrap|Line Numbers
  1. <scenario>
  2.   <counter name="counterdef">
  3.     <EtE-counter init="2000" />
  4.     <HbH-counter init="1000" />
  5.     <session-counter init="10005" />
  6.   </counter>
  7. </scenario>


My expectation was as it was before :

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2. <scenario>
  3. <counter>
  4.   <counterdef name="HbH-counter" init="1000"> </counterdef>
  5.   <counterdef name="EtE-counter" init="2000"> </counterdef>
  6.   <counterdef name="session-counter" init="10005"> </counterdef>
  7. </counter>
  8. </scenario>
Apr 6 '10 #1
4 5482
toolic
70 Expert
I can not get XML::Simple to do what you want, but this is simple to do with XML::Twig:

http://search.cpan.org/~mirod/XML-Twig-3.35/

Expand|Select|Wrap|Line Numbers
  1. use strict; 
  2. use warnings; 
  3.  
  4. my $file_to_parse = <<EOF;
  5. <?xml version="1.0" encoding="ISO-8859-1" ?>
  6. <scenario>
  7. <counter>
  8. <counterdef name="HbH-counter" init="1000"> </counterdef>
  9. <counterdef name="EtE-counter" init="2000"> </counterdef>
  10. <counterdef name="session-counter" init="10005"> </counterdef>
  11. </counter>
  12. </scenario>
  13. EOF
  14.  
  15. use XML::Twig;
  16. my $t = XML::Twig->new(pretty_print => 'indented');
  17. $t->parse($file_to_parse);
  18. $t->print();
  19.  
  20. __END__
  21.  
  22. <?xml version="1.0" encoding="ISO-8859-1"?>
  23. <scenario>
  24.   <counter>
  25.     <counterdef init="1000" name="HbH-counter"> </counterdef>
  26.     <counterdef init="2000" name="EtE-counter"> </counterdef>
  27.     <counterdef init="10005" name="session-counter"> </counterdef>
  28.   </counter>
  29. </scenario>
Jun 5 '10 #2
babp
10
Thanks for the solution
Jun 29 '10 #3
babp
10
@toolic
I need a solution for below scenario .Is it possible to do the below one without using any Module.




Hi Iam new to perl and need a help to send inputs to an running application :



I am running an application XXXX , and when it starts i am passing a file name called "connect.spb" and after the application connects to the server i am sending filename "accept.spb" as a parameter.

BL31DL385:$ ./XXXX

This is XXXX (Reproducer by Order or RelaY)


XXXX> @connect.spb

XXXX>Opening connect.spb

Script> SET TCPIP /LOCAL_PORT=15331
Initialised TCP Listener on BL31DL385 (port: 15331)


>@accept.spb

XXXX> Opening accept.spb

So basically Input parameters are @connect.spb and @accept.spb.
After getting first string application will connect to the client ,
Then wait for the input and when accept parameter is given communication established succesfully.



MyQuestion##can we automate this using a script which will first run the application XXXX, and then pass the connect.spb and accept.spb as input.
Jun 29 '10 #4
Regarding your first problem re:How to get input xml file as XMLout. output.

Add the parameter "#KeyAttr=>[]," to your Simple::XMLin function call and you should get the same output as your input.

ie.
my $xml = new XML::Simple;
my $config = eval { XML::Simple::XMLi("$file_to_parse") };
$data = $xml->XML::Simple::XMLin("$file_to_parse", KeyAttr=>[], keeproot => 1);
print $xml->XMLout($data,keeproot => 1,XMLDecl => "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
Nov 3 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stefan Schmidt | last post by:
Hi@ll ! I have an application where the items of each XML value are placed in an array like this: my $result = transfer({ FIELD1 => 'value1', FIELD2 => 0, FIELD3 => "something other" ....
7
by: MM | last post by:
Hi there, How can I change my code (below) so that I use an "input argument" to specify the file name of the input file? For example, if I compile the code and that the application then gets the...
1
by: Aalok | last post by:
This is what i want to do. Read a text file as an input and based on that file, Create an outpu text file which saves the contents of the input file in a specifi format in the output file. I...
4
by: Carlo Marchesoni | last post by:
I really don't achieve to read a simple 'input.txt' with the following content: Jürg (Hex: 4a fc 72 67) to an identical 'output.txt' I do the following (and tried with tons of different...
5
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. ...
0
by: srikar | last post by:
Hi all, I am having a problem, when I am compiling the code in 32 bit option on a 64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from the linker . ...
3
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never...
116
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however,...
1
by: yohan610 | last post by:
i have to read the binary data of a file, then encrypt them according to a supplied algorithm...and then the obtained output has to be written to an output file...everything works ok, and there are...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.