4

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?

1 Answer 1

8

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));
    }
  };
});
1
  • hi, when i click button and update dom value is not reflecting, how to fix that?
    – Velkumar
    Jun 1, 2017 at 12:39

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.