What are invalid characters in XML

后端 未结 15 1607
时光说笑
时光说笑 2020-11-22 03:23

I am working with some XML that holds strings like:

This is a string

Some of the strings that I am passing to the

15条回答
  •  梦如初夏
    2020-11-22 04:25

    In the Woodstox XML processor, invalid characters are classified by this code:

    if (c == 0) {
        throw new IOException("Invalid null character in text to output");
    }
    if (c < ' ' || (c >= 0x7F && c <= 0x9F)) {
        String msg = "Invalid white space character (0x" + Integer.toHexString(c) + ") in text to output";
        if (mXml11) {
            msg += " (can only be output using character entity)";
        }
        throw new IOException(msg);
    }
    if (c > 0x10FFFF) {
        throw new IOException("Illegal unicode character point (0x" + Integer.toHexString(c) + ") to output; max is 0x10FFFF as per RFC");
    }
    /*
     * Surrogate pair in non-quotable (not text or attribute value) content, and non-unicode encoding (ISO-8859-x,
     * Ascii)?
     */
    if (c >= SURR1_FIRST && c <= SURR2_LAST) {
        throw new IOException("Illegal surrogate pair -- can only be output via character entities, which are not allowed in this content");
    }
    throw new IOException("Invalid XML character (0x"+Integer.toHexString(c)+") in text to output");
    

    Source from here

提交回复
热议问题