-
Sep 8th, 2009, 10:43 AM
#1
Numeric Entity handling with XmlOptions
Hi there,
I'm having a tricky time trying to transform a British pound symbol (£) in my XML to a "numeric entity" - i.e. & # 1 6 3 ; (as shown but with no spaces).
I have no problem doing this in a simple main method test case - here are the relevant lines of code:
// Set up
XmlOptionCharEscapeMap escapes = new XmlOptionCharEscapeMap();
escapes.addMapping('£', XmlOptionCharEscapeMap.DECIMAL);
XmlOptions opts = new XmlOptions();
opts.setSaveSubstituteCharacters(escapes);
And where xmlOfferType is an XmlObject with one element that contains a British pound symbol, I can see my successful transformation like this:
StringWriter sw = new StringWriter();
xmlOfferType.save(sw, opts);
System.out.println("Saved result: " + sw.toString());
Hoorah! So then to Spring-WS to Springify my solution. I find that the XmlOptionsFactoryBean won't quite cut it for me as there is no way I can see of setting the character escape map - so I write a couple of adapters - and to cut a long story short, end up with an apparently working implementation. Just to prove it, I put the following code in the invokeInternal() method of my end point:
//DEBUG CODE
XmlOptions opts = ((XmlBeansMarshaller) getMarshaller()).getXmlOptions();
logger.debug("XML Text for outer XML Bean, applying options object:\n" + xmlBeanResponse.xmlText(opts));
... and all is well in my log: I can see my XML text filled with numeric entities where there would otherwise be British pound symbols. So my Spring wiring all seems fine: the marshaller knows about my idiosyncratic XMLOptions.
And yet - when I target the web service with my test client (SOAP-UI), the pound signs come through as pound signs - not transformed at all.
I conclude that either:
(1) The marshalling process isn't applying XMLOptions as per my debug code, so no transformation is taking place.
(2) Spring-WS is applying some sort of un-transformation post-marshalling.
I would be very grateful for any input on this at all, and more than happy to post any code required.
Thanks in anticipation,
David Bridgewater (Developer, UK).
-
Nov 11th, 2009, 04:19 PM
#2
We're having a similar issue - trying to tweak the SAVE_CDATA_LENGTH_THRESHOLD and SAVE_CDATA_ENTITY_COUNT_THRESHOLD via XmlOptionsFactoryBean.
Works fine when we roll our own XmlOptions and apply the transform manually, but does NOT work automatically via spring-ws (1.5.4).
Has anyone run into this before?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules