Snippets Collections
this.XMLHelper = (new x_hca2_mh_intg.MHXMLUtils());

var responseBody = response.getBody();
var prettyXML = this.XMLHelper.prettifyXML(responseBody);


var MHXMLUtils = Class.create();
MHXMLUtils.prototype = {

    initialize: function() {
    },

    parseXMLNode: function (xml, node) {
        var xmlDoc = new XMLDocument2();
        xmlDoc.parseXML(xml);
        return (xmlDoc.getNodeText(node));
    },

    prettifyXML: function (xmlString) {
        var formatted = '';
        var reg = /(>)(<)(/)/g;
        xmlString = xmlString.replace(reg, '$1\r\n$2$3');
        var pad = 0;
        var nodes = xmlString.split('\r\n');
        nodes.forEach(function(node, index) {
            var indent = 0;
            if (node.match( /.+</\w[^>]>$/ ))
                indent = 0;
            else if (node.match( /^</\w/ )) {
                if (pad != 0) {
                    pad -= 1;
                }
            } else if (node.match( /^<\w[^>][^/]>.$/ ))
                indent = 1;
            else
                indent = 0;

            var padding = '';
            for (var i = 0; i < pad; i++)
                padding += '    ';

            formatted += padding + node + '\r\n';
            pad += indent;
        });
        return formatted;
    },

    type: 'MHXMLUtils'
};
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="45"
        android:startColor="#ff00ff"
        android:endColor="#000000"/>
</shape>
> More steps

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension