title: How to extend doc() functionality in saxon
body: <p>I am looking for an extension of doc() functionality currently available in SAXON in a way that it will read XML not from filesystem or from http network, but from memory, where I have those xmls.</p>
  
  <p>The way I want to use it is like:</p>
  
  <pre><code>mydoc('id')/root/subroot/@myattr
  </code></pre>
  
  <p>or</p>
  
  <pre><code>doc('mydoc://id')/root/subroot/@myattr
  </code></pre>
  
  <p>What I have considered so far:</p>
  
  <ol>
  <li>use queryEvaluator.setContextItem() - does not solve my use case as I can have multiple XML sources in one query</li>
  <li>register some own URL scheme protocol into Java - seems to me like overkill and I have never done this</li>
  <li>write own ExtensionFunction - seems to be the right way so far, but i am confused whether I should use ExtensionFunction or rather ExtensionFunctionDefinition. Also I am littel bit confused by Doc_1 and Doc Saxonica source  code as it uses Atomizer and other unknown internall stuff. </li>
  </ol>
  
  <p><strong>So the questions are:</strong></p>
  
  <ol>
  <li>Is it variant 3 the best one (in the means of simplicity) or would you recommend some other approach ?</li>
  <li>Is it OK to use ExtensionFunction and return XdmNode from my in-memory xmls ? It seems to me it should work, but I really do not want to step into some edge cases or saxon minefield.</li>
  </ol>
  
  <p>Any comment from experienced Saxon user will be appretiated.</p>