Im writing a program that takes waypoint positions and converts them into XML using XML::Simple. I am having problems with the scripts.
1. first, the forcearray is forcing all elements to be an array when I just want all but Waypoint to be forced. the XML::Simple docs says to list them and i tried that but it still is not working.
2. In the Waypoint area the code keeps printing => and not =>.
I cant figure out a way to fix these.
The scripts:
#! perl -slw use strict; use IO::Socket; use XML::Simple; $\="\n"; for (;;){ ################################# #Waypoint Functions: print "%%% Waypoint GO %%%"; open TEMP, '<', '/home/uas/Scripts/WP/waytemp' or die "cannot +open 'waytemp' $!"; open FINAL, '<', '/home/uas/Scripts/WP/wayfinal' or die "canno +t open 'wayfinal' $!"; #check for a new waypoint file my @tstat = stat(TEMP); my @fstat = stat(FINAL); #If waytemp is newer send it to VC if ($tstat[9] >= $fstat[9]) { print "### NEW File ###"; my $xml = new XML::Simple ( RootName => 'Task', XMLDecl => + '<?xml version="1.0" encoding="UTF-8"?>', ForceArray => [ 'ID' ]); my @temp = <TEMP>; my @final = <FINAL>; close TEMP; close FINAL; my @waypoints; my $count = 0; foreach (@temp) { my @point = split(',', $_); push(@waypoints, "{'Longitude' => '$point[0]', 'Latitu +de' => '$point[1]', 'SequenceNumber' => '$count'}"); $count++; } print "### Create XML ###"; my $waydata= { 'xmlns' => "http://Task.CUIntegration.com", + 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xsi:sch +emaLocation' => "http://Task.CUIntegration.com Task.xsd ", 'ID' => 'ID', 'Type' => ['Loop'], 'Destination' => ['Velocity'], 'Waypoint' => [ "@waypoints"], }; print $waydata; my $textdata = $xml->XMLout($waydata); print $textdata; #print "--- SENDING ---"; #send($way_client, $textdata, 0); print "%%% DONE %%%"; } print "SLEEP"; sleep 10; }

And outputs this:
%%% Waypoint GO %%% ### NEW File ### ### Create XML ### HASH(0x97dbeb8) <?xml version="1.0" encoding="UTF-8"?> <Task ID="ID" xmlns="http://Task.CUIntegration.com" xmlns:xsi="http:// +www.w3.org /2001/XMLSchema-instance" xsi:schemaLocation="http://Task.CUIntegratio +n.com Task .xsd "> <Destination>Velocity</Destination> <Type>Loop</Type> <Waypoint>{'Longitude' =&gt; '40.56', 'Latitude' =&gt; ' -106.25 ', 'SequenceNumber' =&gt; '0'} {'Longitude' =&gt; '38.89', 'Latitude' +=&gt; ' -1 05.44 ', 'SequenceNumber' =&gt; '1'} {'Longitude' =&gt; '40.31', 'Latitude' +=&gt; ' -1 03.82', 'SequenceNumber' =&gt; '2'}</Waypoint> </Task> %%% DONE %%% SLEEP

and needs to look like this:
<?xml version="1.0" encoding="UTF-8"?> <Task xmlns="http://Task.CUIntegration.com" xmlns:xsi="http://www.w3.o +rg/2001/XMLSchema-instance" xsi:schemaLocation="http://Task.CUIntegra +tion.com Task.xsd "> <ID>ID</ID> <Type>Loop</Type> <Destination>Velocity</Destination> <Waypoint Latitude="40.147622" Longitude="-105.240443" SequenceNumber +="0"/> <Waypoint Latitude="40.146132" Longitude="-105.246007" SequenceNumber +="1"/> <Waypoint Latitude="40.139455" Longitude="-105.246007" SequenceNumber +="2"/> <Waypoint Latitude="40.140011" Longitude="-105.253101" SequenceNumber +="3"/> <Waypoint Latitude="40.133751" Longitude="-105.255049" SequenceNumber +="4"/> </Task>

In reply to XML problems by deadpickle

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.