-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
JibxMarshaller - provide access to jibx's writeDocType [SPR-6907] #11572
Comments
Arjen Poutsma commented Unfortunately, the marshalRootElement method on MarshallingContext is protected, so we can't use it in the JibxMarshaller. I could not find any alternatives, do you have any suggestions? |
Ben Davies commented Ah, sorry Arjen. That should have been marshallingContext.startDocument(this.encoding, this.standalone, outputStream);
marshallingContext.getXmlWriter().writeDocType(...);
marshallingContext.marshalDocument(graph); |
Arjen Poutsma commented Thanks for the pointer, I've added four new properties on the JibxMarshaller (docTypeRootElementName, docTypeSystemId, etc). If set, a doctype declaration is written. |
Ben Davies commented Many thanks Arjen. |
Ben Davies commented Hi Arjen, I don't think your implementation is quite right. XML requires that if one uses a PUBLIC ID, one also provide a SYSTEM ID. Take XHTML String 1.0 as an example <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "-//W3C//DTD XHTML 1.0 Strict//EN" is the public ID
Take a look at JiBX's implementation which respects this: /**
* Write DOCTYPE declaration to document.
*
* @param name root element name
* @param sys system ID (<code>null</code> if none, must be
* non-<code>null</code> for public ID to be used)
* @param pub public ID (<code>null</code> if none)
* @param subset internal subset (<code>null</code> if none)
* @throws IOException on error writing to document
*/
public void writeDocType(String name, String sys, String pub, String subset)
throws IOException {
indentAfterFirst();
writeMarkup("<!DOCTYPE ");
writeMarkup(name);
writeMarkup(' ');
if (sys != null) {
if (pub == null) {
writeMarkup("SYSTEM \"");
writeMarkup(sys);
} else {
writeMarkup("PUBLIC \"");
writeMarkup(pub);
writeMarkup("\" \"");
writeMarkup(sys);
}
writeMarkup('"');
}
if (subset != null) {
writeMarkup('[');
writeMarkup(subset);
writeMarkup(']');
}
writeMarkup('>');
} Cheers, |
Arjen Poutsma commented Woops, reopening |
Arjen Poutsma commented I removed that assertion. |
Ben Davies commented Thanks again for the quick turn around. |
Ben Davies opened SPR-6907 and commented
The current jibx oxm marshaller hides everything away from the user, making it impossible to utilise all of jibx's feature.
I need to be able to add a doctype to my marshalled document, but this is not possible with spring's current implementation.
The change would involved replacing all instances of
with something like:
Cheers,
Ben
Affects: 3.0.1
Referenced from: commits 9d1c3fa, 894875c
The text was updated successfully, but these errors were encountered: