Inserting XML words to MySQL using Java Pattern and Matcher -


I want to keep track of word usage in group chat using the MySQL database. The message sent in the insertword method is an XML string currently. The XML string may contain special characters such as & amp; Apos; and & amp; Quot; . What is a better way to use String.replace to convert XML formatted strings in general?

If my message is: I & amp; Apos; I bad, but they are & amp; Apos; ; & Quot; Good & amp; Quot;

How can I convert it to: I'm bad, but they are not "good"

My code apos 2 times and 2 times how do i fix it?

  pattern p = Pattern.compile ("[\\ w '] +"); Prepared position entry WordStmt = connection.prepareStatement ("Include words (word, count) values ​​(?, 1)" + "duplicate key update calculation = count + 1"); Public Zero insert word (string msg) {msg = msg.toLowerCase (); Try {MATTTER M = p.matcher (msg); Whereas (m.find ()) {string word = msg.substring (m.start (), m.end ()); InsertWordStmt.setString (1, word); InsertWordStmt.executeUpdate (); }} Hold (SQLException e) {e.printStackTrace (); }}    

Try adding double quote matches

  Pattern P = Pattern.compile ("[\ [w \"] + ");   

Edit after comments

  Place of msg (msg) to replace toLowerCase () instead of ("& amp;" "" ""). ("& Amp; Bid,", "\" ");    

Comments