Solved

Data to XML

Posted on 2010-09-20
6
689 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

695 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