我想为
Java类编写一个方法.该方法接受如下给出的XML数据串作为输入.
<?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>
XML字符串包含许多以<>开头和结尾的子字符串.子串可以包含XML实体,例如>,<,&,'和“.该方法需要用& gt;,& lt;,& amp;.&和&来代替它们.分别. Java中是否有任何正则表达式方法来完成此任务?