?
Solved

Data to XML

Posted on 2010-09-20
6
Medium Priority
?
705 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 84

Accepted Solution

by:
ozo earned 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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…
Suggested Courses

650 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