Error about invalid XML characters on Java

前端 未结 4 684
野趣味
野趣味 2020-12-03 08:09

Parsing an xml file on Java I get the error:

An invalid XML character (Unicode: 0x0) was found in the element content of the document.

The xml c

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 08:37

    fixed with this code:

    String cleanXMLString = null;
    Pattern pattern = null;
    Matcher matcher = null;
    pattern = Pattern.compile("[\\000]*");
    matcher = pattern.matcher(dirtyXMLString);
    if (matcher.find()) {
       cleanXMLString = matcher.replaceAll("");
    }
    

提交回复
热议问题