title: how to modify xml tag specific value in java?
body: <p>i am new to work on xml.i have used an xml file as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
        - &lt;root&gt;
        - &lt;key&gt;
             &lt;Question&gt;Is the color of the car&lt;/Question&gt; 
             &lt;Ans&gt;black?&lt;/Ans&gt; 
         &lt;/key&gt;
       - &lt;key&gt;
             &lt;Question&gt;Is the color of the car&lt;/Question&gt; 
             &lt;Ans&gt;black?&lt;/Ans&gt; 
         &lt;/key&gt;
       - &lt;key&gt;
             &lt;Question&gt;Is the news paper&lt;/Question&gt; 
             &lt;Ans&gt;wallstreet?&lt;/Ans&gt; 
        &lt;/key&gt;
      - &lt;key&gt;
            &lt;Question&gt;fragrance odor&lt;/Question&gt; 
            &lt;Ans&gt;Lavendor?&lt;/Ans&gt; 
       &lt;/key&gt;
     - &lt;key&gt;
            &lt;Question&gt;Is the baggage collector available&lt;/Question&gt; 
           &lt;Ans /&gt; 
       &lt;/key&gt;
    &lt;/root&gt;
  </code></pre>
  
  <p>from the above xml i would like to change only </p>
  
  <pre><code>             &lt;Ans&gt;wallstreet?&lt;/Ans&gt; as &lt;Ans&gt;WonderWorld&lt;/Ans&gt;.
  </code></pre>
  
  <p>how can i change wallstreet? as WonderWorld? through my java application.</p>
  
  <p>i have written java method as shown below:</p>
  
  <pre><code>  public void modifyNodeval(){
   try{
          DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
          Document doc = docBuilder.parse(new File(path));
          Node nodes1 = doc.getElementsByTagName("*");
          for(int j=0;j&lt;nodes1.getLength();j++)
          {
              //Get the staff element by tag name directly
              Node nodes = doc.getElementsByTagName("key").item(j);
              //loop the staff child node
              NodeList list = nodes.getChildNodes();
  
              for (int i = 0; i != list.getLength(); ++i)
              {
                  Node child = list.item(i);
  
                 if (child.getNodeName().equals("Ans")) {
  
                     child.getFirstChild().setNodeValue("WonderWorld") ;
                     System.out.println("tag val modified success fuly");
                 }
  
             }
         }
         TransformerFactory transformerFactory = TransformerFactory.newInstance();
         Transformer transformer = transformerFactory.newTransformer();
         DOMSource source = new DOMSource(doc);
         StreamResult result = new StreamResult(path);
         transformer.transform(source, result);
     }
     catch (Exception e) 
     {
         e.printStackTrace();
     }
  }
  </code></pre>
  
  <p>by using above code i am able to change the all  tag text as wonder world but my intention is i want change only wallstreet? as WonderWorld.</p>
  
  <p>any body please help me.....</p>