title: Autocompleting XML values and attributes in Ace editor
body: <p>I'm looking to autocomplete XML tags and attributes. The valid values will come from the server. For example,</p>
  
  <p>If I have a tag such as,</p>
  
  <pre><code>&lt;status&gt;&lt;/status&gt;
  </code></pre>
  
  <p>and my cursor is inside the open and closing tags, I'd like to hit <code>control + space</code> and have only valid values appear in the drop-down. Such as: <code>ok</code>, <code>error</code>, <code>warning</code>, ...</p>
  
  <p>Similarly for attributes,</p>
  
  <pre><code>&lt;status audience=""&gt;ok&lt;/status&gt;
  </code></pre>
  
  <p>If my cursor has focus inside the quotes I'd like only valid audiences to appear in the drop-down when hitting <code>control + space</code>.</p>
  
  <p>Here's what I have so far. This completer completes words I'm typing. I just can't figure out how to know what kind of tag I'm inside and how to send specific values for that tag or attribute.</p>
  
  <p>Any ideas or examples to point me to? Thanks, /w</p>
  
  <pre><code>function loadEditor() {
      var langTools = ace.require("ace/ext/language_tools");
      editor = ace.edit("editor");
      editor.setOptions({
          enableBasicAutocompletion: true,
          enableLiveAutocompletion: true,
          enableSnippets: true,
      });
      editor.getSession().setMode("ace/mode/xml");
  
      var myCompleter = {
          getCompletions: function(editor, session, pos, prefix, callback) {
              if (prefix.length === 0) {
                  callback(null, []);
                  return;
              }                    
              $.getJSON("completions.php?a=completions&amp;prefix=" 
                      + prefix + "&amp;content=" + session, function(json) {
                  callback(null, json.map(function(c) {
                      console.log("value: " + c.value);
                      return {value: c.value, caption: c.caption, meta: c.meta, score:c.score};
                  }));
              })
          }
      };
      langTools.addCompleter(myCompleter);
  }
  </code></pre>