languagetool-org/languagetool · error · RuntimeException
Could not parse XML: + completeWikiContent
Error message
Could not parse XML: + completeWikiContent
What it means
Parsing guard in getRevisionContent: the XML fetched from the MediaWiki API could not be parsed by the SAX parser, i.e. the response is not the expected MediaWiki export/rev format (API error page, HTML, truncated body).
Source
Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/WikipediaQuickCheck.java:229
return wikiContent
.replaceAll("\\[\\[[a-z]{2,6}:.*?\\]\\]", "")
// category links
.replaceAll(
"\\[\\[:?(Category|Categoria|Categoría|Catégorie|Kategorie):.*?\\]\\]", "")
// file links, keeps alt and caption
.replaceAll(
"(File|Fitxer|Fichero|Ficheiro|Fichier|Datei):.*?\\.(png|jpg|svg|jpeg|tiff|gif|PNG|JPG|SVG|JPEG|TIFF|GIF)\\|((thumb|miniatur)\\|)?((right|left)\\|)?", "");
}
private MediaWikiContent getRevisionContent(String completeWikiContent) {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser;
RevisionContentHandler handler = new RevisionContentHandler();
try {
saxParser = factory.newSAXParser();
saxParser.parse(new InputSource(new StringReader(completeWikiContent)), handler);
} catch (Exception e) {
throw new RuntimeException("Could not parse XML: " + completeWikiContent, e);
}
return new MediaWikiContent(handler.getRevisionContent(), handler.getTimestamp());
}
private MultiThreadedJLanguageTool getLanguageTool(Language lang) throws IOException {
MultiThreadedJLanguageTool lt = new MultiThreadedJLanguageTool(lang);
enableWikipediaRules(lt);
for (String disabledRuleId : disabledRuleIds) {
lt.disableRule(disabledRuleId);
}
if (ngramDir != null) {
lt.activateLanguageModelRules(ngramDir);
}
disableSpellingRules(lt);
return lt;
}
private void enableWikipediaRules(JLanguageTool lt) {View on GitHub (pinned to 2e990059ce)
Solutions
- Inspect the fetched XML around the failure point
- Check the MediaWiki API endpoint and parameters are correct
- Handle API error responses before parsing
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/WikipediaQuickCheck.java:229 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/c011570390c20a91.
Report an issue: GitHub.