alibaba/spring-cloud-alibaba · error · IOException
The xml content parse error.
Error message
The xml content parse error.
What it means
Thrown by NacosXmlPropertySourceParser.parseXml2Map when DocumentBuilder.parse(resource.getInputStream()) or the subsequent node walk raises any Exception. The catch-all wraps it as IOException("The xml content parse error.") carrying e.getCause(). This loader is used when a Nacos config file has the .xml extension; the content must be well-formed XML parseable by the default DocumentBuilder.
Source
Thrown at spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/parser/NacosXmlPropertySourceLoader.java:113
}
return Collections.singletonList(
new OriginTrackedMapPropertySource(name, nacosDataMap, true));
}
private @Nullable Map<String, Object> parseXml2Map(Resource resource) throws IOException {
Map<String, Object> map = new LinkedHashMap<>(32);
try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document document = documentBuilder.parse(resource.getInputStream());
if (null == document) {
return null;
}
parseNodeList(document.getChildNodes(), map, "");
}
catch (Exception e) {
throw new IOException("The xml content parse error.", e.getCause());
}
return map;
}
private void parseNodeList(NodeList nodeList, Map<String, Object> map,
String parentKey) {
if (nodeList == null || nodeList.getLength() < 1) {
return;
}
parentKey = parentKey == null ? "" : parentKey;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
String value = node.getNodeValue();
value = value == null ? "" : value.trim();
String name = node.getNodeName();
name = name == null ? "" : name.trim();
if (StringUtils.isEmpty(name)) {View on GitHub (pinned to 115d590110)
Solutions
- Validate the published XML is well-formed (open it in a browser or xmllint --noout file.xml) and fix structural errors.
- Ensure the dataId extension matches the actual content; move non-XML content to a .properties or .yaml dataId.
- Remove any DOCTYPE declarations or unsupported entity references that the default DocumentBuilder disallows.
- Re-save with UTF-8 (no BOM) encoding.
Example fix
<!-- before (malformed) --> <config> <key>value </config> <!-- after --> <config> <key>value</key> </config>
Defensive patterns
Strategy: try-catch
Validate before calling
// Before publishing/binding, validate the XML is well-formed. DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); DocumentBuilder b = f.newDocumentBuilder(); b.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
Type guard
static boolean isWellFormedXml(String xml) {
try {
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.newDocumentBuilder().parse(new java.io.ByteArrayInputStream(xml.getBytes(java.nio.charset.StandardCharsets.UTF_8)));
return true;
} catch (Exception e) {
return false;
}
} Try / catch
try {
// load the xml config
} catch (IOException e) {
if ("The xml content parse error.".equals(e.getMessage())) {
// re-validate the published XML in the Nacos console and fix structure
}
} Prevention
- Validate XML in the Nacos console before publishing (well-formedness).
- Match the dataId extension to the content type.
- Save as UTF-8 without BOM and avoid unsupported DOCTYPE/entity declarations.
When it happens
Trigger: A Nacos config published with an .xml dataId whose content is not well-formed XML — unclosed tags, invalid nesting, BOM/encoding issues, stray characters, a DOCTYPE/entity reference the default factory rejects, or non-XML text accidentally saved under an xml dataId.
Common situations: Editing config in Nacos console and saving malformed XML; pasting a properties/yaml snippet into an xml dataId; encoding/BOM from an editor; XXE-guard changes in the JDK tightening DocumentBuilderFactory defaults.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- ConfigService is not initialized
- Invalid date format
- NacosConfigKeysChangeListener must be marked as a single par
- @NacosConfigListener must be over a method with a single p
- ApplicationContext not set
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/5b5d95a1e54c20eb.
Report an issue: GitHub.