{"record":{"id":"c0d2ec532ef5c87c","repo":"OtterMind/Chat2DB","slug":"error-parsing-xml-document","errorCode":null,"errorMessage":"Error parsing XML document","messagePattern":"Error parsing XML document","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ncx/XMLUtils.java","lineNumber":54,"sourceCode":"    public static Document parseDocument(InputStream is) {\n        return parseDocument(new InputSource(is));\n    }\n\n    public static Document parseDocument(java.io.Reader is) {\n        return parseDocument(new InputSource(is));\n    }\n\n    public static Document parseDocument(InputSource source) {\n        try {\n            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\n            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);\n            dbf.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", true);\n            dbf.setFeature(\"http://xml.org/sax/features/external-general-entities\", false);\n            dbf.setFeature(\"http://xml.org/sax/features/external-parameter-entities\", false);\n            DocumentBuilder xmlBuilder = dbf.newDocumentBuilder();\n            return xmlBuilder.parse(source);\n        } catch (Exception er) {\n            throw new RuntimeException(\"Error parsing XML document\", er);\n        }\n    }\n\n    public static Document createDocument() {\n        try {\n            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\n            DocumentBuilder xmlBuilder = dbf.newDocumentBuilder();\n            return xmlBuilder.newDocument();\n        } catch (Exception er) {\n            throw new RuntimeException(\"Error creating XML document\", er);\n        }\n    }\n\n    public static Element getChildElement(Element element,  String childName) {\n        if (element == null) {\n            return null;\n        }\n        for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ncx/XMLUtils.java#L36-L72","documentation":"RuntimeException 'Error parsing XML document' from XMLUtils.parseDocument(InputSource) when DocumentBuilder.parse fails — SAXParseException (malformed XML), ParserConfigurationException, or an I/O error mid-read. The factory is hardened with secure processing and doctype disallowal, so a DOCTYPE in the input will also land here.","triggerScenarios":"Parsing an NCX/DBP/JSON-import XML file that is not well-formed, has an unexpected encoding, or contains a DOCTYPE/external entity (blocked by FEATURE_SECURE_PROCESSING + disallow-doctype-decl).","commonSituations":"Corrupt or truncated export file; file saved with a different encoding; file authored with an XML editor that inserts a DOCTYPE; XXE attempt blocked by secure processing.","solutions":["Open the file in an XML validator and fix well-formedness errors.","Remove any DOCTYPE declaration; the parser explicitly disallows it for security.","Re-export the file from its source tool if it is malformed.","Check encoding matches the XML declaration."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// strip DOCTYPE and validate well-formedness before parse\nString content = java.nio.file.Files.readString(java.nio.file.Path.of(fileName));\nif (content.contains(\"<!DOCTYPE\")) throw new IllegalArgumentException(\"DOCTYPE not allowed\");","typeGuard":null,"tryCatchPattern":"try { return XMLUtils.parseDocument(inputSource); }\ncatch (RuntimeException e) {\n    // message is generic 'Error parsing XML document'; inspect cause for SAXParseException line/col\n    throw new ConfigImportException(\"malformed config file: \" + e.getCause().getMessage(), e);\n}","preventionTips":["Validate XML well-formedness before import.","Remove DOCTYPE declarations; the parser disallows them by design.","Match file encoding to the XML declaration."],"tags":["xml","parsing","security","import"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}