gpt4 book ai didi

java - fatal error : Character reference "&# org. xml.sax.SAXParseException;

转载 作者:太空宇宙 更新时间:2023-11-04 09:46:45 25 4
gpt4 key购买 nike

 <BATCHNAME>&#4; Any</BATCHNAME> 
我的 xml 请求中的

标记的值包含“”字符。如果没有这些字符,我的代码可以完美运行,但在某些情况下我有这些字符。它给了我以下错误

[Fatal Error] :144:28: Character reference "&# org.xml.sax.SAXParseException; lineNumber: 144; columnNumber: 28; Character reference "&# at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) at d.b(AllCommonTasks.java:277) at...

我需要验证这些字符

我正在尝试这段代码=>

try {                      

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();

URLConnection urlConnection = new URL(urlString).openConnection();
urlConnection.addRequestProperty("Accept", "application/xml");
urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) ");
Document doc = db.parse(urlConnection.getInputStream());
doc.getDocumentElement().normalize();

str = convertDocumentToString(doc);


}catch(Exception e){
System.err.println("In exception 1");
e.printStackTrace();
}

我该如何解决这个问题?

最佳答案

查看Wikipedia page for XML and HTML entity references ,遵循 &#nnnn; 模式的实体引用是十进制形式的 Unicode 代码点,这意味着  将等效于 Unicode U+0004 : END OF TRANSMISSION 这是一个非打印字符。

所以我认为解析器在这种情况下失败是正确的。

事实上,如果您查看 com.sun.org.apache.xerces.internal.impl.XMLScanner#scanCharReferenceValue 的源代码,您可以看到它在此处引用 com.sun.org.apache.xerces.internal.util.XMLChar#isValid:

/**
* 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

关于java - fatal error : Character reference "&# org. xml.sax.SAXParseException;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55335528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com