title: Trying to remove XML tags based on attribute value using Jsoup java
body: <p>im trying to remove xml elements based on attribute value kind='lib. when i print out the file the content is removed but when i write to file and open the file i see extra elements are removed that are not given in the condition. i can see kind ='con' is removed but i would need to keep this</p>
  <p>my code</p>
  <pre><code>Path classPath=Paths.get(prop.getProperty(&quot;testClasspath&quot;));
          String pomFile = new String(Files.readAllBytes(classPath),StandardCharsets.UTF_8);
           
           Document doc_classpath = Jsoup.parse(pomFile,&quot;&quot;,Parser.xmlParser());
  
  
              //for pretty xml formating
              doc_classpath.outputSettings().prettyPrint(false);
            
     
              doc_classpath.select(&quot;[kind=lib]&quot;).remove();
              System.out.println(doc_classpath.toString());
      
              Files.write(Paths.get(prop.getProperty(&quot;testClasspath&quot;)),doc_classpath.toString().getBytes());
  </code></pre>
  <p>my xml current</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;classpath&gt;
          &lt;classpathentry kind=&quot;src&quot; output=&quot;target/classes&quot; path=&quot;src/java&quot;&gt;
                  &lt;attributes&gt;
                          &lt;attribute name=&quot;optional&quot; value=&quot;true&quot;/&gt;
                          &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot;/&gt;
                  &lt;/attributes&gt;
          &lt;/classpathentry&gt;
          &lt;classpathentry excluding=&quot;**&quot; kind=&quot;src&quot; output=&quot;target/classes&quot; path=&quot;src/resources&quot;&gt;
                  &lt;attributes&gt;
                          &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot;/&gt;
                  &lt;/attributes&gt;
          &lt;/classpathentry&gt;
          &lt;classpathentry kind=&quot;src&quot; output=&quot;target/test-classes&quot; path=&quot;src/test/java&quot;&gt;
                  &lt;attributes&gt;
                          &lt;attribute name=&quot;optional&quot; value=&quot;true&quot;/&gt;
                          &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot;/&gt;
                          &lt;attribute name=&quot;test&quot; value=&quot;true&quot;/&gt;
                  &lt;/attributes&gt;
          &lt;/classpathentry&gt;
          &lt;classpathentry excluding=&quot;**&quot; kind=&quot;src&quot; output=&quot;target/test-classes&quot; path=&quot;src/test/resources&quot;&gt;
                  &lt;attributes&gt;
                          &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot;/&gt;
                          &lt;attribute name=&quot;test&quot; value=&quot;true&quot;/&gt;
                  &lt;/attributes&gt;
          &lt;/classpathentry&gt;
          &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/test/lib_local/activation-1.1.jar&quot;/&gt;
          &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/test/lib_local/ahClient-1.0_A41.jar&quot;/&gt;
          &lt;classpathentry kind=&quot;lib&quot; path=&quot;C:/test/lib_local/ahClient-1.0_A51.jar&quot;/&gt;
                 &lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8&quot;&gt;
                  &lt;attributes&gt;
                          &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot;/&gt;
                  &lt;/attributes&gt;
          &lt;/classpathentry&gt;
  &lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER&quot;&gt;
      &lt;attributes&gt;
          &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot;/&gt;
          &lt;attribute name=&quot;org.eclipse.jst.component.dependency&quot; value=&quot;/WEB-INF/lib&quot;/&gt;
      &lt;/attributes&gt;
  &lt;/classpathentry&gt;
  &lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.jst.j2ee.internal.web.container&quot;/&gt;
  &lt;classpathentry kind=&quot;con&quot; path=&quot;org.eclipse.jst.j2ee.internal.module.container&quot;/&gt;
  &lt;classpathentry kind=&quot;output&quot; path=&quot;target/classes&quot;/&gt;
  </code></pre>
  <p>output xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;classpath&gt;
      &lt;classpathentry kind=&quot;src&quot; output=&quot;target/classes&quot; path=&quot;src/java&quot;&gt;
          &lt;attributes&gt;
              &lt;attribute name=&quot;optional&quot; value=&quot;true&quot; /&gt;
              &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot; /&gt;
          &lt;/attributes&gt;
      &lt;/classpathentry&gt;
      &lt;classpathentry excluding=&quot;**&quot; kind=&quot;src&quot; output=&quot;target/classes&quot; path=&quot;src/resources&quot;&gt;
          &lt;attributes&gt;
              &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot; /&gt;
          &lt;/attributes&gt;
      &lt;/classpathentry&gt;
      &lt;classpathentry kind=&quot;src&quot; output=&quot;target/test-classes&quot; path=&quot;src/test/java&quot;&gt;
          &lt;attributes&gt;
              &lt;attribute name=&quot;optional&quot; value=&quot;true&quot; /&gt;
              &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot; /&gt;
              &lt;attribute name=&quot;test&quot; value=&quot;true&quot; /&gt;
          &lt;/attributes&gt;
      &lt;/classpathentry&gt;
      &lt;classpathentry excluding=&quot;**&quot; kind=&quot;src&quot; output=&quot;target/test-classes&quot; path=&quot;src/test/resources&quot;&gt;
          &lt;attributes&gt;
              &lt;attribute name=&quot;maven.pomderived&quot; value=&quot;true&quot; /&gt;
              &lt;attribute name=&quot;test&quot; value=&quot;true&quot; /&gt;
          &lt;/attributes&gt;
      &lt;/classpathentry&gt;
  </code></pre>
  <p>when i execute the programme i see extra cml tags removed. Any help with this?</p>