on 01-20-2010 9:48 PM
Hello,
I have the following issue with XML character escaping. The following characters need to be escaped: < > & ' and ".
When I receive the message in the integration engine < and > are already escaped as expected. However ' and " are not.
I have implemented a Java Mapping to replace " and ' with it escape characters & quot; and & apos;
Problem however is that ALL " are escaped (including the XML prolog xml version = "1.0" )
The XML then results in a parsing error when executing a test for the mapping.
Do you have any idea how I can resolve this?`
Thank you very much!
Edited by: Florian Guppenberger on Jan 20, 2010 10:49 PM
Edited by: Florian Guppenberger on Jan 20, 2010 10:49 PM
Usually there is no need for escaping ' and ", as the XML is valid anyway.
I think you should use a SAX parser. The SAX parser divides the XML in tags, namespaces and elements.
So you can do the String replace routines on element level only.
Regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Depending on how big your msgs are (or how often they arrive), if performance overhead is acceptable, then you could :
XML->1 String->apply reg ex to replace only " and ' within 2 tags ...
But this is only a dirty way of doing what a custom SAX parser would do (more elegantly and efficiently) ...
Chris
When the message arrives everything is escaped, however after executing the XSLT mapping ' and &qot; are de-escaped again.
I think both the SAX parster or the regex are a good approach to solve the problem.
Christophe, do you have any sample code available for the replacement with a regex? Guess that I have to find the relevanr substrings first, and then having a replace all run on that. But it would be very helpful to see a code sample there....
Thank you!
Edited by: Florian Guppenberger on Jan 21, 2010 2:20 PM
Edited by: Florian Guppenberger on Jan 21, 2010 4:02 PM
Hello,
@Fariha: Unfortunately there is the need to escape ' and '" in my case. Problem is that I use a 2-step mapping (graphical / XSLT)
' and " are already escaped when calling the XSLT mapping. However the output of the XSLT contains ' and " again.
Our business partner however does not accept these two un-escaped characters
@Christophe: Would be great to see some sample code with regular patterns. This seems to be a little bit tricky as I have to apply a pattern to get only element values, then replace the characters and then somehow move it back to the original string......
At least this is what I was thinking of.
> @Fariha: Unfortunately there is the need to escape ' and '" in my case. Problem is that I use a 2-step mapping (graphical / XSLT)
> ' and " are already escaped when calling the XSLT mapping. However the output of the XSLT contains ' and " again.
I wonder whether there is an option in XSLT to prevent de-escaping. Maybe you check an XSLT refernce first before you create a Java mapping.
Hi Florian,
You can change the Unicode in Adapter engine from UTF8 to ISO... it supports &
the other solution is you can replace your & with some constant (like!!!!@!!!!!) using java mapping and at the receiver end you replace !!!!@!!!! with & to show the end user the exact string.
Thanks,
Sunil Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Florian,
why reinvent the wheel ?:)
type : escaping java in google and take any of the many examples as your java mapping
escaping is totally not PI specific
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
>>>yes, there are a couple of examples out there, however the problem is that I just want to have the " characters escaped that are part of the element value and not all others (such " characters that are part of the prolog or attributes)...
and do you think the prolog is PI/XI specific ?
Regards,
Michal Krawczyk
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.