Hi all, I need some assistance with the xml writer. I could possbly figure this out myself, but I have a deadline so no time to fiddle. I am writing an xml file with perl as items get updated from the front end by users. my query is that I have to write a xml query where it will use all the inputs given from a database, using foreach statement, we'll not go to the database so here is what I want to achieve. I have a list of devices and ports, I need to create a button based on a filter, the filter would be something like this where node='node1' and port='port1' the xml file gets populated based on filter names and filters can only exist once. so here is an example of the script. ## I wrote this on here, so don't judge on errors, I just need an answer for the main question.
use IO::File; use XML::Writer; my $output = IO::File->new(">wheretowrite.xml"); my $writer = XML::Writer->new(OUTPUT => $output); my @device_list = ( "node1 port1" , "node2 port2" , "node3 port3" ) foreach $node(@device_list) { @get_data = split ( ' ' , $node ); $device_name = @get_data[0]; $port_name = @get_data[1]; $writer->startTag("filter", "name" => "all_events", "sql" => "(where + node ="$device_name and port=$port_name") or (where node="device_nam +e and port=$port_name"), "label" => "just-testing", "view" => "Defaul +t"); $writer->endTag( "filter" ); } # end
As you can see, I need to write the $device_name and $port_name in the single filter, the way it does currently do it (as above) it will do a foreach and try to write the filter xml each time, but as it can only exist once it will end up with a single filter with single device and port. trying to put the foreach inbetween the middle of the xml writer statement, it will return an error. the end result should end in (where node='node1" and port=port1) or (where node='node2" and port=port2) so whether there are 100 nodes and ports or 1000's it must write in that sequence in a single filter. i hope this made sense.

In reply to xml::Writer query by GerryD

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.