Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
There are some pretty good responses here. I'll add that you do not seem to just be converting CSV to XML. If you were the following would suffice:
my (@data, @hdrs) ; for(<DATA>) { chomp; unless ($first) {@hdrs = split q~,~; $first++; next}; @data = split q~,~; print qq~<record>\n~; for(1,3) {print qq!<$hdrs[$_]> $data[$_] </$hdrs[$_]>\n!}; print qq~</record>\n~; ++$first; } __DATA__ Name,Company,Email,Phone A,X,a.x@aol.com,1111 B,Y,b.y@aol.com,0 C,Z,c.z@aol.com,2222
Produces:
<record> <Company> X </Company> <Phone> 1111 </Phone> </record> <record> <Company> Y </Company> <Phone> 0 </Phone> </record> <record> <Company> Z </Company> <Phone> 2222 </Phone> </record>

What you really appear to be doing is taking some data in one format and embedding it into an XML format. There is a difference between the two. There are actually tools out there to convert XML to other formats of XML as well as tools to format XML for the browser (CSS) that might make what you appear to be doing here moot.

As for the rest of that elaborate output (really everything up to and including the tgroup tag as well as the closing tags) can be added using simple print statements like print qq~<record>\n~;. Or you could use a template module for everything but the dynamic parts of your output.

Celebrate Intellectual Diversity


In reply to Re: csv to xml by InfiniteSilence
in thread csv to xml by vavz

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found