Hi Monks, I am stuck at a situation in my task and want your help in solving it. A brief background about the problem statement is as below. I am parsing the Below xml using the XML::parser module and i am able to parse the XML. My XML and the code i am using to parse is as below. My script should perform the below operations. 1)Access each testcase defined in the XML and perform the operations mentioned in each step. For each step there is a command and parameters for the command. This command is basically a perl function module which i have written and its placed in a seperate perl file. 2)My script should access each step and trigger the corresponding function with the specified parameter. The parameters are specified as Arguments in my XML, Uptil now i was only able to parse the XML using the below code but i am not able to trigger functions based on the steps, since the output of the parser is kind a confusing and i don't know how i can use this output. Please suggest how i can proceed, if you have any doubts in regarding the problems please let me know.

<DCA> <testcase type = "Interactive"> <step command ="LaunchApp " param1 = "executablepath" param2 = "di +rpath"/> <step command = "Gohere"/> <step command = "Changemode" param1 = "100"/> <step command = "CaptureRectanlge" param1 = "3" param2 = "96" para +m3 = "726" param4 = "580"/> <step command = "CompareImage" param1 = "D:\\img1.jpg" param2 = "D +:\\img2.jpg "/> </testcase> <testcase type = "broswer"> <step command ="Launchapp " param1 = "executablepath" param2 = "di +rpath"/> <step command = "Gohere"/> <step command = "Channgemode" param1 = "100"/> <step command = "CaptureRectanlge" param1 = "3" param2 = "96" para +m3 = "726" param4 = "580"/> <step command = "CompareImage" image1 = "D:\\img1.jpg" image2 = "D +:\\img2.jpg "/> </testcase> </DCA> MyCode: use warnings; use 5.010; use XML::Simple; #using XML::Parser use XML::Parser; my $parser = new XML::Parser; $parser->setHandlers(Start => \&startElement, End => \&endElement); + $parser->parsefile('D:\\ABC\\Perl Projects\\DCA.xml'); sub startElement { my( $parseinst, $element, %attrs ) = @_; SWITCH: { if ($element eq "testcase") { $count++; $tag = "testcase"; print "Testcase $count:\n"; for my $attr (keys %attrs) { print "$attr: $attrs{$attr}\n"; } last SWITCH; } if ($element eq "step") { print "Step: "; $tag = "step"; for my $attr (keys %attrs) { print "$attr: $attrs{$attr}\n"; } last SWITCH; } } } sub endElement { my( $parseinst, $element ) = @_; if ($element eq "testcase") { print "\n\n"; } elsif ($element eq "title") { print "\n"; } } Output of my script Testcase 1: type: Interactive Step: param2: dirpath param1: executablepath command: Launchsimulator Step: command: Homescreen Step: param1: 100 command: Channelchange Step: param4: 580 param2: 96 param3: 726 param1: 3 command: CaptureRectanlge Step: param2: D:\\img2.jpg param1: D:\\img1.jpg command: CompareImage Testcase 2: type: Netfront Step: param2: dirpath param1: executablepath command: Launchsimulator Step: command: Homescreen Step: param1: 100 command: Channelchange Step: param4: 580 param2: 96 param3: 726 param1: 3 command: CaptureRectanlge Step: image1: D:\\img1.jpg image2: D:\\img2.jpg command: CompareImage Testcase 3: type: HTML

So if you see the output i am getting tiggers for each of my registered handlers but i am not able to make use of the output for my scenario. Any suggestion is highly appreciated. If you have better design idea also please provide your suggestions.


In reply to Using function modules and passing arguments by parsing an XML. by balajinagaraju

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.