how to set standalone directive

105 views
Skip to first unread message

Scott Shipp

unread,
Aug 14, 2020, 2:07:25 PM8/14/20
to Woodstox User Mailing List
Hi everyone,

Sorry if this is an easy question that I've somehow overlooked in the docs, but I've already been through all the Jackson modules and the Woodstox module looking for an answer as well as searching all the usual places like the wiki pages, issues, and such.

How would one go about setting standalone="yes" directive in the declaration?

The reason I'm asking here is a quick grep of the woodstox code shows a lot of results for "standalone" so it would appear that maybe Woodstox is the one that would handle this.

Our use case is that we're trying to mirror an existing API in a new application, and the XML response from our application needs to match. The existing application writes the declaration as

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

whereas so far we only see

<?xml version="1.0" encoding="UTF-8" ?>

from ours.

Thanks in advance for any ideas about getting the standalone directive in there. 

Tatu Saloranta

unread,
Aug 14, 2020, 2:31:52 PM8/14/20
to Scott Shipp, Woodstox User Mailing List
On Fri, Aug 14, 2020 at 11:07 AM Scott Shipp <scott...@gmail.com> wrote:
Hi everyone,

Sorry if this is an easy question that I've somehow overlooked in the docs, but I've already been through all the Jackson

No, I don't think it's a simple question (and much less on with an obvious answer).
So this is a good place to ask.
 
modules and the Woodstox module looking for an answer as well as searching all the usual places like the wiki pages, issues, and such.

How would one go about setting standalone="yes" directive in the declaration?

The reason I'm asking here is a quick grep of the woodstox code shows a lot of results for "standalone" so it would appear that maybe Woodstox is the one that would handle this.

Our use case is that we're trying to mirror an existing API in a new application, and the XML response from our application needs to match. The existing application writes the declaration as

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

whereas so far we only see

<?xml version="1.0" encoding="UTF-8" ?>

from ours.

Thanks in advance for any ideas about getting the standalone directive in there. 

So, now.... Woodstox can provide this via Stax (and Stax2) API, with one of overloads of XMLStreamWriter.writeStartDocument() (or similar). The challenge is how to do that via jackson-dataformat-xml; unfortunately there is no clean way to do that yet. Issue that is related is this:


and I was hoping to address this for 2.12, but not sure if I will have time.
Problem is mostly due to huge load of all the work related to Jackson, and the need to figure out specific configurability mechanic to use for this format-specific extension.

Until this configurability option is added, I think there are still 2 potential ways to get it done:

1. Create XMLStreamWriter manually, call `writeStartDocument()` explicitly,  pass that to XmlMapper.writeValue(...) (I think there are a few overloads there).
2. Construct basic `Writer` (or `OutputStream`), write XML declaration, pass that to `writeValue()` of XmlMapper or ObjectWriter.

the one concern there, however, is that mapper may try to call `writeStartDocument()` on its own.

Come to think of that, there probably should also be `ToXmlGenerator.Feature.WRITE_START_DOCUMENT` (enabled by default), disabling of which would explicitly prevent XML declaration from being written.
That I should be able to add quite easily as a new Feature in 2.12.
I will create an issue for that.

-+ Tatu +-


 

--
You received this message because you are subscribed to the Google Groups "Woodstox User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to woodstox-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/woodstox-user/0ecb7ade-65f3-458b-8e56-40fc6a18be4fn%40googlegroups.com.

Tatu Saloranta

unread,
Aug 14, 2020, 2:35:36 PM8/14/20
to Scott Shipp, Woodstox User Mailing List
.... and I should have first checked if such a feature ALREADY exists. Looks like I already decided in 2010 that it was a good idea, so there is already:

ToXmlGenerator.Feature.WRITE_XML_DECLARATION

which can be disabled in the way to prevent dual writing (backend has no means to check if declaration has been written already, unfortunately).

-+ Tatu +-

Scott Shipp

unread,
Aug 14, 2020, 4:12:22 PM8/14/20
to Woodstox User Mailing List
Great! Thanks so much for all the helpful resources!
Reply all
Reply to author
Forward
0 new messages