請掌舵我。SAXParseException - 實體「szlig」被引用,但未聲明。 XML驗證錯誤?
我有我驗證的XML字符串。有時候,文檔沒有通過驗證。因爲有一個詞「Weiß」。如何解決這個和其他類似的錯誤?我明白髮誓信上「ß」。但奇怪的行爲,第一次拋出錯誤,但第二次,同一行已經是有效的。我使用xerces庫。
org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 17; The entity "szlig" was referenced, but not declare
驗證
SchemaFactory factory = new XMLSchemaFactory();
try {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(WTConstants.XSD_VALIDATOR);
if (xmlString.startsWith("\uFEFF")) {
xmlString = xmlString.substring(1);// remove BOM
}
Schema schema = factory.newSchema(new StreamSource(stream));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new StringReader(xmlString)));
} catch (SAXException | IOException e) {
logger.error("Validation error: ", e);
isXmlValid = false;
}
感謝。
可能的重複[http://stackoverflow.com/questions/15858914/entity-was-referenced-but-not-declared](http://stackoverflow.com/questions/15858914/entity-was-referenced-但沒有聲明) –
我認爲沒有。它不能解決我的問題.. – JDev