I'm trying to write an xml file using javascript like this:   var root = new ActiveXobject("Microsoft.XMLDOM");  var Plnode = root.createProcessingInstruction("xml", "version ='1.0' encoding='utf-8'");  var Firstnode = root. createElement("Project");  var Input_data = root. createElement("Input_data");   When written, the data is written all in one line.  &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Project&gt;&lt;Input_data&gt;&lt;/Input_data&gt;&lt;/Project&gt;   Is there a way to print this in a prettified manner instead, like below?  &lt;Project&gt;  &lt;Input_data&gt;  &lt;/Input_data&gt; &lt;/Project&gt;
I have a string that represents a non indented XML that I would like to pretty-print. For example:  &lt;root&gt;&lt;node/&gt;&lt;/root&gt;   should become:  &lt;root&gt;   &lt;node/&gt; &lt;/root&gt;   Syntax highlighting is not a requirement. To tackle the problem I first transform the XML to add carriage returns and white spaces and then use a  tag to output the XML. To add new lines and white spaces I wrote the following function:   function formatXml(xml) {     var formatted = '';     var reg = /(&gt;)(&lt;)(\/*)/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( /.+&lt;\/\w[^&gt;]*&gt;$/ )) {             indent = 0;         } else if (node.match( /^&lt;\/\w/ )) {             if (pad != 0) {                 pad -= 1;             }         } else if (node.match( /^&lt;\w[^&gt;]*[^\/]&gt;.*$/ )) {             indent = 1;         } else {             indent = 0;         }          var padding = '';         for (var i = 0; i &lt; pad; i++) {             padding += '  ';         }          formatted += padding + node + '\r\n';         pad += indent;     });      return formatted; }   I then call the function like this:  jQuery('pre.formatted-xml').text(formatXml('&lt;root&gt;&lt;node1/&gt;&lt;/root&gt;'));   This works perfectly fine for me but while I was writing the previous function I thought that there must be a better way. So my question is do you know of any better way given an XML string to pretty-print it in an html page? Any javascript frameworks and/or plugins that could do the job are welcome. My only requirement is this to be done on the client side.
how to prove $\mathbb Z_n$ has divisors of zero if and only if $n$ is not prime A non-zero number $a \in \mathbb Z_n$ is called a divisor of zero if there is a non-zero number $b \in \mathbb Z_n$ such that $ab\equiv 0\pmod n.$  How can I prove $\mathbb Z_n$ has divisors of zero if and only if $n$ is not prime.  I filled out the addition and multiplication tables for modulo 6 and 7 and tried to find out the relation, and it's definitely true. I know I need to prove it in both directions since it is an 'iff' question. But I still don't get it. What is the optimal path between $2$ fixed points around an invisible obstructing wall? This question is actually related to my earlier question ("").  The fact that objects move a lot in the universe and that the universe is expanding, can imply that gravity is a repulsive force that increases with distance.. so the farthest objects repel us more.  This can still explain several existing observations, e.g., why does the apple fall?   Motion is the result of such repulsion. Two objects unlucky enough not to be moving relative to each other get squished due to the repulsion of the rest of the universe  around them. The earth repels the apple less than the stars so it is pushed towards the earth.   Furthermore, it can explain the expanding universe without the need for dark energy.  This could be demonstrated in a thought experiment. If we take a lot of same-charge particles (with small mass) such as electrons and lock them in a large box at a low enough temperature. The mutual repulsion of the particles may cause similar motion as if due to gravitational attraction.   Another experiment would be to measure the slight changes in our weight during day and night when the sun and earth align (if their masses are large enough to detect the feeble change in repulsion).   [EDIT: the question in the original form may not have been clear. It is "can we model".. with a yes/no answer and why (not). If downvoting, please justify. Do I need a transit visa for Malaysia? I am an Indian passport holder travelling from China to India via Kuala Lumpur, on Air Asia tickets bought separately. The layover is 4 hours and 30 minutes.  Do I need a transit visa? Laws of addition of Vectors If you use sudo su - or sudo -s you will get the full root certification  "likewise a root user ".  Is this user an official user or is it from canonical?  ~$ sudo su - [sudo] password for username:  root@lp:~# id uid=0(root) gid=0(root) groups=0(root) root@lp:~# pwd /root root@lp:~# Ubuntu 18.10 gnome extensions stop working after hibernation After upgrading to 18.10 I am experiencing very strange behaviour of gnome extensions. After my laptop goes into hibernation they all switch off and enabling them back on  doesn't help: nothing changes and when I refresh the page they are disabled again.   The only way to turn them back on is to reinstall them. How to prove that a compact set in a Hausdorff topological space is closed? Is $f(a)\!=\!0\!=\!f(b)\Rightarrow (x\!-\!a)(x\!-\!b)\mid f(x)\,$ true if $\,a=b?\ $ [Double Factor Theorem] Does C# have an equivalent to JavaScript's encodeURIComponent()? In JavaScript:  encodeURIComponent("©√") == "%C2%A9%E2%88%9A"   Is there an equivalent for C# applications? For escaping HTML characters I used:  txtOut.Text = Regex.Replace(txtIn.Text, @"[\u0080-\uFFFF]",     m =&gt; @"&amp;#" + ((int)m.Value[0]).ToString() + ";");   But I'm not sure how to convert the match to the correct hexadecimal format that JS uses. For example this code:  txtOut.Text = Regex.Replace(txtIn.Text, @"[\u0080-\uFFFF]",     m =&gt; @"%" + String.Format("{0:x}", ((int)m.Value[0])));   Returns "%a9%221a" for "©√" instead of "%C2%A9%E2%88%9A". It looks like I need to split the string up into bytes or something.  Edit: This is for a windows app, the only items available in System.Web are: AspNetHostingPermission, AspNetHostingPermissionAttribute, and AspNetHostingPermissionLevel. How can I make Ubuntu 18.04 / 18.10 desktop use Unity (be like Ubuntu 14.04)? How to convert an instance of std::string to lower case Using $\text{n}^{\text{th}}$ root of unity  $$\large\left(e^{\frac{2ki\pi}{n}}\right)^{n} = 1$$  Prove that   $$\prod_{k=1}^{n-1}\sin\frac{k \pi}{n} = \frac{n}{2^{n-1}}$$ Is it possible to upgrade the graphics card in modern laptops? As there's no definitive answer to this, and I would prefer not to be too specific about particular models, what are the things that determine whether this is possible or not?   What expansion slots would the laptop require to do this? How can you find out if a motherboard/chipset supports upgrades?  Is heat an issue? Could it void the warranty? How is battery life affected? Continuous function from $(0, 1]$ onto $(0, 1)$? Disable password request from suspend - 18.04 I need to know a word which means:     "negligence shown by a person in performing a duty, or a responsibility, or any given task."   or,      "A person who is negligent in performing their duties/responsibilities."   One possible choice is the use of word "delinquent". Is there any other word?  Please provide the usage of suggested word in a sentence also. Tracking very long shot with no points in common between first and last frame Is it possible to track an handheld shot (there is already an answer on here about tripod shots: ) that doesn't have any visible points in common between the first and the last frame? As an example, imagine a shot of someone driving in a car for thirty minutes. Obviously everything from the first couple of seconds won't be there anymore at minute 15. What is the simplest way to convert char[] to/from tchar[] in C/C++(ms)? This seems like a pretty softball question, but I always have a hard time looking up this function because there seem there are so many variations regarding the referencing of char and tchar. Will the Android app be receiving any future updates? Will there be a new version of the Android app? It's been without any update for a long time and it doesn't seem to be working really well.