{"record":{"id":"b5d395af6186703d","repo":"MiniMax-AI/skills","slug":"docx-does-not-contain-word-document-xml","errorCode":null,"errorMessage":"DOCX does not contain word/document.xml","messagePattern":"DOCX does not contain word/document\\.xml","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs","lineNumber":13,"sourceCode":"using System.IO.Compression;\nusing System.Xml;\nusing System.Xml.Schema;\n\nnamespace MiniMaxAIDocx.Core.Validation;\n\npublic class XsdValidator\n{\n    public ValidationResult Validate(string docxPath, string xsdPath)\n    {\n        using var zip = ZipFile.OpenRead(docxPath);\n        var entry = zip.GetEntry(\"word/document.xml\")\n            ?? throw new InvalidOperationException(\"DOCX does not contain word/document.xml\");\n\n        using var stream = entry.Open();\n        using var reader = new StreamReader(stream);\n        var xmlContent = reader.ReadToEnd();\n\n        return ValidateXml(xmlContent, xsdPath);\n    }\n\n    public ValidationResult ValidateXml(string xmlContent, string xsdPath)\n    {\n        var result = new ValidationResult();\n        var settings = new XmlReaderSettings();\n\n        var schemaSet = new XmlSchemaSet();\n        schemaSet.Add(null, xsdPath);\n        settings.Schemas = schemaSet;\n        settings.ValidationType = ValidationType.Schema;\n        settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs#L1-L31","documentation":"`zip.GetEntry(\"word/document.xml\") ?? throw new InvalidOperationException(\"DOCX does not contain word/document.xml\")` in `XsdValidator.Validate`. Identical structural expectation as the business-rule validator: the XSD validation target is `word/document.xml`, so a package missing it cannot be schema-validated. The throw happens before any XSD logic runs.","triggerScenarios":"Passing a path to a non-`.docx` ZIP, a corrupt/truncated `.docx`, a `.dotx`/`.docm` with a non-standard layout, or a file where `word/document.xml` was stripped.","commonSituations":"Wrong file type passed in (legacy `.doc`, plain ZIP), corrupt download, or an OPC package that is technically valid but not a Word document body.","solutions":["Verify the file is a real `.docx` and opens in Word.","Convert legacy `.doc` to `.docx` before validating.","Re-acquire the file if it may be corrupt; check the entry list with `zip.Entries` for diagnosis.","Guard: `if (zip.GetEntry(\"word/document.xml\") is null) return InvalidResult(\"not a docx\");`."],"exampleFix":"// before\nxsdValidator.Validate(\"notes.zip\", \"schema.xsd\"); // throws\n\n// after\nif (zip.GetEntry(\"word/document.xml\") is null)\n    return ValidationResult.Fail(\"File is not a valid .docx\");\nxsdValidator.Validate(\"notes.docx\", \"schema.xsd\");","handlingStrategy":"validation","validationCode":"static bool IsOpenableDocx(string path)\n{\n    using var zip = ZipFile.OpenRead(path);\n    return zip.GetEntry(\"word/document.xml\") is not null;\n}\n\nif (!IsOpenableDocx(docxPath))\n    return ValidationResult.Fail(\"Not a valid .docx; cannot run XSD validation.\");","typeGuard":"bool ContainsDocumentXml(string docxPath)\n{\n    using var zip = ZipFile.OpenRead(docxPath);\n    return zip.GetEntry(\"word/document.xml\") is not null;\n}","tryCatchPattern":"try\n{\n    return xsdValidator.Validate(docxPath, xsdPath);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"document.xml\"))\n{\n    return ValidationResult.Fail($\"{docxPath} is not a valid .docx package.\");\n}","preventionTips":["Gate XSD validation behind a structural pre-check for `word/document.xml`.","Convert legacy `.doc` to `.docx` before validation.","Inspect `zip.Entries` during onboarding to confirm the package shape.","Return a structured ValidationResult instead of throwing for user-supplied files."],"tags":["csharp","openxml","docx","zip","xsd","validation","document-structure"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}