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));
    }
  };
});
Sign up to request clarification or add additional context in comments.

1 Comment

hi, when i click button and update dom value is not reflecting, how to fix that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.