Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display xml text in html in angular js

I have some data in string -

 var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel>    </rss>" ;

Now I want this string to be display on web page in proper xml format .

<channel>
   <title>
        RSS Title
   </title>
</channel>

How can I do this?

like image 584
Disha Avatar asked Feb 10 '23 09:02

Disha


1 Answers

Was expecting google-code-prettify would do the job but looks like it does not do indentation. With an additional plugin for indentation (vkbeautify) able to get the proper xml format with indentation.

http://plnkr.co/edit/Pep9HurLI8NPtAXRsoFD?p=preview

<div ng-controller="myCtrl">
  <pre class="prettyprint lang-xml"></pre>
</div>

App.directive('prettyprint', function() {
  return {
    restrict: 'C',
    link: function postLink(scope, element, attrs) {
          element.text(vkbeautify.xml(scope.dom, 4));
    }
  };
});
like image 117
Bharat Avatar answered Feb 12 '23 00:02

Bharat