Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying URI of the default namespace for root element #541

Open
cowtowncoder opened this issue Jul 25, 2022 · 2 comments
Open

Allow specifying URI of the default namespace for root element #541

cowtowncoder opened this issue Jul 25, 2022 · 2 comments
Labels
adding-declarations Issues related to adding non-content declarations to XML output most-wanted Tag to indicate that there is heavy user +1'ing action

Comments

@cowtowncoder
Copy link
Member

Although namespace declarations will be automatically written as needed, sometimes it'd be nice to be able to explicitly specify root element namespace binding for the "default" namespace (one with no prefix).

Note that this is similar to #207 but specifically refers to ability to specify desired default namespace URI as opposed to namespace prefix for explicit namespaces.

@cowtowncoder cowtowncoder added adding-declarations Issues related to adding non-content declarations to XML output most-wanted Tag to indicate that there is heavy user +1'ing action 2.14 labels Jul 25, 2022
@cowtowncoder cowtowncoder removed the 2.14 label Nov 17, 2023
@rjrudin
Copy link

rjrudin commented Apr 9, 2024

This would be particularly useful for a scenario where a user has a string of JSON and wishes to convert it to XML with a custom root namespace. My understanding is that I want to read the JSON into an ObjectNode and then use an XmlMapper to output XML. Something like this would be a welcome addition:

String json = "...";
ObjectNode node = objectMapper.readTree(json);
String xml = xmlMapper.writer()
    .withRootName("myRootElement")
    .withRootNamespace("http://example.org") // or simply .withNamespace("...")
    .writeValueAsString(node);

@cowtowncoder
Copy link
Member Author

Default namespace handling can be tricky in many ways, but yes, I can see this one use case being one where it'd make sense as JsonNode otherwise will not have namespace information.

Although it does depend a bit on how underlying Stax XmlStreamWriter does things -- if it is aware of default namespace being written, it will then add explicit REMOVAL of namespace declaration for all elements :-(
(as it will match NamespaceURI to use and sees request for "empty" namespace on writeStartElement()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adding-declarations Issues related to adding non-content declarations to XML output most-wanted Tag to indicate that there is heavy user +1'ing action
Projects
None yet
Development

No branches or pull requests

2 participants