1. 程式人生 > >xml去掉多餘空格

xml去掉多餘空格

在xml的解析中,經常遇到因為xml不規範導致的錯誤

如:The element type is required in the attribute-list declaration. 等問提就是xml格式不規範,只需要將標籤之間的空格去除即可

//去掉所有的換行符 空格 製表符

String xml="<xxx></xxx>";
Pattern p = Pattern.compile(">(\\s*|\n|\t|\r)<");  
Matcher m = p.matcher(xml);  
xml = m.replaceAll("><");  

用><代替>    <,去除中間的空格