title: update text in HTML page using parser
body: <p>I always gets error in the <code>middlebitparent.replaceWith(nodespan);</code>
  in the following code which is written in jsoup to navigate the HTML doc and change the background color of word "In"</p>
  
  <pre><code>Elements divs= doc.select("div");
            for(Element div : divs)
            {
                 if (div.hasText())
                  {
                      int pos = div.text().indexOf("In");
                      out.println(pos);
                      if (pos &gt;= 0)
                          {
                          Element span = doc.createElement("span");
                          span.attr("style", "background-color: yellow");
                          TextNode text = new TextNode(div.text(),"");
                        //  String[] words = div.split("\\s", 4);
                       TextNode middlebit = text.splitText(4);
                       TextNode endbit=text.splitText("In".length());           
                        Node middleclone = middlebit.clone();
                        span.appendChild(middleclone);
                        Node nodespan=span.clone();
                        Node middlebitparent = middlebit.parent();
                        middlebitparent.replaceWith(nodespan);
  </code></pre>
  
  <p>The error says </p>
  
  <pre><code>java.lang.NullPointerException
      org.apache.jsp.Page1_jsp._jspService(Page1_jsp.java:177)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  </code></pre>
  
  <h2>UPDATE:</h2>
  
  <p>Is there any parser which can update text in text node in an easy way</p>