0

I am populating table using vb-script code :-

Set table = document.createElement("table")
Set tbody = document.createElement("tbody")
i = 0
For Each node In objMSXML.selectNodes(sXPath)   
    Set tr = document.createElement("tr")
    Set td = document.createElement("td")
    td.innerText = node.parentNode.nodeName & "->" & node.text
    tr.appendChild td
    tbody.appendChild tr
    i = i +1
Next
table.appendChild tbody
document.body.appendChild table

However I want to generate multiple columns my current output is :-

universespace->Milkyway 
universespace->Earth Layer 
scienceSubject->Solar System 
scienceItem->Earth 
scienceItem->Moon 
scienceItem->Mars 

And I want it to be like :-

+--------------+--------------+--------------+-----------+
|universespace1|universespace2|scienceSubject|scienceItem| 
+--------------+--------------+--------------+-----------+
| Milkyway     | Earth Layer  | Solar System | Earth     |
+--------------+--------------+--------------+-----------+
| Milkyway     | Earth Layer  | Solar System | Moon      |
+--------------+--------------+--------------+-----------+
| Milkyway     | Earth Layer  | Solar System | Mars      |
+--------------+--------------+--------------+-----------+

I tried various other ways :-

Set table = document.createElement("table")
Set tbody = document.createElement("tbody")
i = 0
For Each node In objMSXML.selectNodes(sXPath)   
    Set tr = document.createElement("tr")
     Select Case True
     Case "namespace" = node.parentNode.nodeName 
        Set th = document.createElement("th")
        th.innerText =   node.parentNode.nodeName
        tr.appendChild th
      Case "namespace" = node.parentNode.nodeName
        Set th1 = document.createElement("th")
        th1.innerText =   node.parentNode.nodeName
        tr.appendChild th1
      Case "querySubject" = node.parentNode.nodeName
        Set th2 = document.createElement("th")
        th2.innerText =   node.parentNode.nodeName
        tr.appendChild th2
      Case "queryItem" = node.parentNode.nodeName
        Set th3 = document.createElement("th")
        th3.innerText =   node.parentNode.nodeName
        tr.appendChild th3
     End Select
    'td.innerText = i & node.parentNode.nodeName & "->" & i & node.text
    'tr.appendChild td
    tbody.appendChild tr

Still not able to get output in desired format. It is all coming in single column rather than different columns.

The answer here doesn't help me to create table with columns. It just displays a table with one row and one column i.e. table cell.

Community
  • 1
  • 1
user2816085
  • 655
  • 4
  • 19
  • Possible duplicate of [Generating table](http://stackoverflow.com/questions/36081205/generating-table) – user692942 Mar 21 '16 at 11:07
  • Also duplicate of [Read text file and show in table vbscript](http://stackoverflow.com/q/36060599/692942) – user692942 Mar 21 '16 at 11:08
  • Then give up on VBScript and went to Java and now back to VBScript. See [search text in xml file using java](http://stackoverflow.com/q/36115367/692942). – user692942 Mar 21 '16 at 11:10
  • No access to install anything in my environment like java, eclipse etc. so vbscript is the only choice I have... – user2816085 Mar 21 '16 at 11:13

1 Answers1

0

I could create the table. Learning to code so always asking stupid questions. :-)

Set table = document.createElement("table")
Set tbody = document.createElement("tbody")
i = 0
Set tr = document.createElement("tr")
set th = document.createElement("th")
th.innerHtml = " Namespace1  "
tr.appendChild th
set th = document.createElement("th")
th.innerHtml = "  Namespace2  "
tr.appendChild th
set th = document.createElement("th")
th.innerHtml = "  Query Subject  "
tr.appendChild th
set th = document.createElement("th")
th.innerHtml = "  Query Item  "
tr.appendChild th
Set tr1 = document.createElement("tr")
For Each node In objMSXML.selectNodes(sXPath)   
    Set td = document.createElement("td")
    td.innerText = i & node.text
    tr1.appendChild td
    tbody.appendChild tr
    tbody.appendChild tr1
    i = i +1
Next
document.body.appendChild list
table.appendChild tbody
document.body.appendChild table
user2816085
  • 655
  • 4
  • 19