views:

35

answers:

0

Hi

I am working on a case where I need to clean invalid XML characters I receive from a SharePoint web service. I know fixing the source is the right thing to do - however this issue has been reported back in 2008, and I have yet to find that Microsoft has released a patch for it.

For now, I call the Web Service using the Provider interface from JAX-WS. I receive the Source with the returned XML just fine, but I'm stuck trying to find a way to transform the source to valid XML DOM.

I get an exception complaining about the illegal XML character every time I try something like the following pseudo code:

public void xmlTranform(javax.xml.transform.Source source) {
     StreamResult sr = new StreamResult(new java.io.StringWriter());
     Transformer tf = TransformerFactory.newInstance().newTransformer();
     tf.transform(source, sr);
     ...

Would it be possible to create a custom FilterReader and insert it into the Transformation?

Or could I customize the Marshaller maybe?

What would be the best way to inject code into the transformation to filter out those invalid characters?