1

I am trying to parse an XML file using Javascript, but I keep getting the same error:

SyntaxError: malformed hexadecimal character escape sequence
$.get('C:\Users\xxxxxx\Desktop\xmloutput.xml', function(xml) {

and it points to the single-quotes right before the C. I looked up the error, but there isn't much information about how to get around it. Or is my syntax incorrect? Here is my code:

$(document).ready(function(){
var data = new Array();

// Load the data from the XML file 
$.get('C:\Users\plk7504\Desktop\xmloutput.xml', function(xml) {

    // Split the lines
    var $xml = $(xml);

    // push series
    $xml.find('row').each(function(i, row) {

        var seriesOptions = {
            Category: $(series).find('Category').text(),
            Actual: $(series).find('Actual').text(),
            Plan: $(series).find('Plan').text(),
            Variance: $(series).find('Variance').text(),
        };

        // add it to the options
        data.push(seriesOptions);
    });
});
$("#month_an_plan1").replaceWith(data[0]);
});
YazanLpizra
  • 520
  • 1
  • 11
  • 32

1 Answers1

1

update the path to be:

C:\\Users\\plk7504\\Desktop\\xmloutput.xml

Also see: How to open a local disk file with Javascript?

Explanation: C:\\Users\\plk7504\\Desktop\\xmloutput.xml would be translated to C:\Users\plk7504\Desktop\xmloutput.xml right? so the problem you were seeing is because you were essentially trying to "escape" other characters such as '\U'

Community
  • 1
  • 1
Davie Brown
  • 717
  • 4
  • 23
  • But why did it call it an escape character? there wasnt a backslash around the single-quote to make it seem like a quote-mark – YazanLpizra Jun 30 '14 at 21:40
  • C:\\Users\\plk7504\\Desktop\\xmloutput.xml would be translated to C:\Users\plk7504\Desktop\xmloutput.xml right? so the problem you were seeing is because you were essentially trying to "escape" other characters such as '\U' – Davie Brown Jun 30 '14 at 21:43