title: Parse an android XML layout file using XmlPullParser
body: <p>This question has been asked a lot in different situations, but for over a day I can't find an answer that fixes my error.</p>
  
  <p>I have an xml file called <code>activity_single_touch.xml</code> inside <code>res/layout</code> folder.
  This file is used to add views like buttons, but I also want to be able to edit it "live" (the user can draw on screen).</p>
  
  <p>Following android guide, I tried using <code>XmlPullParser</code> in my main java code like so:</p>
  
  <pre><code>public class SingleTouchActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // setContentView(R.layout.activity_single_touch);
          XmlPullParser parser = getResources().getXml(R.xml.activity_single_touch);
          AttributeSet attributes = Xml.asAttributeSet(parser);
          setContentView(new SingleTouchEventView(this, attributes));
      }
  
      public class SingleTouchEventView extends View {
          ...
      }
  }
  </code></pre>
  
  <p>The rest of the code uses <code>OnDraw</code> and <code>OnTouchEvent</code> to draw a path according to user movement, and then invalidate.</p>
  
  <p>The error I am getting at the moment is "cannot resolve symbol 'xml'".
  How can I fix this?</p>
  
  <p>p.s:
  Things I have tried (and have failed):
  Using</p>
  
  <pre><code>XmlPullParser parser =getResources().getXml(R.layout.activity_single_touch);
  </code></pre>
  
  <p>and getting "expected xml element" error,</p>
  
  <p>I've read over </p>
  
  <p><a href="http://www.edumobile.org/android/search-interface/" rel="nofollow noreferrer">this guide</a><br>
   <a href="https://stackoverflow.com/questions/36541226/how-to-use-your-own-xml-resource-in-android/36541601#36541601">these answeres</a><br>
  <a href="https://stackoverflow.com/questions/21123811/android-xml-cannot-be-resolved-or-is-not-in-the-field/21124121#21124121">these as well</a><br>
   <a href="https://stackoverflow.com/questions/10996136/passing-xml-resource-to-xmlreader/10996202#10996202">use of streams</a><br>
   <a href="https://stackoverflow.com/questions/8579138/how-to-use-getresources-getxml/8579533">use of context</a><br>
   <a href="https://stackoverflow.com/questions/17634611/how-to-get-xml-from-local-res-raw-folder">moving the xml file to a different folder(could not move it)</a><br>
  <a href="https://stackoverflow.com/questions/28373487/getting-started-with-xmlpullparser">this guide</a>   </p>
  
  <p>and of course searching google and some more stackOverflow questions and answers.</p>