我有一些字符串数据 -
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel> </rss>" ;
现在我想将这个字符串以正确的 XML 格式展示在网页上。
<channel>
<title>
RSS Title
</title>
</channel>
我该怎么做?
我有一些字符串数据 -
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel> </rss>" ;
<channel>
<title>
RSS Title
</title>
</channel>
希望 google-code-prettify 可以完成工作,但似乎它不能对缩进进行处理。通过一个额外的缩进插件 (vkbeautify),可以获取正确的带有缩进的 xml 格式。
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));
}
};
});