The character restriction is actually part of the XML standard, which is why the code is checking this. I don't want people to accidentally produce documents that will be rejected by a parser.
If you want to override this for your documents and knowingly produce something that will be rejected by most parsers you can do so by creating your own ICharacterEscaper implementation and using the MarshallingContext.setOutput() call that takes an ICharacterEscaper. For this purpose you could copy the code in UTF8Escaper and just take out the checks for chr < 0x20 and not a tab, new line, or line feed. This is dangerous, though; even if the supplied xpp3 parser doesn't check this on input, most parsers will (including parsers such as StAX that may become the default for JiBX in the future).
If you know this data contains binary values, you really should use base64 encoding on it. I've been meaning to add a standard serializer/deserializer for base64 to the Utilities class and make this the default for byte[]. Would that suit your needs?
- Dennis
Stefano Fornari wrote:
Hi Dennis,
the 0x03 is probably the offending character...
By the way, IMHO the point is not what is formally in the standard, but what makes sense. Is there any advantage in throwing an exception if I try to write a binary code? If yes, it is ok. If it is just because 0x3 is not listed in the specs, I would have some things to say.
I really love jibx, but being too strictly rigoruse dimineshes its applications. Unfortunately, the external world is not so conformant and I think jibx should be flexible in how sever it has to be. It is the same problem with namespaces. There is no way to say: " listen, forget about namespaces, just parse the tags! ".
I know, I have no rights to pretend anything, take that feedbacks as user comments. If you will consider it for a fix, I would really appreciate it. If you won't fix it, I will do it just for my project.
Thanks for the good work,
Stefano
Dennis Sosnoski wrote:
What are the actual binary values of those characters in your string? The error message is saying that one of them is a 0x03, which is completely illegal in XML 1.0.
- Dennis
Stefano Fornari wrote:
Hi All,
We are using JiBX in a production system; unfortunately, we are facing some problems that I hope somebody can help with.
This is the latter:
org.jibx.runtime.JiBXException: Error writing marshalled document
Root cause: java.io.IOException: Illegal character code 0x3 in content text
at org.jibx.runtime.impl.MarshallingContext.element(MarshallingContext.java:642)
Caused by:
java.io.IOException: Illegal character code 0x3 in content text
at org.jibx.runtime.impl.UTF8StreamWriter.writeTextContent(UTF8StreamWriter.java:254)
at org.jibx.runtime.impl.MarshallingContext.element(MarshallingContext.java:638)
This happens marshalling the following XML snippet:
<Cred> <Meta><Type>syncml:auth-md5</Type></Meta> <Data>N?�U#>G?a�???�??</Data> </Cred>
With the following mapping:
<mapping name="Cred" class="sync4j.framework.core.Cred">
<structure field="authentication" class="sync4j.framework.core.Authentication">
<structure name="Meta" class="sync4j.framework.core.Meta">
<value name="Format" field="format" usage="optional"/>
<value name="Type" field="type"/>
</structure>
<structure name="Data" usage="optional">
<value field="data" style="text" class="sync4j.framework.core.Data" usage="optional"/>
</structure>
</structure>
</mapping>
It looks like a bug in the writer.
Regards, Stefano
-- Dennis M. Sosnoski Enterprise Java, XML, and Web Services Training and Consulting http://www.sosnoski.com Redmond, WA 425.885.7197
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE. http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users
