2016-10-01 79 views
1

任何人都可以帮助我用BLOB解析Oracle DB中存在的XML内容。并使用Angular JS在HTML表格中显示它。将JSON解析为HTML表

从Oracle数据库每当我问题涉及的领域,它会返回多个一行BLOB

,并且每个斑点包含XML数据。现在我想从AngularJS解析它。

这里我已经试过

我正在从PHP的XML响应,并把它发送到的sitemap.xml和访问,在AngularJS

因为我有3行从数据库返回,我得到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> 

现在我想要使用ANGULAR JS将它转换为JSON并在HTML TABLE中显示值。能否请你帮我

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); 
     }); 
    }); 

和我的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> 
+0

你有XML,你想生成HTML。 JSON与什么有什么关系? –

+1

请勿标记垃圾邮件。虽然您的XML来自BLOB,并且您正在使用PHP服务器端来检索它,但问题与blob或PHP没有任何关系。这是一个关于使用Angular操作XML的客户端JavaScript的问题。我删除了不相关的标签并添加了[tag:javascript]。我没有删除[tag:json],等待您澄清JSON与此有关的事情。 –

+0

@ T.J.Crowder由于我的XML数据非常大,我在这里给出了示例,所以我希望它在解析之前拥有JSON,并且在解析JSON的过程中很容易在Angular JS – Batman

回答

0

我得到的答案自己。 问题是XML有多个根元素,所以它没有转换为JSON。

由于周围的工作我现在追加我的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>