javascript - 在 web 浏览器上显示来自 xml 文件的 HTML 表,无需在 unix 上使用任何软件或安装

标签 javascript python html pandas xml

我是 HTML 和 javascript 的新手。遇到了很多关于我的问题的问题,在努力寻找解决方案之后,我发布了这个问题。
问题陈述:
我有一个 xml,我正在尝试将其转换为 HTML,以便我可以在 Web 浏览器上以表格格式显示它。

<?xml version="1.0" encoding="UTF-8"?>
<chapter name="ndlkjfidm" date="dfhkryi">
    <edge name="nnn" P="ffgnp" V="0.825" T="125c">
        <seen name="seen1">
        </seen>
        <seen name="ABB">
            <mob name="adas_jk3" type="entry">
                <nod name="VSS" voltage="0.000000" vector="!ENXB" active_input="NA" active_ouput="ENX">
                    <temp name="ADS_DEFAULT_temp_LOW">
                        <raw nod="VBP" alt="7.05537e-15" jus="74.4619" />
                        <raw nod="VDDC" alt="4.63027e-10" jus="115.178" />
                        <raw nod="VDDP" alt="6.75316e-10" jus="115.178" />
                        <raw nod="VSS" alt="5.04568e-14" jus="9.63935" />
                        <raw nod="VBN" alt="1.21047e-14" jus="192.973" />
                        <raw nod="VBP" trip="4.58141e-12" />
                        <raw nod="VDDC" trip="5.19549e-09" />
                        <raw nod="VDDP" trip="5.49458e-08" />
                        <raw nod="VSS" trip="6.00563e-08" />
                        <raw nod="VBN" trip="8.94924e-11" />
                    </temp>
                </nod>
                <nod name="VSS" voltage="0.000000" vector="ENXB" active_input="NA" active_ouput="ENX">
                    <temp name="ADS_DEFAULT_temp_HIGH">
                        <raw nod="VBP" alt="7.05537e-15" jus="74.4644" />
                        <raw nod="VDDC" alt="1.52578e-14" jus="311.073" />
                        <raw nod="VDDP" alt="1.00188e-14" jus="521.709" />
                        <raw nod="VSS" alt="4.03483e-14" jus="11.1118" />
                        <raw nod="VBN" alt="1.21047e-14" jus="192.975" />
                        <raw nod="VBP" trip="4.58141e-12" />
                        <raw nod="VDDC" trip="1.29302e-12" />
                        <raw nod="VDDP" trip="4.92723e-08" />
                        <raw nod="VSS" trip="4.91887e-08" />
                        <raw nod="VBN" trip="8.95356e-11" />
                    </temp>
                </nod>
            </mob>
        </seen>
    </edge>
</chapter>
以下是我尝试过的链接。
https://www.w3schools.com/xml/ajax_applications.asp
https://www.geeksforgeeks.org/read-xml-file-and-print-the-details-as-tabular-data-by-using-javascript/
循环孔:
我无法安装任何东西(sudo apt install apache2 等)或任何软件(xammp 等)
因此,javascript 不显示表格。
也尝试过 pandas,但不知道如何在网络浏览器上显示它,而且 xml 也非常大(~1GB)
有人可以建议我如何使用任何语言组合来完成这项工作。
  • 带有 HTML 和 javascript 的 python
  • 带有 json 和 HTML 的 python
  • 带有 javascript 的 HTML
  • 最佳答案

    这应该解决您的问题(如要求),使用 Pandas :

    import pandas as pd
    
    xml_data = '''<?xml version="1.0" encoding="UTF-8"?>
    <chapter name="ndlkjfidm" date="dfhkryi">
        <edge name="nnn" P="ffgnp" V="0.825" T="125c">
            <seen name="seen1">
            </seen>
            <seen name="ABB">
                <mob name="adas_jk3" type="entry">
                    <nod name="VSS" voltage="0.000000" vector="!ENXB" active_input="NA" active_ouput="ENX">
                        <temp name="ADS_DEFAULT_temp_LOW">
                            <raw nod="VBP" alt="7.05537e-15" jus="74.4619" />
                            <raw nod="VDDC" alt="4.63027e-10" jus="115.178" />
                            <raw nod="VDDP" alt="6.75316e-10" jus="115.178" />
                            <raw nod="VSS" alt="5.04568e-14" jus="9.63935" />
                            <raw nod="VBN" alt="1.21047e-14" jus="192.973" />
                            <raw nod="VBP" trip="4.58141e-12" />
                            <raw nod="VDDC" trip="5.19549e-09" />
                            <raw nod="VDDP" trip="5.49458e-08" />
                            <raw nod="VSS" trip="6.00563e-08" />
                            <raw nod="VBN" trip="8.94924e-11" />
                        </temp>
                    </nod>
                    <nod name="VSS" voltage="0.000000" vector="ENXB" active_input="NA" active_ouput="ENX">
                        <temp name="ADS_DEFAULT_temp_HIGH">
                            <raw nod="VBP" alt="7.05537e-15" jus="74.4644" />
                            <raw nod="VDDC" alt="1.52578e-14" jus="311.073" />
                            <raw nod="VDDP" alt="1.00188e-14" jus="521.709" />
                            <raw nod="VSS" alt="4.03483e-14" jus="11.1118" />
                            <raw nod="VBN" alt="1.21047e-14" jus="192.975" />
                            <raw nod="VBP" trip="4.58141e-12" />
                            <raw nod="VDDC" trip="1.29302e-12" />
                            <raw nod="VDDP" trip="4.92723e-08" />
                            <raw nod="VSS" trip="4.91887e-08" />
                            <raw nod="VBN" trip="8.95356e-11" />
                        </temp>
                    </nod>
                </mob>
            </seen>
        </edge>
    </chapter>
    
    
    '''
    
    读取 xml 的一种选择是:
    df = pd.read_xml(xml_data)
    # df
    html = df.to_html()
    print(html)
    
    结果:

    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>name</th>
          <th>P</th>
          <th>V</th>
          <th>T</th>
          <th>seen</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>nnn</td>
          <td>ffgnp</td>
          <td>0.825</td>
          <td>125c</td>
          <td>NaN</td>
        </tr>
      </tbody>
    </table>

    当然,您可以深入研究该 xml:
    df = pd.read_xml(xml_data, xpath=".//nod")
    # df
    html = df.to_html()
    print(html)
    
    这将导致:

    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>name</th>
          <th>voltage</th>
          <th>vector</th>
          <th>active_input</th>
          <th>active_ouput</th>
          <th>temp</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>VSS</td>
          <td>0.0</td>
          <td>!ENXB</td>
          <td>NaN</td>
          <td>ENX</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>1</th>
          <td>VSS</td>
          <td>0.0</td>
          <td>ENXB</td>
          <td>NaN</td>
          <td>ENX</td>
          <td>NaN</td>
        </tr>
      </tbody>
    </table>

    甚至:
    df = pd.read_xml(xml_data, xpath=".//raw")
    # df
    html = df.to_html()
    print(html)
    
    返回:

    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>nod</th>
          <th>alt</th>
          <th>jus</th>
          <th>trip</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>VBP</td>
          <td>7.055370e-15</td>
          <td>74.46190</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>1</th>
          <td>VDDC</td>
          <td>4.630270e-10</td>
          <td>115.17800</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>2</th>
          <td>VDDP</td>
          <td>6.753160e-10</td>
          <td>115.17800</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>3</th>
          <td>VSS</td>
          <td>5.045680e-14</td>
          <td>9.63935</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>4</th>
          <td>VBN</td>
          <td>1.210470e-14</td>
          <td>192.97300</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>5</th>
          <td>VBP</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>4.581410e-12</td>
        </tr>
        <tr>
          <th>6</th>
          <td>VDDC</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>5.195490e-09</td>
        </tr>
        <tr>
          <th>7</th>
          <td>VDDP</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>5.494580e-08</td>
        </tr>
        <tr>
          <th>8</th>
          <td>VSS</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>6.005630e-08</td>
        </tr>
        <tr>
          <th>9</th>
          <td>VBN</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>8.949240e-11</td>
        </tr>
        <tr>
          <th>10</th>
          <td>VBP</td>
          <td>7.055370e-15</td>
          <td>74.46440</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>11</th>
          <td>VDDC</td>
          <td>1.525780e-14</td>
          <td>311.07300</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>12</th>
          <td>VDDP</td>
          <td>1.001880e-14</td>
          <td>521.70900</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>13</th>
          <td>VSS</td>
          <td>4.034830e-14</td>
          <td>11.11180</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>14</th>
          <td>VBN</td>
          <td>1.210470e-14</td>
          <td>192.97500</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>15</th>
          <td>VBP</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>4.581410e-12</td>
        </tr>
        <tr>
          <th>16</th>
          <td>VDDC</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>1.293020e-12</td>
        </tr>
        <tr>
          <th>17</th>
          <td>VDDP</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>4.927230e-08</td>
        </tr>
        <tr>
          <th>18</th>
          <td>VSS</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>4.918870e-08</td>
        </tr>
        <tr>
          <th>19</th>
          <td>VBN</td>
          <td>NaN</td>
          <td>NaN</td>
          <td>8.953560e-11</td>
        </tr>
      </tbody>
    </table>

    以下 pandas 文档可能会有所帮助:
    https://pandas.pydata.org/docs/dev/reference/api/pandas.read_xml.html

    https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_html.html

    关于javascript - 在 web 浏览器上显示来自 xml 文件的 HTML 表,无需在 unix 上使用任何软件或安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73066883/

    相关文章:

    python - 如何在Python中存储嵌套数据?

    html - div 内的 ASP : Table buttons become unclickable: Buttons nested inside a table,

    javascript - 按下空格键时暂停 HTML5 视频

    javascript - 有谁知道如何使起始数和结束数产生平方根的无序列表?

    javascript - SlideToggle 删除显示后将焦点设置到元素 :hidden attribute with jQuery

    python - 谁能给我提供一些聚类示例?

    css - 为网页添加水印 - 架构

    javascript - 如何修复 JavaScript 中的 "this.property is not iterable at window.onload"

    javascript - 实时显示所有当前访客光标

    python - 使用 pyODBC 连接到 ODBC