用dom4j解析XML字符串时出现org.dom4j.DocumentException异常

用dom4j解析XML字符串时出现org.dom4j.DocumentException错误?因为XML字符串的开头多了一个换行?去除xml字

用dom4j解析XML字符串时出现org.dom4j.DocumentException错误

?

因为XML字符串的开头多了一个换行

?

去除xml字符串中空格、换行、制表等的方法如下:

import java.util.regex.Matcher;

import java.util.regex.Pattern;

?

?

Pattern p = Pattern.compile(“\\s*|\t|\r|\n”);
String str="I am a, I am Hello ok, \n new line ffdsa!";
System.out.println("before:"+str);
Matcher m = p.matcher(str);
String after = m.replaceAll("");
System.out.println("after:"+after);