title: Replace all strings "<" and ">" in a variable with "&lt;" and "&gt;"
body: <p>I am currently trying to code an input form where you can type and format a text for later use as XML entries. In order to make the HTML code XML-readable, I have to replace the code brackets with the corresponding symbol codes, i.e. <code>&lt;</code> with <code>&amp;lt;</code> and <code>&gt;</code> with <code>&amp;gt;</code>.</p>
  
  <p>The formatted text gets transferred as HTML code with the variable <em>inputtext</em>, so we have for example the text</p>
  
  <pre><code>The &lt;b&gt;Genji&lt;/b&gt; and the &lt;b&gt;Heike&lt;/b&gt; waged a long and bloody war.
  </code></pre>
  
  <p>which needs to get converted into</p>
  
  <pre><code>The &amp;lt;b&amp;gt;Genji&amp;lt;/b&amp;gt; and the &amp;lt;b&amp;gt;Heike&amp;lt;/b&amp;gt; waged a long and bloody war.
  </code></pre>
  
  <p>I tried it with the .replace() function:</p>
  
  <pre><code>inputxml = inputxml.replace("&lt;", "&amp;lt;");       
  inputxml = inputxml.replace("&gt;", "&amp;gt;");
  </code></pre>
  
  <p>But this would just replace the first occurrence of the brackets. I'm pretty sure I need some sort of loop for this; I also tried using the <code>each()</code> function from jQuery (a friend recommended I looked at the jQuery package), but I'm still new to coding in general and I have troubles getting this to work.</p>
  
  <p>How would you code a loop which would replace the code brackets within a variable as described above?</p>
  
  <p><strong>Additional information</strong></p>
  
  <p>You are, of course, right in the assumption that this is part of something larger. I am a graduate student in Japanese studies and currently, I am trying to visualize information about Japenese history in a more accessible way. For this, I am using the Simile Timeline API developed by MIT grad students. You can see a working test of a timeline on <a href="http://www.michaeljuerges.de/timelines/timeline-test.html">my homepage</a>.</p>
  
  <p>The Simile Timeline uses an API based on AJAX and Javascript. If you don't want to install the AJAX engine on your own server, you can implement the timeline API from the MIT. The data for the timeline is usually provided either by one or several XML files or JSON files. In my case, I use XML files; you can have a look at the XML structure in <a href="http://www.michaeljuerges.de/timelines/tengu.xml">this example</a>.</p>
  
  <p>Within the timeline, there are so-called "events" on which you can click in order to reveal additional information within an info bubble popup. The text within those info bubbles originates from the XML source file. Now, if you want to do some HTML formatting within the info bubbles, you cannot use code bracket because those will just be displayed as plain text. It works if you use the symbol codes instead of the plain brackets, however.</p>
  
  <p>The content for the timeline will be written by people absolutely and totally not accustomed to codified markup, i.e. historians, art historians, sociologists, among them several persons of age 50 and older. I have tried to explain to them how they have to format the XML file if they want to create a timeline, but they occasionally slip up and get frustrated when the timeline doesn't load because they forgot to close a bracket or to include an apostrophe. </p>
  
  <p>In order to make it easier, I have tried making an easy-to-use input form where you can enter all the information and format the text WYSIWYG style and then have it converted into XML code which you just have to copy and paste into the XML source file. Most of it works, though I am still struggling with the conversion of the text markup in the main text field.</p>
  
  <p>The conversion of the code brackets into symbol code is the last thing I needed to get working in order to have a working input form.</p>