【转】org.jdom.IllegalDataException: The data ""is not legal for a JDOM attribute: 0xb is not a legal 异常
今天用jdom生成xml,在操作中出现了 org.jdom.IllegalDataException: The data ""is not legal for a JDOM attribute: 0xb is not a legal 异常,仔细跟踪发现,在原有的组建对象的属性中出现了异常字符,通过下面的替换,再重新转换成String,trim后正常。
char [] xmlChar = paragraph.toCharArray(); for (int i=0; i < xmlChar.length; ++i) { if (xmlChar[i] > 0xFFFD) { //直接替换掉0xb xmlChar[i] =' '; } else if (xmlChar[i] < 0x20 && xmlChar[i] != 't' & xmlChar[i] != 'n' & xmlChar[i] != 'r') { //直接替换掉0xb xmlChar[i] =' ' ; } }