Hello, I have a perl script that retrieves data from a database and saves the results in a text file. I need to change this so the database results are saved in an XML file. I would like to format/ generate the XML tags automatically, but I do not know how to do this, what changes will be necessary on the script. Any help on how to do this in the code, would be really nice. This is my current script:
#!/usr/local/bin/perl use warnings; use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; my $objConn = Win32::OLE->new("ADODB.Connection"); my $objCommand = Win32::OLE->new("ADODB.Command"); my $objRecordSet = Win32::OLE->new("ADODB.Recordset"); $objConn->Open("Driver={Webtrends ODBC Driver};Server=sdfhadgdjlah;Por +t=7099;Database=flrdacbkoji;Uid=adkljd;Pwd=fadadk;lmam;AccountId=1;La +nguage=english;ProfileGuid=KlDwrNbKgm6;SSL=0;"); $objCommand->{"ActiveConnection"} = $objConn; $objCommand->{"CommandText"} = "SELECT * FROM Pages WHERE Titles <> '' + AND URLs IS NOT NULL AND Titles NOT LIKE '%404 Error Page%' AND Titl +es NOT LIKE '%302 Found' AND URLs <> 'http://powerhousetv.com/' AND U +RLs <> 'http://domain.com/index.htm' AND URLs <> 'http://domain.com/w +cm/idcplg/' ORDER BY Visits DESC"; $objRecordSet->{"CursorLocation"} = 3; #adUseClient $objRecordSet->{"CursorType"} = 0; #adOpenForwardOnly $objRecordSet->{"LockType"} = 1; #adLockReadOnly; $objRecordSet = $objCommand->Execute(); open OUT, ">output.txt"; while (!$objRecordSet->EOF) { print OUT $objRecordSet->Fields("Titles")->value, ", "; print OUT $objRecordSet->Fields("URLs")->value, ", "; print OUT $objRecordSet->Fields("Visits")->value, ", "; print OUT $objRecordSet->Fields("Views")->value, "\n"; $objRecordSet->MoveNext(); }

In reply to saving sql data in xml formatted file by Anonymous Monk

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.