views:

238

answers:

3

I have the following problem: I have an XML and an XSLT file to process this it and generate output.

The output of this process should contain a control character '0B'. And as far as I know, XML doesn't embed control characters, so how can I accomplish this?

+2  A: 

Is the result meant to be an XML file? As you say, XML doesn't allow character U+000B. So by definition, any file containing that character is not a valid XML file. What's the bigger picture here? Why do you need that character? What alternatives might be available to you?

If you're trying to create a text file as the result of the XSLT transformation, that's a different matter.

Jon Skeet
I need to transform it into XML document, then take this document and convert it into Java Object (jPOS ISOMessage Object to be sent over network)one of the values of the XML file should be U+000B, Is it possible ?
Mohammed
Not without some sort of escaping, no. You could pick another "special" (but supported) character which you wouldn't use elsewhere, and then just switch between the two characters appropriately. Pretty hideous, but it would work.
Jon Skeet
You mean in XSLT, I set the value of the generated XML to a specail supported character instead of U+000B and then when goes to code that consume this XML file, I change the value of this character back to U+0000B ?
Mohammed
A: 

You could also encode your payload containing 0x0B to Base64 before adding to your XML Document.

This would rely on the consumer of your output transformation being able to convert back from Base64 to the original encoding.

Ash
the resulting XML document takes its value as hardcoded from XSL file
Mohammed
A: 

If the relevant XML format supports such characters, I would expect them to reside in some element which supports CDATA.

Can you put your characters inside a CDATA section? XSLT has a construct for creating CDATA sections (<xsl:cdata>). Inside, you can encode your characters using XML entity references <xsl:entity-ref/>.

The parser which reads your XML file should be able to convert those entityrefs to the appropriate characters.

Tor Haugen