How do you XML encode your data?

I was using jqgrid to display some "filtered" data on the grid, but some filters won't display any data. My immediate suspect was special characters that may interfere with XML markup.

jqgrid table

After looking at Extensible Markup Language (XML) 1.0 (Second Edition) specification, disallowed characters are defined in IETF RFC 2396 except for (#), (%) and square bracket characters are re-allowed. Per W3 recommendation, there are three ways as recommended.

  • Each disallowed character is converted to UTF-8
  • Any octets corresponding to a disallowed character are escaped with the URI escaping mechanism (that is, converted to %HH, where HH is the hexadecimal notation of the byte value).
  • Better yet, enclose your data in <![CDATA[ your text here ]]>

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment