Dear Perlers,

I am trying to print double quotes in the output (output.xml) but it is 
printing " instead of "". How can I include double quotes "" in the 
output. Please help.

Here is the code

[code]
#!/usr/bin/perl

use strict;
use warnings;

use XML::DOM;

my $parser = XML::DOM::Parser->new();
my $doc = $parser->parsefile("input.xml");

# create an XML::DOM::Document object
my $new_doc = XML::DOM::Document->new();
# create the root element of the document
my $root = $new_doc->createElement('testng-results');
my $suite = $new_doc->createElement('suite');
$suite->setAttribute("name","Suite1");
my $test = $new_doc->createElement('test');
$test->setAttribute("name", "EML_CLOG_TSS320_3_6");
my $class = $new_doc->createElement('class');
$class->setAttribute("name","1350OMS_9.6.5.0AD1_UX+IRP619UX.EML_CLOG_TSS320_3_6");

$root->appendChild($suite);
$suite->appendChild($test);
$test->appendChild($class);

my $count = 0;

foreach my $node ($doc->getElementsByTagName('log')) {
$count++; #Counter which indicates the record number
#Getting the value of attribute nodes
my $attribute_act = $node->getAttributeNode("act")->getValue();
#Filling the empty space with underscore
$attribute_act =~ tr/ /_/;
#Getting the value of elements
my $app = 
$node->getElementsByTagName('app')->item(0)->getFirstChild->getNodeValue;
my $subsys = 
$node->getElementsByTagName('subsys')->item(0)->getFirstChild->getNodeValue;
my $host = 
$node->getElementsByTagName('host')->item(0)->getFirstChild->getNodeValue;
my $operator = 
$node->getElementsByTagName('operator')->item(0)->getFirstChild->getNodeValue;
my $time = 
$node->getElementsByTagName('time')->item(0)->getFirstChild->getNodeValue;
$time =~ tr/ /_/;
my $status = 
$node->getElementsByTagName('status')->item(0)->getFirstChild->getNodeValue;
#my $userLabel = 
$node->getElementsByTagName('userLabel')->item(0)->getFirstChild->getNodeValue;
my $involved_object = 
$node->getElementsByTagName('involved_object')->item(0)->getFirstChild->getNodeValue;
#my $command = 
$node->getElementsByTagName('command')->item(0)->getFirstChild->getNodeValue;
my $client_host = 
$node->getElementsByTagName('client_host')->item(0)->getFirstChild->getNodeValue;
#Printing the information to screen
print '*' x 40, "\n";
print "app : $app\n";
print "act : $attribute_act\n";
print "subsys : $subsys\n";
print "host : $host\n";
print "operator : $operator\n";
print "time : $time\n";
print "status : $status\n";
#print "userLabel : $userLabel\n";
print "involved_object : $involved_object\n";
#print "command : $command\n";
print "client host : $client_host\n";
print '*' x 40, "\n";
#create a new test-method element
    my $test_method = $new_doc->createElement('test-method');
    if($status eq 'SUCCESS') {
    $test_method->setAttribute("status","PASS");
    } else {
    $test_method->setAttribute("status","FAIL");
    } 
    
    $test_method->setAttribute("signature","=$count)$involved_object" . "_" . 
"$attribute_act" . 
"(app=$app,subsys=$subsys,host=$host,operator=$operator,time=$time,status=$status,involved_object=$involved_object,client_host=$client_host);\n");
    $test_method->setAttribute("name","\"$count.$attribute_act\" 
duration-ms=\"0\" started-at=\"0\"");
    
$test_method->setAttribute("description","$attribute_act(log_act=$attribute_act,app=$app,subsys=$subsys,host=$host,operator=$operator,time=$time,status=$status,involved_object=$involved_object,client_host=$client_host);\"
 finished-at=\"0\">");
    $test->appendChild($test_method);    
}

$root->printToFile("output.xml");
[/code]

[input.xml]
<logger>

     <log act="NE Login">
     <app>ZIC</app>
     <seq>0</seq>
     <subsys>1850TSS320ZIC</subsys>
     <host>sindhu</host>
     <operator>CHANDRA</operator>
     <time>2013-11-19 16:17:44</time>
     <utc_time>2013-11-19 10:47:44</utc_time>
     <status>SUCCESS</status>
     <userLabel>TSS320-BA-04</userLabel>
     <involved_object>TSS320-BA-04</involved_object>
     <request_id>KWeCoZClHWuE7iJAnYGpEQ</request_id>
     <command>ACT-USER</command>
     <clog_private_db_insertion_flag>1</clog_private_db_insertion_flag>
     <client_host>135.244.1.157</client_host>
     <username>CHANDRA</username>
     <params>::CHANDRA:V25537::*********:HOSTIP=135-244-1-157</params>
     </log>

     <log act="AddCard">
     <app>ZIC</app>
     <seq>1</seq>
     <subsys>1850TSS320ZIC</subsys>
     <host>sindhu</host>
     <operator>CHANDRA</operator>
     <time>2013-11-19 16:17:44</time>
     <utc_time>2013-11-19 10:47:44</utc_time>
     <status>FAILED</status>
     <involved_object>TSS320-BA-04</involved_object>
     <request_id>WLAlMy4XMt9dysWL0xFM9g</request_id>
     <slotList>
       <slot>
         <slotLabel>XFP-1-1-8-1</slotLabel>
       </slot>
     </slotList>
     <clog_private_db_insertion_flag>1</clog_private_db_insertion_flag>
     <client_host>135.244.1.157</client_host>
     <username>CHANDRA</username>
     <neList>
       <ne>
         <neLabel>TSS320-BA-04</neLabel>
       </ne>
     </neList>
     <type>XI-641</type>
     </log>

     <log act="CreateXC">
     <app>ZIC</app>
     <seq>3</seq>
     <subsys>1850TSS320ZIC</subsys>
     <host>sindhu</host>
     <operator>CHANDRA</operator>
     <time>2013-11-19 16:17:44</time>
     <utc_time>2013-11-19 10:47:44</utc_time>
     <status>SUCCESS</status>
     <involved_object>TSS320-BA-04</involved_object>
     <tpList>
       <tp>
         <neLabel>TSS320-BA-04</neLabel>
         <role>from</role>
         <tpLabel>STM64AU4-1-1-6-1-1</tpLabel>
       </tp>
       <tp>
         <neLabel>TSS320-BA-04</neLabel>
         <role>to</role>
         <tpLabel>STM64AU4-1-1-8-1-1</tpLabel>
       </tp>
     </tpList>
     <dir>BID</dir>
     <xc_rate>VC4</xc_rate>
     <request_id>Ym67SHJiWlsovsjFX56ZaA</request_id>
     <xc_id></xc_id>
     <clog_private_db_insertion_flag>1</clog_private_db_insertion_flag>
     <client_host>135.244.1.157</client_host>
     <username>CHANDRA</username>
     </log>
     
</logger>
[/input.xml]


[output.xml]
<testng-results><suite name="Suite1"><test name="EML_CLOG_TSS320_3_6"><class 
name="1350OMS_9.6.5.0AD1_UX+IRP619UX.EML_CLOG_TSS320_3_6"/><test-method 
status="PASS" 
signature="=1)TSS320-BA-04_NE_Login(app=ZIC,subsys=1850TSS320ZIC,host=sindhu,operator=CHANDRA,time=2013-11-19_16:17:44,status=SUCCESS,involved_object=TSS320-BA-04,client_host=135.244.1.157);
" name="&quot;1.NE_Login&quot; duration-ms=&quot;0&quot; 
started-at=&quot;0&quot;" 
description="NE_Login(log_act=NE_Login,app=ZIC,subsys=1850TSS320ZIC,host=sindhu,operator=CHANDRA,time=2013-11-19_16:17:44,status=SUCCESS,involved_object=TSS320-BA-04,client_host=135.244.1.157);&quot;
 finished-at=&quot;0&quot;&gt;"/><test-method status="FAIL" 
signature="=2)TSS320-BA-04_AddCard(app=ZIC,subsys=1850TSS320ZIC,host=sindhu,operator=CHANDRA,time=2013-11-19_16:17:44,status=FAILED,involved_object=TSS320-BA-04,client_host=135.244.1.157);
" name="&quot;2.AddCard&quot; duration-ms=&quot;0&quot; 
started-at=&quot;0&quot;" 
description="AddCard(log_act=AddCard,app=ZIC,subsys=1850TSS320ZIC,host=sindhu,operator=CHANDRA,time=2013-11-19_16:17:44,status=FAILED,involved_object=TSS320-BA-04,client_host=135.244.1.157);&quot;
 finished-at=&quot;0&quot;&gt;"/><test-method status="PASS" 
signature="=3)TSS320-BA-04_CreateXC(app=ZIC,subsys=1850TSS320ZIC,host=sindhu,operator=CHANDRA,time=2013-11-19_16:17:44,status=SUCCESS,involved_object=TSS320-BA-04,client_host=135.244.1.157);
" name="&quot;3.CreateXC&quot; duration-ms=&quot;0&quot; 
started-at=&quot;0&quot;" 
description="CreateXC(log_act=CreateXC,app=ZIC,subsys=1850TSS320ZIC,host=sindhu,operator=CHANDRA,time=2013-11-19_16:17:44,status=SUCCESS,involved_object=TSS320-BA-04,client_host=135.244.1.157);&quot;
 finished-at=&quot;0&quot;&gt;"/></test></suite></testng-results>
[/output.xml]


best,
Shaji 
-------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to God.
-------------------------------------------------------------------------------

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to