Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:17:48+00:00 2026-06-14T10:17:48+00:00

I am creating a table using the following code based on the input provided

  • 0

I am creating a table using the following code based on the input provided in XML which is working perfectly fine but I want to convert to code to create a table dynamically meaning if i add more columns,code should automatically adjust..currently I have hardcoded that the table will contain four columns..please suggest on what changes need to be done to the code to achieve this

Input XML:-

<Fixes>
CR           FA      CL                    TITLE

409452      WLAN    656885        Age out RSSI values from buffer in Beacon miss scenario  
12345,45678  BT     54567,34567   Test
379104       BT     656928        CR379104: BT doesn’t work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.
</Fixes>

Python code

crInfo = [ ]
CRlist = [ ]
CRsFixedStart=xmlfile.find('<Fixes>')
CRsFixedEnd=xmlfile.find('</Fixes>')
info=xmlfile[CRsFixedStart+12:CRsFixedEnd].strip()
for i in info.splitlines():
    index = i.split(None, 3)
    CRlist.append(index)
crInfo= CRlisttable(CRlist)
file.close()

def CRlisttable(CRlist,CRcount):
#For logging
global logString
print "\nBuilding the CRtable\n"
logString += "Building the build combo table\n"
#print "CRlist"
#print CRlist
CRstring = "<table cellspacing=\"1\" cellpadding=\"1\" border=\"1\">\n"
CRstring += "<tr>\n"
CRstring += "<th bgcolor=\"#67B0F9\" scope=\"col\">" + CRlist[0][0] + "</th>\n"
CRstring += "<th bgcolor=\"#67B0F9\" scope=\"col\">" + CRlist[0][1] + "</th>\n"
CRstring += "<th bgcolor=\"#67B0F9\" scope=\"col\">" + CRlist[0][2] + "</th>\n"
CRstring += "<th bgcolor=\"#67B0F9\" scope=\"col\">" + CRlist[0][3] + "</th>\n"
CRstring += "</tr>\n"

TEMPLATE = """
<tr>
<td><a href='http://prism/CR/{CR}'>{CR}</a></td>
<td>{FA}</td>
<td>{CL}</td>
<td>{Title}</td>
</tr>
"""
for item in CRlist[1:]:
    CRstring += TEMPLATE.format(
        CR=item[0],
        FA=item[1],
        CL=item[2],
        Title=item[3],
        )
CRstring += "\n</table>\n"
#print CRstring
return CRstring
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:17:50+00:00Added an answer on June 14, 2026 at 10:17 am

    Although I have some reservations about providing this since you seem unwilling to even attempt doing so yourself, here’s an example showing one way it could be done — all in the hopes that perhaps at least you’ll be inclined to the effort to study and possibly learn a little something from it even though it’s being handed to you…

    with open('cr_fixes.xml') as file: # get some data to process
        xmlfile = file.read()
    
    def CRlistToTable(CRlist):
        cols = CRlist[0] # first item is header-row of col names on the first line
    
        CRstrings = ['<table cellspacing="1" cellpadding="1" border="1">']
        # table header row
        CRstrings.append('  <tr>')
        for col in cols:
            CRstrings.append('    <th bgcolor="#67B0F9" scope="col">{}</th>'.format(col))
        CRstrings.append('  </tr>')
    
        # create a template for each table row
        TR_TEMPLATE = ['  <tr>']
        # 1st col of each row is CR and handled separately since it corresponds to a link
        TR_TEMPLATE.append(
            '    <td><a href="http://prism/CR/{{{}}}">{{{}}}</a></td>'.format(*[cols[0]]*2))
        for col in cols[1:]:
            TR_TEMPLATE.append('    <td>{{}}</td>'.format(col))
        TR_TEMPLATE.append('  </tr>')
        TR_TEMPLATE = '\n'.join(TR_TEMPLATE)
    
        # then apply the template to all the non-header rows of CRlist
        for items in CRlist[1:]:
            CRstrings.append(TR_TEMPLATE.format(CR=items[0], *items[1:]))
        CRstrings.append("</table>")
    
        return '\n'.join(CRstrings) + '\n'
    
    FIXES_START_TAG, FIXES_END_TAG = '<Fixes>, </Fixes>'.replace(',', ' ').split()
    CRsFixesStart = xmlfile.find(FIXES_START_TAG) + len(FIXES_START_TAG)
    CRsFixesEnd = xmlfile.find(FIXES_END_TAG)
    info = xmlfile[CRsFixesStart:CRsFixesEnd].strip().splitlines()
    
    # first line of extracted info is a blank-separated list of column names
    num_cols = len(info[0].split())
    
    # split non-blank lines of info into list of columnar data
    # assuming last col is the variable-length title, comprising reminder of line
    CRlist = [line.split(None, num_cols-1) for line in info if line]
    
    # convert list into html table
    crInfo = CRlistToTable(CRlist)
    print crInfo
    

    Output:

    <table cellspacing="1" cellpadding="1" border="1">
      <tr>
        <th bgcolor="#67B0F9" scope="col">CR</th>
        <th bgcolor="#67B0F9" scope="col">FA</th>
        <th bgcolor="#67B0F9" scope="col">CL</th>
        <th bgcolor="#67B0F9" scope="col">TITLE</th>
      </tr>
      <tr>
        <td><a href="http://prism/CR/409452">409452</a></td>
        <td>WLAN</td>
        <td>656885</td>
        <td>Age out RSSI values from buffer in Beacon miss scenario</td>
      </tr>
      <tr>
        <td><a href="http://prism/CR/12345,45678">12345,45678</a></td>
        <td>BT</td>
        <td>54567,34567</td>
        <td>Test</td>
      </tr>
      <tr>
        <td><a href="http://prism/CR/379104">379104</a></td>
        <td>BT</td>
        <td>656928</td>
        <td>CR379104: BT doesnt work that Riva neither sends HCI Evt for HID ACL data nor 
            response to HCI_INQUIRY after entering into pseudo sniff subrating mode.</td>
      </tr>
    </table>
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am creating the search bar and table view programatically using the following code
I'm using the following org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent) I'm creating a table viewer with cellEditors and
I am creating one form in html using table. Which have one Drop down
I am creating an android application in which I am using table layout in
i am inserting data into data base using following code but data is not
I'm adding a record to a table using the following code: Dim rs1 As
I'm having trouble creating an Access table using VBA, then accessing it via open-recordset.
i am creating a new android application.i am using the table layout. I have
In runtime I'm creating a DataTable and using nested for-loops to populate the table.
I'm using MyFaces 1.1.7 with Facelets and Tomahawk. When creating a regular data table,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.