简体   繁体   English

将JSON解析为HTML表

[英]Parsing JSON into HTML Table

Can anyone help me parsing the XML content present in Oracle DB with BLOB. 任何人都可以帮我解析使用BLOB在Oracle DB中存在的XML内容。 And Display it in UI with HTML Table using Angular JS. 并使用Angular JS在HTML表格中显示它。

From Oracle DB whenever I Query a field ,it will return multiple ROW with BLOB 每当我查询一个字段时,从Oracle DB,它将返回多个带有BLOB的ROW

And Each Blob contains XML data. 每个Blob都包含XML数据。 Now I want to Parse it from AngularJS. 现在我想从AngularJS中解析它。

Here What I have tried 这是我尝试过的

I am getting the XML Response from php and sending it to Sitemap.xml and accessing that in AngularJS 我从php获取XML响应并将其发送到Sitemap.xml并在AngularJS中访问它

Since I have 3 ROWS returning from database , I am getting 3 XML tags like below 由于我有3个ROWS从数据库返回,我得到3个XML标签,如下所示

<Person:PersonEvent xmlns:Person = "http://PERSON/PersonEvent">
    <Person:Body>
        <Person:WorkOrder workOrderId = "1">
            <Person:OrderStatus>RED</Person:OrderStatus>
            <Person:OrderType>A</Person:OrderType>
        </Person:WorkOrder>
    </Person:Body>
</Person:PersonEvent>
<Person:PersonEvent xmlns:Person = "http://PERSON/PersonEvent">
    <Person:Body>
        <Person:WorkOrder workOrderId = "2">
            <Person:OrderStatus>GREEN</Person:OrderStatus>
            <Person:OrderType>B</Person:OrderType>
        </Person:WorkOrder>
    </Person:Body>
</Person:PersonEvent>
<Person:PersonEvent xmlns:Person = "http://PERSON/PersonEvent">
    <Person:Body>
        <Person:WorkOrder workOrderId = "3">
            <Person:OrderStatus>RED</Person:OrderStatus>
            <Person:OrderType>C</Person:OrderType>
        </Person:WorkOrder>
    </Person:Body>
</Person:PersonEvent>

Now I want to convert it into JSON using ANGULAR JS and Display the Values in HTML TABLE. 现在我想使用ANGULAR JS将它转换为JSON并在HTML TABLE中显示值。 Can you please help me 你能帮我么

AngularJS AngularJS

    var app = angular.module('httpApp', []);
    app.controller('httpController', function ($scope, $http) {
        $http.get("Sitemap.xml",
                {
                    transformResponse: function (cnv) {
                        var x2js = new X2JS();
                        var aftCnv = x2js.xml_str2json(cnv);
                        return aftCnv;
                    }
                })
        .success(function (response) {
            console.log(response);
        });
    });

And My UI Should look as HTML Table like 我的UI应该看起来像HTML表格

   <table>
  <tr>
    <th>WorkOrder</th>
    <th>OrderStatus</th>
    <th>OrderType</th>
  </tr>
  <tr>
    <td>1<br></td>
    <td>RED</td>
    <td>A</td>
  </tr>
  <tr>
    <td>2</td>
    <td>GREEN</td>
    <td>B</td>
  </tr>
  <tr>
    <td>3</td>
    <td>RED</td>
    <td>C</td>
  </tr>
</table>

I got answer to myself. 我得到了答案。 The Problem was the XML is having multiple root elements so it wasn't converted to JSON. 问题是XML有多个根元素,因此它没有转换为JSON。

As a work around now I am Appending my XML with So Now I am able to convert it into JSON 作为一个现在的工作我正在使用So附加我的XML现在我能够将它转换为JSON

<Persons>
<Person:PersonEvent xmlns:Person = "http://PERSON/PersonEvent">
    <Person:Body>
        <Person:WorkOrder workOrderId = "1">
            <Person:OrderStatus>RED</Person:OrderStatus>
            <Person:OrderType>A</Person:OrderType>
        </Person:WorkOrder>
    </Person:Body>
</Person:PersonEvent>
<Person:PersonEvent xmlns:Person = "http://PERSON/PersonEvent">
    <Person:Body>
        <Person:WorkOrder workOrderId = "2">
            <Person:OrderStatus>GREEN</Person:OrderStatus>
            <Person:OrderType>B</Person:OrderType>
        </Person:WorkOrder>
    </Person:Body>
</Person:PersonEvent>
<Person:PersonEvent xmlns:Person = "http://PERSON/PersonEvent">
    <Person:Body>
        <Person:WorkOrder workOrderId = "3">
            <Person:OrderStatus>RED</Person:OrderStatus>
            <Person:OrderType>C</Person:OrderType>
        </Person:WorkOrder>
    </Person:Body>
</Person:PersonEvent>
</Persons>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM