XML Parsing fails due to special character [message #1781051] |
Wed, 31 January 2018 15:45  |
Eclipse User |
|
|
|
In my application if any there is any special character and if I try to save file then parsing fails and nothing get saved(size of file is 1KB). If I use property
XMLResource.OPTION_SKIP_ESCAPE to skpi processing of values having special character, which leads to data loss.
Can someone help me overcome this?
|
|
|
Re: XML Parsing fails due to special character [message #1781323 is a reply to message #1781051] |
Mon, 05 February 2018 23:52   |
Eclipse User |
|
|
|
You've not mentioned what's special about the character, so I can only guess. Of course you should specifying an character encoding that can encode all your characters, i.e., org.eclipse.emf.ecore.xmi.XMLResource.setEncoding(String) with the value "UTF-8" in your resource factory. You should use OPTION_SKIP_ESCAPE only if there are known to be no characters that need escaping. You should use OPTION_SKIP_ESCAPE_URI mapped to FALSE if your URIs for cross references contain characters that need escaping; but best you avoid that by not using resources with things like <, >, or & in the URI. And finally, there are the control characters, <= 0x1F. XML 1.0 cannot serialize many of these, but XML 1.1 can, so you could use org.eclipse.emf.ecore.xmi.XMLResource.setXMLVersion(String) with the value 1.1 to serialize these. But no version of XML can serialize the null character 0x0. If you need that , you'll have to define your own EDataType (that wraps java.util.String), and does encoding and decoding.
|
|
|
Re: XML Parsing fails due to special character [message #1781331 is a reply to message #1781323] |
Tue, 06 February 2018 02:19  |
Eclipse User |
|
|
|
Hi
EMF generally does a good job of XML encoding, however there are a few scenarios where the encoding responsibility is pushed back to the user since enforcement by EMF would impose a disproportionate cost on normal use. xmi:id values are one example of this; xmi:id values must be legal without further encoding.
Without an example of your bad character we can only guess.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.04490 seconds