Java 致命错误:字符引用“&;#org.xml.sax.SAXParseException;

Java 致命错误:字符引用“&;#org.xml.sax.SAXParseException;,java,xml,sax,saxparser,Java,Xml,Sax,Saxparser,有 <BATCHNAME>&#4; Any</BATCHNAME> 如何解决这个问题?查看&nnnn模式是十进制形式的Unicode代码点,这意味着相当于Unicode:传输结束,这是一个非打印字符 因此,我认为解析器在这种情况下失败是正确的 事实上,如果您查看com.sun.org.apache.xerces.internal.impl.XMLScanner#scanCharReferenceValue,您可以看到它引用了com.sun.org.ap

 <BATCHNAME>&#4; Any</BATCHNAME> 
如何解决这个问题?

查看
&nnnn
模式是十进制形式的Unicode代码点,这意味着

相当于Unicode:
传输结束
,这是一个非打印字符

因此,我认为解析器在这种情况下失败是正确的

事实上,如果您查看
com.sun.org.apache.xerces.internal.impl.XMLScanner#scanCharReferenceValue
,您可以看到它引用了
com.sun.org.apache.xerces.internal.util.XMLChar#在这里是有效的

/**
 * Returns true if the specified character is valid. This method
 * also checks the surrogate character range from 0x10000 to 0x10FFFF.
 * <p>
 * If the program chooses to apply the mask directly to the
 * <code>CHARS</code> array, then they are responsible for checking
 * the surrogate character range.
 *
 * @param c The character to check.
 */
public static boolean isValid(int c) {
    return (c < 0x10000 && (CHARS[c] & MASK_VALID) != 0) ||
           (0x10000 <= c && c <= 0x10FFFF);
} // isValid(int):boolean

是,字符不是有效的xml。但是我只希望在某些情况下使用xml中的这些字符,应该有任何方法来添加/允许这些字符..?一种方法是转到xml 1.1,它添加了对U+0001以后的支持,但不确定您是否可以控制传入的xml文档?请参阅
应该是
";
。如果它确实是
;
,请将XML作为文本读取,并将XML版本修补为1.0版中禁止使用的控制字符的版本1.1。
/**
 * Returns true if the specified character is valid. This method
 * also checks the surrogate character range from 0x10000 to 0x10FFFF.
 * <p>
 * If the program chooses to apply the mask directly to the
 * <code>CHARS</code> array, then they are responsible for checking
 * the surrogate character range.
 *
 * @param c The character to check.
 */
public static boolean isValid(int c) {
    return (c < 0x10000 && (CHARS[c] & MASK_VALID) != 0) ||
           (0x10000 <= c && c <= 0x10FFFF);
} // isValid(int):boolean