{"record":{"id":"bffd118235d988b5","repo":"dianping/cat","slug":"xqst0047","errorCode":"XQST0047","errorMessage":"\"{uri}\": duplicate target namespace","messagePattern":"\"(.+?)\": duplicate target namespace","errorType":"error_code","errorClass":"StaticError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":1808,"sourceCode":"            }\n            return this;\n        },\n        getAvailableModuleNamespaces: function(){\n            return this.root.availableModuleNamespaces;\n        },\n        getPrefixByNamespace: function(uri){\n            return this.root.namespaces[uri].prefix;\n        },\n        addNamespace: function (uri, prefix, pos, type) {\n            if(prefix === '' && type === 'module') {\n                throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos);\n            }\n            if (uri === '') {\n                throw new StaticError('XQST0088', 'empty target namespace in module import or module declaration', pos);\n            }\n            var namespace = this.getNamespace(uri);\n            if (namespace && namespace.type === type && type !== 'declare' && !namespace.override) {\n                throw new StaticError('XQST0047', '\"' + uri + '\": duplicate target namespace', pos);\n            }\n            namespace = this.getNamespaceByPrefix(prefix);\n            if (namespace && !namespace.override) {\n                throw new StaticError('XQST0033', '\"' + prefix + '\": namespace prefix already bound to \"' + namespace.uri + '\"', pos);\n            }\n\n            namespace = this.namespaces[uri];\n            this.namespaces[uri] = {\n                prefix: prefix,\n                pos: pos,\n                type: type\n            };\n\n            if (namespace) {\n                throw new StaticWarning('W02', '\"' + uri + '\" already bound to the \"' + namespace.prefix + '\" prefix', pos);\n            }\n\n        },","sourceCodeStart":1790,"sourceCodeEnd":1826,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L1790-L1826","documentation":"XQST0047 is thrown when the same target namespace URI is imported/declared twice with the same type. addNamespace() looks up the URI in the scope chain; if an existing entry has the same type, the type is not 'declare', and the entry is not marked override, the second binding is rejected as a duplicate target namespace.","triggerScenarios":"Two 'import module namespace a = \"U\";' and 'import module namespace b = \"U\";' statements, or the same module imported twice under different prefixes; also duplicate schema imports of the same namespace.","commonSituations":"Merged query files that each import the same module; copy-paste duplication; refactoring that adds an import without checking existing ones at the top of the prolog.","solutions":["Delete one of the duplicate import declarations and keep a single prefix for that namespace.","If different prefixes are genuinely needed, check whether the existing entry supports override before relying on rebinding.","Remember 'declare' bindings (e.g. declare namespace) do not conflict with imports of the same URI — only same-type duplicates do."],"exampleFix":"// before\nimport module namespace a = \"http://example.org/mod\";\nimport module namespace b = \"http://example.org/mod\";\n\n// after\nimport module namespace a = \"http://example.org/mod\";","handlingStrategy":"validation","validationCode":"// Pre-check a prolog for duplicate same-type namespace targets\nvar seen = {};\nprologImports.forEach(function(imp) {\n  var key = imp.type + '|' + imp.uri;\n  if (seen[key]) { warn('Duplicate ' + imp.type + ' of ' + imp.uri); }\n  seen[key] = true;\n});","typeGuard":null,"tryCatchPattern":"if (e.code === 'XQST0047') {\n  highlight(e.pos, 'Namespace already imported — remove the duplicate import');\n}","preventionTips":["Keep all imports at the top of the prolog in one block so duplicates are visible.","Lint for duplicate import URIs in CI for generated or merged XQuery."],"tags":["xquery","namespace","module-import","duplicate"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}