title: How do I remove a soap envelope using JDOM and return the remainder of the XML as a String?
body: <p>I have the following XML with a soap envelope as a Java <code>String</code>:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;soap:Body&gt;
      &lt;MyStartElement xmlns="http://www.example.com/service"&gt;
        ...
  </code></pre>
  
  <p>I want to be able to use hamcrest and the xml-matchers extension <a href="https://code.google.com/p/xml-matchers" rel="nofollow">https://code.google.com/p/xml-matchers</a> on it later on, but first I want to get rid of the soap envelope.</p>
  
  <p>How can I remove the soap envelope using JDOM 2.0.5 and get the remaining XML (i.e. starting with the <code>MyStartElement</code> as root) back as a <code>String</code>?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>SAXBuilder builder = new SAXBuilder();
  Document document = (Document) builder.build(toInputStream(THE_XML));
  Namespace ns = Namespace
             .getNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
  Namespace ns2 = Namespace
              .getNamespace("http://www.example.com/service");
  Element response = document.getRootElement()
              .getChild("Body", ns)
              .getChild("MyStartElement", ns2);
  System.out.println(new XMLOutputter().outputString(new Document(response)));
  </code></pre>
  
  <p>This returns: <em>Exception in thread "main" org.jdom2.IllegalAddException: The Content already has an existing parent "soap:Body"</em></p>
  
  <p>I had a similar setup, where I called</p>
  
  <pre><code>System.out.println(new XMLOutputter().outputString(new Document(response)));
  </code></pre>
  
  <p>but that returned the whole XML including soap envelope.</p>
  
  <p>What would I have to do to strip the soap envelope from my XML using JDOM and get a <code>String</code> back?</p>
  
  <p><strong>Bonus questions:</strong> </p>
  
  <ul>
  <li>Is there a good introduction/tutorial to JDOM 2? (The website seems to only have the
  JavaDocs, which makes it a bit difficult to get started...)</li>
  <li>I realise using JDOM is probably a bit over the top for this one. Any suggestions on how to do this in an easier way?</li>
  </ul>