title: Advanced XML language injections
body: <p>I have some xml files in which I embed the python code and I'm using language injection for it. It is sort of working but not for 100%. Here is an example</p>
  
  <pre><code>
  &lt;frm&gt;
  
  ...
  
   &lt;script&gt;
  
    &lt;code name = "__init__(self, *args, **kwargs)"&gt;
  
     &lt;![CDATA[
  
  # Python code
  
  super().__init__(*args, **kwargs)
  
  ]]&gt;
  
    &lt;/code&gt;
  
   &lt;/script&gt;
  
  &lt;/frm&gt;
  
  </code></pre>
  
  <p>The above xml should be "translated" to the following python code:</p>
  
  <pre><code>
  class Form1(FormBase):
  
   def __init__(self, *args, **kwargs):
  
    # Python code
  
    super().__init__(*args, **kwargs)
  
  ...
  
  </code></pre>
  
  <p>Now, my first question, is it possible to define language injection for the full path of the tag? I mean <code>frm/script/code</code>? Because it is working only if I specify "code" as local name in xml language injection.</p>
  
  <p>For <code>&lt;script&gt;</code> I have defined prefix as "class Form1(FormBase):", but don't know if it's working, because hovering on "self" in the method definition doesn't show anything, only that is isn't used anywhere.</p>
  
  <p>The <code>&lt;code&gt;</code> tag is working OK (I guess). But the injection for the <code>&lt;code&gt;'s</code> <code>CDATA</code> isn't working as a part of the function body. I have it defined as "code" as a local name in xml injection.</p>
  
  <p>Indentations - Could I somehow specify, that the code in the <code>&lt;code&gt;</code> tag should be idented for some number of spaces/tabs?</p>
  
  <p>Could I somehow view the "generated" code from the language injections?</p>
  
  <p>Or could I somehow make a plugin which would create the language injection I need?</p>
  
  <p>(The question was posted on pycharm forums, but no reply <a href="https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006457580-Advanced-XML-language-injections-" rel="nofollow noreferrer">https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006457580-Advanced-XML-language-injections-</a>)</p>
  
  <p>Thanks</p>
  
  <p><strong>edit:</strong></p>
  
  <p>So I have tried to make a plugin using <code>LanguageInjector</code> and also <code>MultiHostInjector</code> but no luck. The python indentations are really problematic and I couldn't "generate" code that would have right indentations. What I would really need is to have option to pre-process the whole xml, generate the python code and then map the code to the XML parts (as I'm doing in my application). If anyone know it it is possible, please let me know.</p>