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]);
});

1 Answer 1

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'

Sign up to request clarification or add additional context in comments.

2 Comments

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
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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.