I want to write a method for a Java class. The method accepts as input a string of XML data as given below.
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<name> <> Programming in ANSI C <> </name>
<author> <> Balaguruswamy <> </author>
<comment> <> This comment may contain xml entities such as &, < and >. <> </comment>
</book>
<book>
<name> <> A Mathematical Theory of Communication <> </name>
<author> <> Claude E. Shannon <> </author>
<comment> <> This comment also may contain xml entities. <> </comment>
</book>
<!-- This library contains more than ten thousand books. -->
</library>
The XML string contains a lot of substring starting and ending with <>. The substring may contain XML entities such as >, <, &, ' and ". The method need to replace them with >, <, &. ' and " respectively.
Is there any regular-expression method in Java to accomplish this task?