Search code examples
javaxmlquotescastor

Converting xml attribute double quotes to single quotes (utility needed, pref java)


I have a seriously annoying problem. My company uses castor to marshall and unmarshall xml. I'm working on integrating with another company and it looks like their xml parser requires attributes to be single-quoted. Castor is hardcoded to use double quotes. Whoops!

Does anyone know of a utility (preferrably a java library) which can safely convert these quotes?

Simple regexps are not a preferred solution because it will become extremely complicated and buggy when trying to fix escaped double quotes and unescaped single quotes inside the attribute values themselves. Plus I'd rather not spend the time writing and debugging such a util if one already exists.

Thanks Alastair


Solution

  • I don't think you're going to find an off-the-shelf serializer that does this. My suggestion (if you can't persuade your business partner to adopt XML standards) would be to find an open-source serializer (e.g. the Saxon one) and customize it.