-
-
Save theangrydev/fab68e129db2cb18f98796415765715f to your computer and use it in GitHub Desktop.
Revisions
-
sente revised this gist
Dec 16, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ function formatXml(xml) { if (pad != 0) { pad -= 1; } } else if (node.match( /^<\w([^>]*[^\/])?>.*$/ )) { indent = 1; } else { indent = 0; -
sente revised this gist
Jul 1, 2016 . 1 changed file with 23 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,26 @@ The MIT License (MIT) Copyright (c) 2016 Stuart Powers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. function formatXml(xml) { var formatted = ''; var reg = /(>)(<)(\/*)/g; -
sente revised this gist
Jun 7, 2012 . 1 changed file with 107 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,107 @@ <html> <head> <title>Javascript xml pretty print - Stuart Powers</title> <script src="http://bit.ly/jqymin"></script> <style> textarea { width: 80%; height: 50%; overflow-x: scroll; overflow-y: scroll; display: block; border: 1px solid black; padding: 5px; margin: 5px; } </style> <script> function formatXml(xml) { var formatted = ''; var reg = /(>)(<)(\/*)/g; xml = xml.replace(reg, '$1\r\n$2$3'); var pad = 0; jQuery.each(xml.split('\r\n'), function(index, node) { 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; } $(function(){ var url = "http://careers.stackoverflow.com/jobs/feed?searchTerm=python&location=02144&range=30"; $.ajax({ url: url, dataType:"text", beforeSend:function(){$('.info').append($('<p>requesting: '+url+'</p>'));}, error:function(){$('.info').append($('<p>error! '+url+'</p>'));}, success: function(data) { $('.unformatted').text(data); } }); $.ajax({ url: url, dataType:"text", beforeSend:function(){ $('.info2').append($('<p>requesting '+url+'</p>')); $('.info2').append($('<p>and formatting the response!')); }, error:function(){$('.info2').append($('<p>error! '+url+'</p>'));}, success: function(data) { xml_neat = formatXml(data); $('.formatted').text(xml_neat); } }); }); </script> </head> <body> <code> Also available <a href="http://sente.cc/misc/javascript_xml_pretty_print.html"> http://sente.cc/misc/javascript_xml_pretty_print.html </a> </code> <pre class="info"></pre> <h3>unformatted</h3> <textarea class="unformatted"></textarea> <h3>formatted</h3> <textarea class="formatted"></textarea> <body> </html> -
sente created this gist
Jul 14, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ function formatXml(xml) { var formatted = ''; var reg = /(>)(<)(\/*)/g; xml = xml.replace(reg, '$1\r\n$2$3'); var pad = 0; jQuery.each(xml.split('\r\n'), function(index, node) { 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; } xml_raw = '<foo><bar><baz>blahblah</baz><baz>tralala</baz></bar></foo>'; xml_formatted = formatXml(xml_raw); xml_escaped = xml_formatted.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/ /g, ' ').replace(/\n/g,'<br />'); var mydiv = document.createElement('div'); mydiv.innerHTML = xml_escaped; document.body.appendChild(mydiv);