Hello Christian,
Thank you for your response. Because of it, I made a more simplified example. Then I discussed it with a colleague, who asked some questions that lead me to a solution.
The simplified example is: ``` @Requires(Permission.NONE) @Deterministic @ContextDependent public Value element() throws QueryException, ParserConfigurationException { // Make a DOM document. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document domDocument = builder.newDocument(); // Construct an element <test xmlns:test="http://test" test:attr="test"/>. Element outputElement = domDocument.createElement("test"); outputElement.setAttributeNS("http://test", "test:attr", "test"); // The namespace declaration must be set as a (pseudo-)attribute. outputElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:test", "http://test"); // Returning `outputElement`, or converting it to BaseX first, loses the attribute namespace URI. //return JavaCall.toValue(inputElement, queryContext, null); // Make the new element the root element of the document. This is needed to get attribute namespaces. domDocument.appendChild(outputElement); // Converting the root element to BaseX does not work: //Value bxResult = JavaCall.toValue(domDocument.getDocumentElement(), queryContext, null); // Converting the document to BaseX and taking the root element works: ANode bxResult = (ANode)JavaCall.toValue(domDocument, queryContext, null); // Return the root element. return bxResult.childIter().next(); } ``` As stated in the comment, returning a DOM document (or converting it to a BaseX node first) will lose the attribute namespace URI. My colleague asked if the namespace was present in the document node, and from there I developed the above code, which retains the namespace URI. The comments show the steps I took and what does not work.
Best regards, Nico