title: JDOM XPath Getting Inner Element without Namespace
body: <p>I have an xml like this:</p>
  
  <pre><code>&lt;root
      xmlns:gl-bus="http://www.xbrl.org/int/gl/bus/2006-10-25"
      xmlns:gl-cor="http://www.xbrl.org/int/gl/cor/2006-10-25" &gt;
      &lt;gl-cor:entityInformation&gt;
          &lt;gl-bus:accountantInformation&gt;
              ...............
          &lt;/gl-bus:accountantInformation&gt;
      &lt;/gl-cor:entityInformation&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>All I want to extract the element "gl-cor:entityInformation" from the root with its child elements. However, I do not want the namespace declarations come with it. </p>
  
  <p>The code is like this:</p>
  
  <pre><code>XPathExpression&lt;Element&gt; xpath = XPathFactory.instance().compile("gl-cor:entityInformation", Filters.element(), null, NAMESPACES);
  Element innerElement = xpath.evaluateFirst(xmlDoc.getRootElement());
  </code></pre>
  
  <p>The problem is that the inner element holds the namespace declarations now. Sample output:</p>
  
  <pre><code>&lt;gl-cor:entityInformation xmlns:gl-cor="http://www.xbrl.org/int/gl/cor/2006-10-25"&gt;
      &lt;gl-bus:accountantInformation xmlns:gl-bus="http://www.xbrl.org/int/gl/bus/2006-10-25"&gt;
      &lt;/gl-bus:accountantInformation&gt;
  &lt;/gl-cor:entityInformation&gt;
  </code></pre>
  
  <p>This is how I get xml as string:</p>
  
  <pre><code>public static String toString(Element element) {
      Format format = Format.getPrettyFormat();
      format.setTextMode(Format.TextMode.NORMALIZE);
      format.setEncoding("UTF-8");
  
      XMLOutputter xmlOut = new XMLOutputter(); 
      xmlOut.setFormat(format);
      return xmlOut.outputString(element);
  }
  </code></pre>
  
  <p>As you see the namespace declarations are passed into the inner elements. Is there a way to get rid of these declarations without losing the prefixes? </p>
  
  <p>I want this because later on I will be merging these inner elements inside another parent element and this parent element has already those namespace declarations.</p>