0

I am getting a xml string from a server through ajax request. But it is not getting parsed through jquery-

var xml = $.parseXML("<dummy>"+xmlStr+"</dummy>");

I am getting the error -

Uncaught Error: Invalid XML: <dummy><SMSInfo><smsTo>7005056</smsTo...

I debugged further for the reason for the invalid xml, got the following error from debugging into jquery parseXML function-

This page contains the following errors:error on line 1 at column 7624: Char 0x0 out of allowed range↵Below is a rendering of the page up to the first error.

Further still I copied the xml data from the console to a new file and opened in another editor, there I could see these kind of characters -

^@Z ^@6 ^@1 ...

My usual editor (Webstorm) does not even show these characters...

I am not able to figure out on how to remove these characters...These are not the usual "<,>,&" characters(I cleaned that already)

Please somebody help!

harsh atal
  • 411
  • 6
  • 16
  • 'Invisible characters not letting me (...)' - that sound really aggressive. :-) Why do you get these characters? Are they legitimate answer of the server that you have to process, or is this type of answer an indication of an error on previous stages? – Artur Opalinski Jun 01 '16 at 10:16
  • :) am stuck that's why....these are not legitimate characters, I am deling with sms data ...so dunno how but may be the user has sent some message with these characters somehow(**^@**).. – harsh atal Jun 01 '16 at 10:28

1 Answers1

1

In unicode 0x0 stands for null and parsing this null causes the exception.
Try to find out what the cause of the null is and tackle the problem at its root.
A very similar issue is discussed in this SO question: Error about invalid XML characters on Java

Community
  • 1
  • 1
CheshireCat
  • 166
  • 2
  • 8