title: Find all 'more or less than' characters which is not tags in xml
body: <p>I need a regex to find all '&lt;' or '>' which is not xml-tags. </p>
  
  <p>Example:</p>
  
  <pre><code>&lt;tag1&gt;W&lt;E&gt;&lt;E&lt;/tag1&gt;Z&lt;&gt;S
  </code></pre>
  
  <p>Should find </p>
  
  <pre><code>&lt;&gt;&lt;&lt;&gt;
  </code></pre>
  
  <p>Example:</p>
  
  <pre><code>&lt;tag1&gt;W&lt;E&gt;&lt;E&lt;/E&gt;&lt;/tag1&gt;Z&lt;&gt;S
  </code></pre>
  
  <p>Should find </p>
  
  <pre><code>&lt;&lt;&gt;
  </code></pre>
  
  <p>So, any hits where '&lt;' or '>' is not in a tag (yes we alos have al self-closing tags which should be taken into consideration :)</p>
  
  <p><strong>Edit #2:</strong>
  What I want to do in the end is to replace all matches with the html-encoded values.</p>
  
  <p><strong>Edit #3:</strong></p>
  
  <p>So what I want to do is from a text containing HTML with some additional tags (very few known tags) get all '&lt;' and '>' which is not included in the tags.</p>
  
  <p>Example (the bold ones I want to find so I can replace them with their encoded values):</p>
  
  <pre><code>&lt;div&gt;
    &lt;a href="link"&gt;Link with &lt; characters&lt;/a&gt;
    &lt;knownTag&gt;Text with character &gt;&lt;/knownTag&gt;
    &lt;knownTag&gt;Text &lt; again &gt;&lt;/knownTag&gt;
  &lt;div&gt;
  </code></pre>
  
  <p>Result should be:</p>
  
  <pre><code>&lt;div&gt;
    &lt;a href="link"&gt;Link with &amp;lt; characters&lt;/a&gt;
    &lt;knownTag&gt;Text with character &amp;gt;&lt;/knownTag&gt;
    &lt;knownTag&gt;Text &amp;lt; again &amp;gt;&lt;/knownTag&gt;
  &lt;div&gt;
  </code></pre>
  
  <p>Any idea on how to solve this problem?</p>