1

This is partly related to the age-old unix vs. windows newline LF/CRLF dilemma. I don't love my solution, but I have most of that figured out... (nonetheless any general guidance related to cross-browser newlines appreciated!). FF can send data from html textareas in a way that the newlines are stored in the db consistently with IE (and my Java client). The other clients can read these FF-authored strings newline and all.

My main remaining issue is how to correctly retrieve and display the strings in FF. How can I identify newlines in xml attributes? For example, I have an xhr returning a set of form fields to render via javascript:

<field name="desc" displayname="Description" value="i
am
in
ff" type="string" length="240"> </field>

(I haven't confirmed, but I'm pretty sure those are CRLFs in the value attribute - same as I stored previously...) This value will get rendered into a textarea.

But when I try to read the attribute in FF, var value = fieldNode.getAttribute( "value" ); I get value="i am in ff"

I know if i convert the CRLF to \n on the server, FF will work; but i think this may cause problems for our other clients. I'd like to find a client-side and client-specific solution.

If I could detect the newlines, I could substitute in
or whatever. I just need a way to detect them.

ps - no responses after more than a month... why am I the only one with this problem?? guess I'll have to figure it out myself :(

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
ss ulrey
  • 298
  • 1
  • 8

2 Answers2

2

Just in case anyone else stumbles on this in the futre... This thread helped get me on the right track: How to save newlines in XML attribute?

As it turns out, CRLF, CR, and LF should get encoded in proper xml CRLF = & #xD;& #xA;). I was previously not encoding these. IE is tolerant of that, while other browsers are not. E.g., Firefox's XML parser converts any newline character to a space. Now that i am encoding the newlines, all is well...

Community
  • 1
  • 1
ss ulrey
  • 298
  • 1
  • 8
0

I know I am a bit late, but is it possible that you could have put attribute value in the tags? Something like this: (NB the CDATA to allow to use '<' & '>' inside the field tags.)

<field> 
  <![CDATA[ i  <br/>
  am <br/>
  in <br/>
  ff ]]>
</field>

You could then have used some javascript to get the nodeValue:

getElementsByTagName("field")[0].childNodes[0].nodeValue;

NB it can be easier in XML not to use Attributes, but to use elements (see here)

adustduke
  • 155
  • 1
  • 8