On Fri, Nov 04, 2005 at 12:52:29PM -0000, Tom Sugden wrote:
> Hello,
> 
> Can anybody suggest the best approach for encoding invalid XML characters
> into an XML document? For example, the Unicode character with the
> hexadecimal code 000C can be encoded into a Java character literal as
> follows:
> 
>     char c = '\u000C';
> 
> I tried encoding this character into an XML string using a standard
> character reference. For example:
> 
>     String s = "<tag>&#x000C;</tag>";

I think the easiest way is to make the tag element have the type
base64Binary.

This way the string "\u000C\u000A\n000D" would become

<tag>DAoN</tag>

however the string "Hello world" would become

<tag>SGVsbG8gd29ybGQ=</tag>

Alternatively you could use mixed content, and so "Hello \u000C" would
become:

<tag>Hello <char number="12"/></tag>

But this one would be harder to process by consumers of your system.

I wonder what solutions other people have for this problem.

David
-- 
"[Hackers] then only have to crack the password to take control"
  -- IT Week on a terrible Unix security flaw

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to