Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

xml transformer issue how to fix #8

Open
HaasJona opened this issue May 11, 2018 · 5 comments
Open

xml transformer issue how to fix #8

HaasJona opened this issue May 11, 2018 · 5 comments

Comments

@HaasJona
Copy link

Any idea how to fix/workaround the xml transformer issue so that it behaves mostly the same as in java 8 (no additional whitespace added)? A workaround might be removing the exisiting whitespace first, but I have no idea how to do that.

@nipafx
Copy link
Member

nipafx commented May 15, 2018

I have not looked into that. It is likely that our tests that discovered that behavior change are still deactivated on Java 9+ (can't check right now). If you can provide a fix, that would be highly appreciated. 😃

@HaasJona
Copy link
Author

I found that removing unecessary whitespace when reading the file is an okay workaround for my usecase.

I did this:

		final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setNamespaceAware(true);
		factory.setValidating(true);
		factory.setAttribute("http://xml.org/sax/features/validation", Boolean.TRUE);
		factory.setIgnoringElementContentWhitespace(true); // ←!!!

when reading

and I also added

transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

when writing, so that previous Java versions match the output of the new Java versions.

@nipafx
Copy link
Member

nipafx commented May 16, 2018

Do you want to add that as a workaround for your specific case to the README? PRs welcome. 😉

@tristanlins
Copy link

Unfortunately the factory.setIgnoringElementContentWhitespace(true); workaround does not work with Java 11 anymore :-(

@HaasJona
Copy link
Author

Still works for me, I believe.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants