Solved

Data to XML

Posted on 2010-09-20
6
681 Views
Last Modified: 2013-11-15
Hi,

I'm looking for a way to convert a list of domain lists to XML format.

Example:

domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number
domain.com     number    number     number     number

Desired Output:

                <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>
      <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>
      <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>
      <tr class="gradeA">
                  <td>domain</td>
                  <td>number</td>
                  <td>number</td>
                  <td class="center">number</td>

                  <td class="center">number</td>
            </tr>

Thank you
0
Comment
Question by:faithless1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 33722826
awk 'print awk '{print "<tr class=\"gradeA\">\n<td>"$1"</td>\n<td>"$2"</td>\n<td>"$3"</td>\n<td class=\"center\">"$4"</td>\n<td class=\"center\">"$5"</td>"}'
0
 
LVL 84

Expert Comment

by:ozo
ID: 33722827
awk '{print "<tr class=\"gradeA\">\n<td>"$1"</td>\n<td>"$2"</td>\n<td>"$3"</td>\n<td class=\"center\">"$4"</td>\n<td class=\"center\">"$5"</td>"}'
0
 
LVL 15

Expert Comment

by:mish33
ID: 33726218

#!/usr/bin/python
import sys
for line in open(sys.stdin):
  domain, n1, n2, n3, n4 = line.split()
  print '''\
           <tr class="gradeA">
                  <td>%s</td>
                  <td>%s</td>
                  <td>%s</td>
                  <td class="center">%s</td>

                  <td class="center">%s</td>
            </tr>
''' % (domain.rsplit('.', 1)[0], n1, n2, n3, n4)

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 33727437
perl -ane 'printf q(   <tr class="gradeA">
                  <td>%s</td>
                  <td>%s</td>
                  <td>%s</td>
                  <td class="center">%s</td>

                  <td class="center">%s</td>
            </tr>
),@F'  
0
 
LVL 15

Expert Comment

by:mish33
ID: 33728363
.com not cut away :)
0
 
LVL 84

Expert Comment

by:ozo
ID: 33731244
perl -ane '$F[0]=~s/\.com$//;printf q(   <tr class="gradeA">
                  <td>%s</td>
                  <td>%s</td>
                  <td>%s</td>
                  <td class="center">%s</td>

                  <td class="center">%s</td>
            </tr>
),@F'  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question