0

When parsing an xmlstring, the \r\n is lost. How to solve that?

//Example
var string = "<x y=\"line1\r\nline2\"></x>",
    xml = $.parseXML(string),
    y = xml.documentElement.getAttribute("y");
//Now y is missing the \r\n.
Niels Steenbeek
  • 4,598
  • 2
  • 39
  • 50

1 Answers1

2

A line break in an attribute value is meaningless.

<foo bar="line1
line2" />

is really equivalent to:

<foo bar="line1 line2" />

Encode your attribute value like this instead:

<foo bar="line1&#xA;line2" />
Tomalak
  • 322,446
  • 66
  • 504
  • 612