Author |
Message
|
jdevassy |
Posted: Sun Sep 12, 2010 6:07 pm Post subject: Broker stripping new line characters |
|
|
Apprentice
Joined: 16 Oct 2005 Posts: 37 Location: Melbourne, Australia
|
Hi,
I have an issue with broker handling the new line character.
The input and the output are xml and one of the fields in the inout has new line character as part of the field value, but after the mapping the output field looses the new line.
eg: input
<Name>First Line
Second Line
Third Line
</Name>
output
<NameOut>First LineSecond LineThird Line</NameOut>
Could you please help, how to retain the new line in the output message
Thanks,
jd |
|
Back to top |
|
 |
kimbert |
Posted: Mon Sep 13, 2010 1:33 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
My guess is that this is nothing to do with message broker. It's an XML thing.
In an XML document, any sequence of line feed characters gets changed to a single LF ( 0x0A ) as required by this section of the XML specification.
If you view the output using a different text editor ( one which interprets line feeds correctly ) or view it in binary mode, I expect you will see that your CR/LF pairs have been converted to a single LF. |
|
Back to top |
|
 |
jdevassy |
Posted: Mon Sep 13, 2010 8:12 pm Post subject: |
|
|
Apprentice
Joined: 16 Oct 2005 Posts: 37 Location: Melbourne, Australia
|
Thanks Kimbert,
"....the XML processor MUST behave as if it normalized all line breaks in external parsed entities (including the document entity) on input, before parsing, by translating both the two-character sequence #xD #xA and any #xD that is not followed by #xA to a single #xA character.
"
But the issue is the output after mapping looses the #xA. If I do a straight OutputRoot = InputRoot in the XML domain, I can see the output with #xA.
jd |
|
Back to top |
|
 |
kimbert |
Posted: Mon Sep 13, 2010 11:50 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
But the issue is the output after mapping looses the #xA. If I do a straight OutputRoot = InputRoot in the XML domain, I can see the output with #xA. |
If you set Parse Timing to 'On Demand' and do a straight 'OutputRoot = InputRoot' then the parser will never be called. The output bitstream will be copied from the input without any involvement from the XML parser.
I still think my diagnosis is correct. If you want to check, set Parse Timing to 'Immediate' or 'Complete' and try your test again. |
|
Back to top |
|
 |
jdevassy |
Posted: Tue Sep 14, 2010 3:46 pm Post subject: |
|
|
Apprentice
Joined: 16 Oct 2005 Posts: 37 Location: Melbourne, Australia
|
Kimbert,
I think the issue is, the input value is in an XML attribute. And apparently the xml attributes will loose the line feed where as the elements will retain it.
In order to test this I created a test message with line feeds in an attribute and an element and the out put had the line feed preserved where copied from input element, but not from attribute.
Thanks
jd |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 15, 2010 1:12 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Did you try setting Parse Timing to 'immediate', as I suggested?
Quote: |
apparently the xml attributes will loose the line feed where as the elements will retain it. |
Who are you quoting here? The XML standard does not say that.
Quote: |
In order to test this I created a test message with line feeds in an attribute and an element and the out put had the line feed preserved where copied from input element, but not from attribute. |
I'm very surprised. Please post your input messages and the resulting output. It would be helpful if you could put [code] tags around the XML snippets to make them readable. |
|
Back to top |
|
 |
jdevassy |
Posted: Wed Sep 15, 2010 3:59 pm Post subject: |
|
|
Apprentice
Joined: 16 Oct 2005 Posts: 37 Location: Melbourne, Australia
|
Kimbert,
According to the xml specification, the line feeds in xml attributes will be normalised on parsing. We have now put a work around by escaping the X'0a chars on the input message and it works.
thanks for your help
jd |
|
Back to top |
|
 |
jdevassy |
Posted: Wed Sep 15, 2010 4:02 pm Post subject: |
|
|
Apprentice
Joined: 16 Oct 2005 Posts: 37 Location: Melbourne, Australia
|
eg:
Input XML Doc:
<Root>
<Child name=" me 
 and

you "/>
</Root>
Output XML Doc:
<Root>
<Child name=" me 
 and 
you "/>
</Root> |
|
Back to top |
|
 |
kimbert |
Posted: Thu Sep 16, 2010 1:14 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
The XML specification says this:
Quote: |
To simplify the tasks of applications, the XML processor MUST behave as if it normalized all line breaks in external parsed entities (including the document entity) on input, before parsing, by translating both the two-character sequence #xD #xA and any #xD that is not followed by #xA to a single #xA character. |
but you said something different:
Quote: |
According to the xml specification, the line feeds in xml attributes will be normalised on parsing. |
What makes you think that attribute values are special? |
|
Back to top |
|
 |
mgk |
Posted: Thu Sep 16, 2010 1:51 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Actually kimbert, section "3.3.3 Attribute-Value Normalization" states :
Quote: |
"For a white space character (#x20, #xD, #xA, #x9), append a space character (#x20) to the normalized value." |
followed by:
Quote: |
"If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character." |
So attributes are special and are normalised on parsing...
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
kimbert |
Posted: Thu Sep 16, 2010 2:37 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Thanks mgk - I completely missed that difference.
jdevassy: Glad you got it working - your fix looks like the correct approach. |
|
Back to top |
|
 |
|